POE::Component::IRC::Qnet::State - a fully event-driven IRC client module for Quakenet, with nickname and channel tracking from POE::Component::IRC::State.
# A simple Rot13 'encryption' bot
use strict;
use warnings;
use POE qw(Component::IRC::Qnet::State);
my $nickname = 'Flibble' . $$;
my $ircname = 'Flibble the Sailor Bot';
my $ircserver = 'irc.blahblahblah.irc';
my $port = 6667;
my $qauth = 'FlibbleBOT';
my $qpass = 'fubar';
my @channels = ( '#Blah', '#Foo', '#Bar' );
# We create a new PoCo-IRC object and component.
my $irc = POE::Component::IRC::Qnet::State->spawn(
nick => $nickname,
server => $ircserver,
port => $port,
ircname => $ircname,
) or die "Oh noooo! $!";
POE::Session->create(
package_states => [
main => [ qw(_default _start irc_001 irc_public) ],
],
heap => { irc => $irc },
);
$poe_kernel->run();
sub _start {
my ($kernel, $heap) = @_[KERNEL, HEAP];
# We get the session ID of the component from the object
# and register and connect to the specified server.
my $irc_session = $heap->{irc}->session_id();
$kernel->post( $irc_session => register => 'all' );
$kernel->post( $irc_session => connect => { } );
return;
}
sub irc_001 {
my ($kernel, $sender) = @_[KERNEL, SENDER];
# Get the component's object at any time by accessing the heap of
# the SENDER
my $poco_object = $sender->get_heap();
print "Connected to ", $poco_object->server_name(), "\n";
# Lets authenticate with Quakenet's Q bot
$kernel->post( $sender => qbot_auth => $qauth => $qpass );
# In any irc_* events SENDER will be the PoCo-IRC session
$kernel->post( $sender => join => $_ ) for @channels;
return;
}
sub irc_public {
my ($kernel, $sender, $who, $where, $what) = @_[KERNEL, SENDER, ARG0, .. ARG2];
my $nick = ( split /!/, $who )[0];
my $channel = $where->[0];
my $poco_object = $sender->get_heap();
if ( my ($rot13) = $what =~ /^rot13 (.+)/ ) {
# Only operators can issue a rot13 command to us.
return if !$poco_object->is_channel_operator( $channel, $nick );
$rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M];
$kernel->post( $sender => privmsg => $channel => "$nick: $rot13" );
}
return;
}
# We registered for all events, this will produce some debug info.
sub _default {
my ($event, $args) = @_[ARG0 .. $#_];
my @output = ( "$event: " );
for my $arg ( @$args ) {
if (ref $arg eq 'ARRAY') {
push( @output, '[' . join(' ,', @$arg ) . ']' );
}
else {
push ( @output, "'$arg'" );
}
}
print join ' ', @output, "\n";
return 0;
}
POE::Component::IRC::Qnet::State is an extension to POE::Component::IRC::Qnet specifically for use on Quakenet http://www.quakenet.org/, which includes the nickname and channel tracking from POE::Component::IRC::State. See the documentation for POE::Component::IRC::Qnet and POE::Component::IRC::State for general usage. This document covers the extensions.
ban_mask
is_nick_authed
find_auth_nicks
nick_info
These additional events are accepted:
resync_chan
irc_chan_sync event for each
channel given.
resync_nick
irc_nick_sync
event for each of the given channels (assuming that nick is on each of those channels).
This module returns one additional event over and above the usual events:
irc_nick_authed
The following two 'irc_*' events are the same as their POE::Component::IRC::State counterparts, with the additional parameters:
irc_quit
irc_part
irc_kick
Like POE::Component::IRC::State this component registers itself for a number of events. The main difference with POE::Component::IRC::State is that it uses an extended form of 'WHO' supported by the Quakenet ircd, asuka. This WHO returns a different numeric reply than the original WHO, namely, 'irc_354'. Also, due to the way Quakenet is configured all users will appear to be on the server '*.quakenet.org'.
A few have turned up in the past and they are sure to again. Please use http://rt.cpan.org/ to report any. Alternatively, email the current maintainer.
Chris 'BinGOs' Williams <chris@bingosnet.co.uk>
Based on the original POE::Component::IRC by:
Dennis Taylor