NAME
POE::Component::IRC::Qnet::State - A fully event-driven IRC client module for Quakenet with nickname and channel tracking
SYNOPSIS
# 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;
}
DESCRIPTION
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.
METHODS
ban_mask
-
Expects a channel and a ban mask, as passed to MODE +b-b. Returns a list of nicks on that channel that match the specified ban mask or an empty list if the channel doesn't exist in the state or there are no matches. Follows Quakenet ircd rules for matching authed users.
is_nick_authed
-
Expects a nickname as parameter. Will return that users authname (account) if that nick is in the state and have authed with Q. Returns a false value if the user is not authed or the nick doesn't exist in the state.
find_auth_nicks
-
Expects an authname and a channel name. Will return a list of nicks on the given channel that have authed with the given authname.
nick_info
-
Expects a nickname. Returns a hashref containing similar information to that returned by WHOIS. Returns a false value if the nickname doesn't exist in the state. The hashref contains the following keys: 'Nick', 'User', 'Host', 'Server', 'Auth', if authed, and, if applicable, 'IRCop'.
INPUT
These additional events are accepted:
resync_chan
-
Accepts a list of channels, will resynchronise each of those channels as if they have been joined for the first time. Expect to see an
irc_chan_sync
event for each channel given. resync_nick
-
Accepts a nickname and a list of channels. Will resynchronise the given nickname and issue an
irc_nick_sync
event for each of the given channels (assuming that nick is on each of those channels).
OUTPUT
This module returns one additional event over and above the usual events:
irc_nick_authed
-
Sent when the component detects that a user has authed with Q. Due to the mechanics of Quakenet you will usually only receive this if an unauthed user joins a channel, then at some later point auths with Q. The component 'detects' the auth by seeing if Q or L decides to +v or +o the user. Klunky? Indeed. But it is the only way to do it, unfortunately.
The following two 'irc_*' events are the same as their POE::Component::IRC::State counterparts, with the additional parameters:
irc_quit
-
ARG3 contains the quitting clients auth name if applicable.
irc_part
-
ARG3 contains the parting clients auth name if applicable.
irc_kick
-
ARG5 contains the kick victim's auth name if applicable.
CAVEATS
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'.
BUGS
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.
AUTHOR
Chris 'BinGOs' Williams <chris@bingosnet.co.uk>
Based on the original POE::Component::IRC by:
Dennis Taylor