| 1 | package POE::Component::IRC::Qnet; | ||||||||||
| 2 | 3 | $POE::Component::IRC::Qnet::VERSION = '6.95'; | |||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use warnings FATAL => 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use POE; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use POE::Component::IRC::Constants qw(:ALL); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use base qw(POE::Component::IRC); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | sub _create { | ||||||||
|
Subroutine
_create: called CC=2 SCAR=6.9
| |||||||||||
| 11 | 1 | my $self = shift; | |||||||||
| 12 | |||||||||||
| 13 | 1 | $self->SUPER::_create(); | |||||||||
| 14 | |||||||||||
| 15 | # Stuff specific to IRC-Qnet | ||||||||||
| 16 | 1 | 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 | |||||||||||
| 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 | $self->{OBJECT_STATES_HASHREF}->{'qbot_' . $_} = '_qnet_bot_commands' for @qbot_commands; | |||||||||
| 57 | 1 | $self->{server} = 'irc.quakenet.org'; | |||||||||
| 58 | 1 | $self->{QBOT} = 'Q@Cserve.quakenet.org'; | |||||||||
| 59 | |||||||||||
| 60 | 1 | return 1; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | sub _qnet_bot_commands { | ||||||||
|
Subroutine
_qnet_bot_commands: not called CC=2 SCAR=17.9
| |||||||||||
| 64 | 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 | ▶ | $command = join(' ',$command,$message) if defined ( $message ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 0 | $kernel->yield( 'sl_prioritized', $pri, $command ); | |||||||||
| 73 | |||||||||||
| 74 | 0 | return; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 0 | ▶ | sub service_bots { | ||||||||
|
Subroutine
service_bots: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 78 | 0 | my ($self, %args) = @_; | |||||||||
| 79 | |||||||||||
| 80 | 0 | for my $botname ( qw(QBOT) ) { | |||||||||
| 81 | 0 | ▶ | if ( defined ( $args{$botname} ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 0 | $self->{$botname} = $args{$botname}; | |||||||||
| 83 | } | ||||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | return 1; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 3 | 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<POE::Component::IRC|POE::Component::IRC> | ||||||||||
| 183 | specifically for use on Quakenet L<http://www.quakenet.org/>. See the | ||||||||||
| 184 | documentation for L<POE::Component::IRC|POE::Component::IRC> 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<service_bots> | ||||||||||
| 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<POE::Component::IRC> "privmsg" command. | ||||||||||
| 205 | |||||||||||
| 206 | =head2 C<qbot_*> | ||||||||||
| 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<C<irc_notice>|POE::Component::IRC/irc_notice> to trap these. | ||||||||||
| 217 | |||||||||||
| 218 | =head2 C<irc_whois> | ||||||||||
| 219 | |||||||||||
| 220 | Has all the same hash keys in C<ARG1> as L<POE::Component::IRC|POE::Component::IRC>, | ||||||||||
| 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<http://rt.cpan.org/> to report any. Alternatively, email the current maintainer. | ||||||||||
| 228 | |||||||||||
| 229 | =head1 AUTHOR | ||||||||||
| 230 | |||||||||||
| 231 | Chris 'BinGOs' Williams E<lt>chris@bingosnet.co.ukE<gt> | ||||||||||
| 232 | |||||||||||
| 233 | Based on the original POE::Component::IRC by: | ||||||||||
| 234 | |||||||||||
| 235 | Dennis Taylor, <dennis@funkplanet.com> | ||||||||||
| 236 | |||||||||||
| 237 | =head1 SEE ALSO | ||||||||||
| 238 | |||||||||||
| 239 | L<POE::Component::IRC> | ||||||||||
| 240 | |||||||||||
| 241 | L<http://www.quakenet.org/> | ||||||||||
| 242 | |||||||||||
| 243 | =cut | ||||||||||