POE::Component::IRC::Plugin::Connector - A PoCo-IRC plugin that deals with the messy business of staying connected to an IRC server.
use POE qw(Component::IRC Component::IRC::Plugin::Connector); my ($irc) = POE::Component::IRC->spawn(); POE::Session->create( package_states => [ 'main' => [ qw(_start lag-o-meter) ], ], ); $poe_kernel->run(); exit 0; sub _start { $irc->yield( register => 'all' ); $irc->plugin_add( 'Connector' => POE::Component::IRC::Plugin::Connector->new() ); $irc->yield ( connect => { Nick => 'testbot', Server => 'someserver.com' } ); $_[KERNEL]->delay( 'lag-o-meter' => 60 ); } sub lagometer { print STDERR "Time: " . time() . " Lag: " . $irc->lag() . "\n"; $_[KERNEL]->delay( 'lag-o-meter' => 60 ); }
POE::Component::IRC::Plugin::Connector is a POE::Component::IRC plugin that deals with making sure that your IRC bot stays connected to the IRC network of your choice. It implements the general algorithm as demonstrated at http://poe.perl.org/?POE_Cookbook/IRC_Bot_Reconnecting.
Takes one argument, 'delay', which the frequency that the plugin will ping it's server. Returns a plugin object suitable for use in POE::Component::IRC's 'plugin_add'.
$irc->plugin_add( 'Connector' => POE::Component::IRC::Plugin::Connector->new( delay => 120 ) );
Returns the current 'lag' in seconds between sending PINGs to the IRC server and getting PONG responses. Probably not likely to be wholely accurate.
Chris "BinGOs" Williams <chris@bingosnet.co.uk>
POE::Component::IRC POE::Component::IRC::Plugin
To install POE::Component::IRC, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Component::IRC
CPAN shell
perl -MCPAN -e shell install POE::Component::IRC
For more information on module installation, please visit the detailed CPAN module installation guide.