File Coverage

blib/lib/POE/Component/IRC/Qnet.pm
Criterion Covered Total %
statement 25 39 64.1
branch 0 4 0.0
condition n/a
subroutine 7 9 77.7
pod 1 1 100.0
total 33 53 62.2


line stmt bran cond sub pod time code
1             package POE::Component::IRC::Qnet;
2             $POE::Component::IRC::Qnet::VERSION = '6.95';
3 3     3   93452 use strict;
  3         7  
  3         135  
4 3     3   14 use warnings FATAL => 'all';
  3         5  
  3         196  
5 3     3   14 use Carp;
  3         4  
  3         203  
6 3     3   14 use POE;
  3         4  
  3         20  
7 3     3   1545 use POE::Component::IRC::Constants qw(:ALL);
  3         7  
  3         606  
8 3     3   17 use base qw(POE::Component::IRC);
  3         5  
  3         1847  
9              
10             sub _create {
11 1     1   2 my $self = shift;
12              
13 1         12 $self->SUPER::_create();
14              
15             # Stuff specific to IRC-Qnet
16 1         21 my @qbot_commands = qw(
17             hello
18             whoami
19             challengeauth
20             showcommands
21             auth
22             challenge
23             help
24             unlock
25             requestpassword
26             reset
27             newpass
28             email
29             authhistory
30             banclear
31             op
32             invite
33             removeuser
34             banlist
35             recover
36             limit
37             unbanall
38             whois
39             version
40             autolimit
41             ban
42             clearchan
43             adduser
44             settopic
45             chanflags
46             deopall
47             requestowner
48             bandel
49             chanlev
50             key
51             welcome
52             voice
53             );
54              
55              
56 1         95 $self->{OBJECT_STATES_HASHREF}->{'qbot_' . $_} = '_qnet_bot_commands' for @qbot_commands;
57 1         5 $self->{server} = 'irc.quakenet.org';
58 1         5 $self->{QBOT} = 'Q@Cserve.quakenet.org';
59              
60 1         7 return 1;
61             }
62              
63             sub _qnet_bot_commands {
64 0     0     my ($kernel, $state, $self) = @_[KERNEL,STATE,OBJECT];
65 0           my $message = join ' ', @_[ARG0 .. $#_];
66              
67 0           my $pri = $self->{IRC_CMDS}->{'privmsghi'}->[CMD_PRI];
68 0           my $command = "PRIVMSG ";
69 0           my ($target,$cmd) = split(/_/,$state);
70 0           $command .= join(' :',$self->{uc $target},uc($cmd));
71 0 0         $command = join(' ',$command,$message) if defined ( $message );
72 0           $kernel->yield( 'sl_prioritized', $pri, $command );
73              
74 0           return;
75             }
76              
77             sub service_bots {
78 0     0 1   my ($self, %args) = @_;
79              
80 0           for my $botname ( qw(QBOT) ) {
81 0 0         if ( defined ( $args{$botname} ) ) {
82 0           $self->{$botname} = $args{$botname};
83             }
84             }
85              
86 0           return 1;
87             }
88              
89             1;
90              
91             =encoding utf8
92              
93             =head1 NAME
94              
95             POE::Component::IRC::Qnet - A fully event-driven IRC client module for Quakenet
96              
97             =head1 SYNOPSIS
98              
99             use strict;
100             use warnings;
101             use POE qw(Component::IRC::Qnet);
102              
103             my $nickname = 'Flibble' . $$;
104             my $ircname = 'Flibble the Sailor Bot';
105             my $port = 6667;
106             my $qauth = 'FlibbleBOT';
107             my $qpass = 'fubar';
108             my @channels = ( '#Blah', '#Foo', '#Bar' );
109              
110             # We create a new PoCo-IRC object and component.
111             my $irc = POE::Component::IRC::Qnet->spawn(
112             nick => $nickname,
113             port => $port,
114             ircname => $ircname,
115             ) or die "Oh noooo! $!";
116              
117             POE::Session->create(
118             package_states => [
119             main => [ qw(_default _start irc_001 irc_public) ],
120             ],
121             heap => { irc => $irc },
122             );
123              
124             $poe_kernel->run();
125              
126             sub _start {
127             my ($kernel, $heap) = @_[KERNEL, HEAP];
128              
129             # We get the session ID of the component from the object
130             # and register and connect to the specified server.
131             my $irc_session = $heap->{irc}->session_id();
132             $kernel->post( $irc_session => register => 'all' );
133             $kernel->post( $irc_session => connect => { } );
134             return;
135             }
136              
137             sub irc_001 {
138             my ($kernel, $sender) = @_[KERNEL, SENDER];
139              
140             # Get the component's object at any time by accessing the heap of
141             # the SENDER
142             my $poco_object = $sender->get_heap();
143             print "Connected to ", $poco_object->server_name(), "\n";
144              
145             # Lets authenticate with Quakenet's Q bot
146             $kernel->post( $sender => qbot_auth => $qauth => $qpass );
147              
148             return;
149             }
150              
151             sub irc_public {
152             my ($kernel, $sender, $who, $where, $what) = @_[KERNEL, SENDER, ARG0 .. ARG2];
153             my $nick = ( split /!/, $who )[0];
154             my $channel = $where->[0];
155              
156             if ( my ($rot13) = $what =~ /^rot13 (.+)/ ) {
157             $rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M];
158             $kernel->post( $sender => privmsg => $channel => "$nick: $rot13" );
159             }
160             return;
161             }
162              
163             # We registered for all events, this will produce some debug info.
164             sub _default {
165             my ($event, $args) = @_[ARG0 .. $#_];
166             my @output = ( "$event: " );
167              
168             for my $arg ( @$args ) {
169             if (ref $arg eq 'ARRAY') {
170             push( @output, '[' . join(', ', @$arg ) . ']' );
171             }
172             else {
173             push ( @output, "'$arg'" );
174             }
175             }
176             print join ' ', @output, "\n";
177             return 0;
178             }
179              
180             =head1 DESCRIPTION
181              
182             POE::Component::IRC::Qnet is an extension to L
183             specifically for use on Quakenet L. See the
184             documentation for L for general usage.
185             This document covers the extensions.
186              
187             The module provides a number of additional commands for communicating with the
188             Quakenet service bot Q.
189              
190             =head1 METHODS
191              
192             =head2 C
193              
194             The component will query Q its default name on Quakenet. If you
195             wish to override these settings, use this method to configure them.
196              
197             $irc->service_bots(QBOT => 'W@blah.network.net');
198              
199             In most cases you shouldn't need to mess with these >;o)
200              
201             =head1 INPUT
202              
203             The Quakenet service bots accept input as PRIVMSG. This module provides a
204             wrapper around the L "privmsg" command.
205              
206             =head2 C
207              
208             Send commands to the Q bot. Pass additional command parameters as arguments to
209             the event.
210              
211             $kernel->post ('my client' => qbot_auth => $q_user => $q_pass);
212              
213             =head1 OUTPUT EVENTS
214              
215             All output from the Quakenet service bots is sent as NOTICEs.
216             Use L|POE::Component::IRC/irc_notice> to trap these.
217              
218             =head2 C
219              
220             Has all the same hash keys in C as L,
221             with the addition of B<'account'>, which contains the name of their Q auth account,
222             if they have authed, or a false value if they haven't.
223              
224             =head1 BUGS
225              
226             A few have turned up in the past and they are sure to again. Please use
227             L to report any. Alternatively, email the current maintainer.
228              
229             =head1 AUTHOR
230              
231             Chris 'BinGOs' Williams Echris@bingosnet.co.ukE
232              
233             Based on the original POE::Component::IRC by:
234              
235             Dennis Taylor,
236              
237             =head1 SEE ALSO
238              
239             L
240              
241             L
242              
243             =cut