On Sun, Jan 19, 2003 at 10:31:56PM -0600, Werlax wrote:
> Hi all,
> I've read through the perldocs and browsed the web for quite a while, but I
> can't seem to figure this one out. My small snippet appears similar to the
> examples I could find and the docs seem to back me up. I believe I'm using
> this correctly, but what happens is the 'bot' (written through PoCo::IRC)
> just hangs in the channel.
> if ( $sleep ) {
> $kernel->delay( cleanup => 5 ); # exit after n seconds
> } else {
> &cleanup; # exit now if not sleeping
> }
>
> The cleanup function isn't doing anything real exciting.
>
> sub cleanup {
> $_[KERNEL]->post( magnet => quit => "Bye.");
> $_[KERNEL]->post( magnet => unregister => "all" );
> }
>
> Pretty simple, but all of this is just a small test for something larger
> that I want to write. I didn't want to continue until I was sure I
> understood this aspect of it. If I run the 'cleanup' function all by
> itself, it works fine and the 'bot' exits. It's only when I try to call it
> through the delay.
You should do the cleanup in two stages.
sub cleanup {
$_[KERNEL]->post( magnet => quit => "Bye." );
}
sub irc_disconnected {
my ($server) = $_[ARG0];
print "Lost connection to server $server.\n";
$_[KERNEL]->post( magnet => unregister => "all" );
}
That way the bot has a chance to quit gracefully, rather than send the
quit and then suddenly disconnect because the program has shut down.
If your bot is still alive after that, it may be because of pending
timers (other than the cleanup timer), aliases, other open files, open
DCC connections, or something else.
-- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/