1POE::Component::IRC::QnUeste:r:SCtoantter(i3b)uted PerlPDOoEc:u:mCeonmtpaotnieonnt::IRC::Qnet::State(3)
2
3
4
6 POE::Component::IRC::Qnet::State - A fully event-driven IRC client
7 module for Quakenet with nickname and channel tracking
8
10 # A simple Rot13 'encryption' bot
11
12 use strict;
13 use warnings;
14 use POE qw(Component::IRC::Qnet::State);
15
16 my $nickname = 'Flibble' . $$;
17 my $ircname = 'Flibble the Sailor Bot';
18 my $ircserver = 'irc.blahblahblah.irc';
19 my $port = 6667;
20 my $qauth = 'FlibbleBOT';
21 my $qpass = 'fubar';
22
23 my @channels = ( '#Blah', '#Foo', '#Bar' );
24
25 # We create a new PoCo-IRC object and component.
26 my $irc = POE::Component::IRC::Qnet::State->spawn(
27 nick => $nickname,
28 server => $ircserver,
29 port => $port,
30 ircname => $ircname,
31 ) or die "Oh noooo! $!";
32
33 POE::Session->create(
34 package_states => [
35 main => [ qw(_default _start irc_001 irc_public) ],
36 ],
37 heap => { irc => $irc },
38 );
39
40 $poe_kernel->run();
41
42 sub _start {
43 my ($kernel, $heap) = @_[KERNEL, HEAP];
44
45 # We get the session ID of the component from the object
46 # and register and connect to the specified server.
47 my $irc_session = $heap->{irc}->session_id();
48 $kernel->post( $irc_session => register => 'all' );
49 $kernel->post( $irc_session => connect => { } );
50
51 return;
52 }
53
54 sub irc_001 {
55 my ($kernel, $sender) = @_[KERNEL, SENDER];
56
57 # Get the component's object at any time by accessing the heap of
58 # the SENDER
59 my $poco_object = $sender->get_heap();
60 print "Connected to ", $poco_object->server_name(), "\n";
61
62 # Lets authenticate with Quakenet's Q bot
63 $kernel->post( $sender => qbot_auth => $qauth => $qpass );
64
65 # In any irc_* events SENDER will be the PoCo-IRC session
66 $kernel->post( $sender => join => $_ ) for @channels;
67
68 return;
69 }
70
71 sub irc_public {
72 my ($kernel, $sender, $who, $where, $what) = @_[KERNEL, SENDER, ARG0, .. ARG2];
73 my $nick = ( split /!/, $who )[0];
74 my $channel = $where->[0];
75 my $poco_object = $sender->get_heap();
76
77 if ( my ($rot13) = $what =~ /^rot13 (.+)/ ) {
78 # Only operators can issue a rot13 command to us.
79 return if !$poco_object->is_channel_operator( $channel, $nick );
80
81 $rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M];
82 $kernel->post( $sender => privmsg => $channel => "$nick: $rot13" );
83 }
84
85 return;
86 }
87
88 # We registered for all events, this will produce some debug info.
89 sub _default {
90 my ($event, $args) = @_[ARG0 .. $#_];
91 my @output = ( "$event: " );
92
93 for my $arg ( @$args ) {
94 if (ref $arg eq 'ARRAY') {
95 push( @output, '[' . join(', ', @$arg ) . ']' );
96 }
97 else {
98 push ( @output, "'$arg'" );
99 }
100 }
101
102 print join ' ', @output, "\n";
103 return 0;
104 }
105
107 POE::Component::IRC::Qnet::State is an extension to
108 POE::Component::IRC::Qnet specifically for use on Quakenet
109 <http://www.quakenet.org/>, which includes the nickname and channel
110 tracking from POE::Component::IRC::State. See the documentation for
111 POE::Component::IRC::Qnet and POE::Component::IRC::State for general
112 usage. This document covers the extensions.
113
115 "ban_mask"
116 Expects a channel and a ban mask, as passed to MODE +b-b. Returns a
117 list of nicks on that channel that match the specified ban mask or
118 an empty list if the channel doesn't exist in the state or there
119 are no matches. Follows Quakenet ircd rules for matching authed
120 users.
121
122 "is_nick_authed"
123 Expects a nickname as parameter. Will return that users authname
124 (account) if that nick is in the state and have authed with Q.
125 Returns a false value if the user is not authed or the nick doesn't
126 exist in the state.
127
128 "find_auth_nicks"
129 Expects an authname and a channel name. Will return a list of nicks
130 on the given channel that have authed with the given authname.
131
132 "nick_info"
133 Expects a nickname. Returns a hashref containing similar
134 information to that returned by WHOIS. Returns a false value if the
135 nickname doesn't exist in the state. The hashref contains the
136 following keys: 'Nick', 'User', 'Host', 'Server', 'Auth', if
137 authed, and, if applicable, 'IRCop'.
138
140 These additional events are accepted:
141
142 "resync_chan"
143 Accepts a list of channels, will resynchronise each of those
144 channels as if they have been joined for the first time. Expect to
145 see an "irc_chan_sync" event for each channel given.
146
147 "resync_nick"
148 Accepts a nickname and a list of channels. Will resynchronise the
149 given nickname and issue an "irc_nick_sync" event for each of the
150 given channels (assuming that nick is on each of those channels).
151
153 This module returns one additional event over and above the usual
154 events:
155
156 "irc_nick_authed"
157 Sent when the component detects that a user has authed with Q. Due
158 to the mechanics of Quakenet you will usually only receive this if
159 an unauthed user joins a channel, then at some later point auths
160 with Q. The component 'detects' the auth by seeing if Q decides to
161 +v or +o the user. Klunky? Indeed. But it is the only way to do it,
162 unfortunately.
163
164 The following two "irc_*" events are the same as their
165 POE::Component::IRC::State counterparts, with the additional
166 parameters:
167
168 "irc_quit"
169 "ARG3" contains the quitting clients auth name if applicable.
170
171 "irc_part"
172 "ARG3" contains the parting clients auth name if applicable.
173
174 "irc_kick"
175 "ARG5" contains the kick victim's auth name if applicable.
176
178 Like POE::Component::IRC::State this component registers itself for a
179 number of events. The main difference with POE::Component::IRC::State
180 is that it uses an extended form of 'WHO' supported by the Quakenet
181 ircd, asuka. This WHO returns a different numeric reply than the
182 original WHO, namely, "irc_354". Also, due to the way Quakenet is
183 configured all users will appear to be on the server '*.quakenet.org'.
184
186 A few have turned up in the past and they are sure to again. Please use
187 <http://rt.cpan.org/> to report any. Alternatively, email the current
188 maintainer.
189
191 Chris 'BinGOs' Williams <chris@bingosnet.co.uk>
192
193 Based on the original POE::Component::IRC by:
194
195 Dennis Taylor
196
198 POE::Component::IRC
199
200 POE::Component::IRC::State
201
202 POE::Component::IRC::Qnet
203
204 <http://www.quakenet.org/>
205
206
207
208perl v5.30.0 2019-07-26POE::Component::IRC::Qnet::State(3)