Component/IRC/Qnet.pm

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