This is a sample script. When I hit Ctrl+C, the bot quits IRC but it reconnects back after some time. How do I shut down the bot correctly?
#!/usr/bin/perl
package main;
my $bot = Perlbot->new (server => 'irc.dal.net');
$SIG{'INT'} = 'Handler';
$SIG{'TERM'} = 'Handler';
sub Handler {
print "\nShutting down bot...\n";
$bot->shutdown('Killed.');
};
$bot->run;
package Perlbot;
use base qw(Bot::BasicBot);
sub connected {
my $self = shift;
$self->join('#codetestchan');
}
I've taken over maintainership of Bot::BasicBot, and as of version 0.82, you can shut it down properly with
$bot->shutdown($quit_message)
.From looking at Bot::BasicBot's documentation and source code, I can't find a graceful way to shut it down. As you demonstrated, calling
$bot->shutdown()
(which actually sends ashutdown
event toPOE::Component::IRC
) will just causeBot::BasicBot
to reconnect (same with$bot->quit()
by the way).This and other limitations users have run into have caused me to recommend using
POE::Component::IRC
directly. It has many plugins nowadays for features provided byBot::BasicBot
which were missing whenBot::BasicBot
was created. While you may have to type a bit more to get a basic bot up and running, you have much more flexibility. Below is a bot like the one in your example, without usingBot::BasicBot
. It will send a quit message to the IRC server when you press CTRL+C, wait until it has been disconnected, then exit: