1 #**************************************************************************
2 # Copyright (C) 2009 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
27 use POE::Component::IRC::Common qw/irc_to_utf8/;
29 use POE::Component::IRC::Plugin::Logger;
30 use POE::Component::IRC::Plugin::BotTraffic;
31 use POE::Component::IRC::Plugin::Connector;
32 use POE::Component::IRC::Plugin::AutoJoin;
33 use POE::Component::IRC::Plugin::NickReclaim;
35 use NDIRC::Dispatcher;
45 # We registered for all events, this will produce some debug info.
47 my ($event, $args) = @_[ARG0 .. $#_];
48 my @output = ( "$event: " );
50 for my $arg (@$args) {
51 if ( ref $arg eq 'ARRAY' ) {
52 push( @output, '[' . join(', ', @$arg ) . ']' );
55 push ( @output, "'$arg'" );
58 print join ' ', @output, "\n";
63 my ($kernel,$heap,$session) = @_[KERNEL,HEAP,SESSION];
65 # retrieve our component's object from the heap where we stashed it
66 my $irc = $heap->{irc};
67 $kernel->sig( DIE => 'sig_DIE' );
68 $kernel->sig( USR1 => 'sig_usr1' );
69 $kernel->sig( USR2 => 'sig_usr2' );
70 $kernel->sig( INT => 'signal_handler' );
72 $irc->plugin_add( 'NickReclaim', POE::Component::IRC::Plugin::NickReclaim->new() );
73 $irc->plugin_add( 'AutoJoin', POE::Component::IRC::Plugin::NickReclaim->new() );
74 $irc->plugin_add( 'BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new() );
75 $irc->plugin_add('Logger', POE::Component::IRC::Plugin::Logger->new(
82 Strip_formatting => 1,
86 $heap->{connector} = POE::Component::IRC::Plugin::Connector->new(
87 servers => [['irc.netgamers.org'], ['underworld.no.eu.netgamers.org']
88 ,['firefly.no.eu.netgamers.org'], ['underworld.ca.us.netgamers.org'] ]
90 $irc->plugin_add( 'Connector' => $heap->{connector} );
92 $irc->yield( register => 'all' );
93 $irc->yield( connect => { server => 'irc.netgamers.org' } );
95 $kernel->delay( refresh => 60 );
102 if (my $f = new IO::File 'auth'){
107 $heap->{irc}->yield(qbot_auth => $user => $pass);
112 my ($kernel,$heap) = @_[KERNEL,HEAP];
114 $kernel->yield( 'refresh' );
120 $self->disp($self->_build_disp);
125 my $disp = new NDIRC::Dispatcher;
127 if (my $commands = new IO::File 'commands'){
128 my @commands = split /\W+/, do{local $/; <$commands>};
129 say "Loading commands from: @commands";
130 $disp->load(@commands);
133 my $channels = new IO::File 'channels' or die $!;;
135 my ($chan, @types) = split /\s+/;
136 say "$chan - @types";
137 if ($chan =~ /^(.*):(.*)$/){
139 $disp->set_target($2,$chan);
141 $disp->add_channel($chan,\@types);
148 my( $kernel,$sig, $ex ) = @_[ KERNEL,ARG0, ARG1 ];
149 say "DIED!!!!!!!!!!!!!!";
151 # $ex is the exception hash
152 warn "$$: error in event: $ex->{error_str}";
153 $kernel->sig_handled();
155 # Send the signal to session that sent the original event.
156 #if( $ex->{source_session} ne $_[SESSION] ) {
157 #$kernel->signal( $ex->{source_session}, 'DIE', $sig, $ex );
162 my ($kernel, $signal_name, $heap) = @_[KERNEL, ARG0, HEAP];
163 print "First session caught SIG$signal_name\n";
167 exit unless $heap->{irc}->connected;
169 $heap->{irc}->yield(quit => 'Bye!');
170 $kernel->sig_handled();
173 #$kernel->sig_handled();
176 sub irc_disconnected {
177 my ($sender,$heap) = @_[SENDER,HEAP];
179 exit if $heap->{INT};
183 my ($self,$sender,$kernel) = @_[OBJECT,SENDER,KERNEL];
185 # Since this is an irc_* event, we can get the component's object by
186 # accessing the heap of the sender. Then we register and connect to the
188 my $irc = $sender->get_heap();
190 print "Connected to ", $irc->server_name(), "\n";
192 $kernel->yield( 'auth' );
193 $irc->yield( mode => $irc->nick_name, '+ix');
195 # we join our channels
196 $irc->yield( join => $_ ) for grep /^#/, keys %{$self->disp->channels};
201 my ($self,$sender, $who, $channel) = @_[OBJECT,SENDER, ARG0 .. ARG1];
202 my $irc = $sender->get_heap();
204 $irc->yield( join => $_ ) for grep /^$channel$/i, keys %{$self->disp->channels}
208 $_[ARG2] = irc_to_utf8 $_[ARG2];
212 $_[ARG2] = irc_to_utf8 $_[ARG2];
222 my ($self, $msg, $server, $nick, $address, $channel, $model) = @_;
224 return if $channel !~ /^#/ && $msg =~ /^~/;
225 $msg = ".$msg" if $channel !~ /^#/ && $msg =~ /^[^.!]/;
227 my ($p,$command,$args) = ($msg =~ /^([.!~])(\S+)(?: (.+))?/);
229 if ($msg =~ m{http://[\w.]+/.+?scan(_id|_grp)?=(\w+)}){
230 if (!$command || $command =~ m{^http://}){
231 ($p,$command,$args) = ('.','addscan',$msg);
232 }elsif($command ne 'addscan'){
233 $self->parseCommand (".addscan $msg", $server, $nick, $address, $channel, $model)
237 return 0 unless $self->disp->has_command($command,$channel);
242 $reply_string = "privmsg $nick";
245 $reply_string = "privmsg $channel";
248 $reply_string = "notice $nick";
252 $address =~ s/.*@(.*)/$1/;
253 my $c = NDIRC::Context->new({
260 reply_string => $reply_string,
263 return $self->disp->run_command($c,$command,$args);