Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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 <code>$bot-&gt;shutdown()</code> (which actually sends a <code>shutdown</code> event to <code>POE::Component::IRC</code>) will just cause <code>Bot::BasicBot</code> to reconnect (same with <code>$bot-&gt;quit()</code> by the way).</p> <p>This and other limitations users have run into have caused me to recommend using <code>POE::Component::IRC</code> directly. It has many plugins nowadays for features provided by <code>Bot::BasicBot</code> which were missing when <code>Bot::BasicBot</code> 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 using <code>Bot::BasicBot</code>. It will send a quit message to the IRC server when you press CTRL+C, wait until it has been disconnected, then exit:</p> <pre><code>#!/usr/bin/env perl use strict; use warnings; use POE; use POE::Component::IRC::State; use POE::Component::IRC::Common qw(parse_user); use POE::Component::IRC::Plugin::Connector; use POE::Component::IRC::Plugin::AutoJoin; # create our session POE::Session-&gt;create( package_states =&gt; [ # event handlers (__PACKAGE__) =&gt; [qw(_start int irc_join irc_disconnected)] ] ); # start the event loop POE::Kernel-&gt;run(); # session start handler sub _start { my ($kernel, $heap) = @_[KERNEL, HEAP]; # handle CTRL+C $kernel-&gt;sig(INT =&gt; 'int'); # create bot object my $irc = POE::Component::IRC::State-&gt;spawn( server =&gt; 'irc.freenode.net', nick =&gt; 'basic123bot', debug =&gt; 1, ); # save $irc in our session's storage heap $heap-&gt;{irc} = $irc; # handle reconnects $irc-&gt;plugin_add('Connector', POE::Component::IRC::Plugin::Connector-&gt;new()); # handle channel joining $irc-&gt;plugin_add('AutoJoin', POE::Component::IRC::Plugin::AutoJoin-&gt;new( Channels =&gt; ['#foo123bar'], )); # connect to IRC $irc-&gt;yield('connect'); } # interrupt signal handler sub int { my ($kernel, $heap) = @_[KERNEL, HEAP]; $heap-&gt;{irc}-&gt;yield('quit', 'Quitting, bye!'); $heap-&gt;{shutting_down} = 1; $kernel-&gt;sig_handled(); } # join handler sub irc_join { my ($who, $chan) = @_[ARG0, ARG1]; my $irc = $_[HEAP]-&gt;{irc}; my ($nick, $user, $host) = parse_user($who); if ($nick eq $irc-&gt;nick_name()) { # say hello to channel members $irc-&gt;yield('privmsg', $chan, 'Hello everybody'); } } # disconnect handler sub irc_disconnected { my ($heap) = $_[HEAP]; # shut down if we disconnected voluntarily $heap-&gt;{irc}-&gt;yield('shutdown') if $heap-&gt;{shutting_down}; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload