Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

How do I shut down a Bot::BasicBot?

by myuserid7 (Scribe)
on Jul 15, 2010 at 14:13 UTC ( #849781=perlquestion: print w/ replies, xml ) Need Help??
myuserid7 has asked for the wisdom of the Perl Monks concerning the following question:

This is a sample bot.
#!/usr/bin/perl package main; my $bot = Perlbot->new (no_run => 0, server => 'swiftco.dal.net', chan +nels => ['#randomtestingchannel']); $SIG{'INT'} = 'Handler'; $SIG{'TERM'} = 'Handler'; sub Handler { $bot->shutdown('Leaving.'); }; $bot->run; package Perlbot; use base qw(Bot::BasicBot);
The bot quits IRC correctly, but it just sits there and reconnects back after 5 minutes. How do I shut it down completely?

Comment on How do I shut down a Bot::BasicBot?
Download Code
5+9 replies Replies are listed 'Oldest First'.
Re: How do I shut down a Bot::BasicBot?
by SuicideJunkie (Priest) on Jul 15, 2010 at 14:33 UTC

    Did you want something fancier than exit 0;?

      exit 0 doesn't send a quit message, and I get the error: (in cleanup) Can't call method "post" on an undefined value at /usr/local/lib/perl5/site_perl/5.10.0/Bot/BasicBot.pm line 1500 during global destruction. I'm looking for a way to shut it down cleanly.

        I thought you said that it quit IRC correctly. Is that not the case, or did you replace the shutdown call with the exit?

Re: How do I shut down a Bot::BasicBot?
by repellent (Priest) on Jul 16, 2010 at 03:52 UTC
      I tried that, and POE::Component::IRC::Cookbook::Disconnecting as well. Bot::BasicBot's documentation under Other Methods says I can call these methods but I'm still not sure how to do it correctly. This is what I tried
      #!/usr/bin/perl use POE; use warnings; use strict; my $bot = Perlbot->new (server => 'swiftco.dal.net', channels => ['#ra +ndomtestingchannel']); $SIG{'INT'} = 'Handler'; $SIG{'TERM'} = 'Handler'; sub Handler { $poe_kernel->signal($poe_kernel,'POCOIRC_SHUTDOWN'); }; $bot->run; package Perlbot; use base qw(Bot::BasicBot);
      It still stays there after disconnecting and then reconnects back to IRC.
Re: How do I shut down a Bot::BasicBot?
by bingos (Vicar) on Jul 16, 2010 at 08:29 UTC

    This will perhaps work:

    #!/usr/bin/perl package main; my $bot = Perlbot->new (no_run => 0, server => 'swiftco.dal.net', chan +nels => ['#randomtestingchannel']); $SIG{'INT'} = 'Handler'; $SIG{'TERM'} = 'Handler'; sub Handler { $bot->{_shutdown} = 1; $bot->shutdown('Leaving.'); }; $bot->run; package Perlbot; use POE; use base qw(Bot::BasicBot); sub irc_disconnected_state { my $self = $_[OBJECT]; return if $self->{_shutdown}; $self->SUPER::irc_disconnected_state( @_ ); }
      Still the same problem :/

        Apologies I missed something whilst looking through Bot::BasicBot's code:

        #!/usr/bin/perl package main; my $bot = Perlbot->new (no_run => 0, server => 'swiftco.dal.net', chan +nels => ['#randomtestingchannel']); $SIG{'INT'} = 'Handler'; $SIG{'TERM'} = 'Handler'; sub Handler { $bot->{_shutdown} = 1; $bot->shutdown('Leaving.'); }; $bot->run; package Perlbot; use strict; use warnings; use POE; use base qw(Bot::BasicBot); sub irc_disconnected_state { my $self = $_[OBJECT]; if ( $self->{_shutdown} ) { $poe_kernel->alarm_remove_all(); $poe_kernel->alias_remove($_) for $poe_kernel->alias_list(); return; } $self->SUPER::irc_disconnected_state( @_ ); } sub irc_error_state { my $self = $_[OBJECT]; if ( $self->{_shutdown} ) { $poe_kernel->alarm_remove_all(); $poe_kernel->alias_remove($_) for $poe_kernel->alias_list(); return; } $self->SUPER::irc_error_state( @_ ); }

        It is icky nasty though.

Re: How do I shut down a Bot::BasicBot?
by SuicideJunkie (Priest) on Jul 16, 2010 at 13:52 UTC

    Something to consider:

    If you're shutting it down anyways, does it really really matter if it shuts down quietly or not?

    Worst case, you could (copy locally and then) edit the source, and hack in a terminate flag that will avoid reconnect attempts during the shutdown.

Re: How do I shut down a Bot::BasicBot?
by Hinrik (Novice) on Mar 26, 2011 at 23:03 UTC
    As of Bot::BasicBot 0.82, you can shut it down properly with $bot->shutdown($quit_message). That will take care of sending a QUIT message to the IRC server, waiting until the server disconnects you, as well as killing any subprocesses you may have started with the forkit() method.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://849781]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (20)
As of 2015-07-07 16:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (91 votes), past polls