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;
46 # We registered for all events, this will produce some debug info.
48 my ($event, $args) = @_[ARG0 .. $#_];
49 my @output = ( "$event: " );
51 for my $arg (@$args) {
52 if ( ref $arg eq 'ARRAY' ) {
53 push( @output, '[' . join(', ', @$arg ) . ']' );
56 push ( @output, "'$arg'" );
59 print join ' ', @output, "\n";
64 my ($kernel,$heap,$session) = @_[KERNEL,HEAP,SESSION];
66 # retrieve our component's object from the heap where we stashed it
67 my $irc = $heap->{irc};
68 $kernel->sig( DIE => 'sig_DIE' );
69 $kernel->sig( USR1 => 'sig_usr1' );
70 $kernel->sig( USR2 => 'sig_usr2' );
71 $kernel->sig( INT => 'signal_handler' );
73 $irc->plugin_add( 'NickReclaim', POE::Component::IRC::Plugin::NickReclaim->new() );
74 $irc->plugin_add( 'AutoJoin', POE::Component::IRC::Plugin::NickReclaim->new() );
75 $irc->plugin_add( 'BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new() );
76 $irc->plugin_add('Logger', POE::Component::IRC::Plugin::Logger->new(
83 Strip_formatting => 1,
87 $heap->{connector} = POE::Component::IRC::Plugin::Connector->new(
88 servers => [['irc.netgamers.org'], ['underworld.no.eu.netgamers.org']
89 ,['firefly.no.eu.netgamers.org'], ['underworld.ca.us.netgamers.org'] ]
91 $irc->plugin_add( 'Connector' => $heap->{connector} );
93 $irc->yield( register => 'all' );
94 $irc->yield( connect => { server => 'irc.netgamers.org' } );
96 $kernel->delay( refresh => 60 );
103 if (my $f = new IO::File 'auth'){
108 $heap->{irc}->yield(qbot_auth => $user => $pass);
113 my ($kernel,$heap) = @_[KERNEL,HEAP];
115 $kernel->yield( 'refresh' );
121 $self->disp($self->_build_disp);
126 my $disp = new NDIRC::Dispatcher;
128 if (my $commands = new IO::File 'commands'){
129 my @commands = split /\W+/, do{local $/; <$commands>};
130 say "Loading commands from: @commands";
131 $disp->load(@commands);
134 my $channels = new IO::File 'channels' or die $!;;
136 my ($chan, @types) = split /\s+/;
137 say "$chan - @types";
138 if ($chan =~ /^(.*):(.*)$/){
140 $disp->set_target($2,$chan);
142 $disp->add_channel($chan,\@types);
149 my( $kernel,$sig, $ex ) = @_[ KERNEL,ARG0, ARG1 ];
150 say "DIED!!!!!!!!!!!!!!";
152 # $ex is the exception hash
153 warn "$$: error in event: $ex->{error_str}";
154 $kernel->sig_handled();
156 # Send the signal to session that sent the original event.
157 #if( $ex->{source_session} ne $_[SESSION] ) {
158 #$kernel->signal( $ex->{source_session}, 'DIE', $sig, $ex );
163 my ($kernel, $signal_name, $heap) = @_[KERNEL, ARG0, HEAP];
164 print "First session caught SIG$signal_name\n";
168 exit unless $heap->{irc}->connected;
170 $heap->{irc}->yield(quit => 'Bye!');
171 $kernel->sig_handled();
174 #$kernel->sig_handled();
177 sub irc_disconnected {
178 my ($sender,$heap) = @_[SENDER,HEAP];
180 exit if $heap->{INT};
184 my ($self,$sender,$kernel) = @_[OBJECT,SENDER,KERNEL];
186 # Since this is an irc_* event, we can get the component's object by
187 # accessing the heap of the sender. Then we register and connect to the
189 my $irc = $sender->get_heap();
191 print "Connected to ", $irc->server_name(), "\n";
193 $kernel->yield( 'auth' );
194 $irc->yield( mode => $irc->nick_name, '+ix');
196 # we join our channels
197 $irc->yield( join => $_ ) for grep /^#/, keys %{$self->disp->channels};
202 my ($self,$sender, $who, $channel) = @_[OBJECT,SENDER, ARG0 .. ARG1];
203 my $irc = $sender->get_heap();
205 $irc->yield( join => $_ ) for grep /^$channel$/i, keys %{$self->disp->channels}
209 $_[ARG2] = irc_to_utf8 $_[ARG2];
213 $_[ARG2] = irc_to_utf8 $_[ARG2];
223 my ($self, $msg, $server, $nick, $address, $channel, $model) = @_;
225 return if $channel !~ /^#/ && $msg =~ /^~/;
226 $msg = ".$msg" if $channel !~ /^#/ && $msg =~ /^[^.!]/;
228 my ($p,$command,$args) = ($msg =~ /^([.!~])(\S+)(?: (.+))?/);
230 if ($msg =~ m{http://[\w.]+/.+?scan(_id|_grp)?=(\w+)}){
231 if (!$command || $command =~ m{^http://}){
232 ($p,$command,$args) = ('.','addscan',$msg);
233 }elsif($command ne 'addscan'){
234 $self->parseCommand (".addscan $msg", $server, $nick, $address, $channel, $model)
238 return 0 unless $self->disp->has_command($command,$channel);
243 $reply_string = "privmsg $nick";
246 $reply_string = "privmsg $channel";
249 $reply_string = "notice $nick";
253 $address =~ s/.*@(.*)/$1/;
254 my $c = NDIRC::Context->new({
261 reply_string => $reply_string,
264 return $self->disp->run_command($c,$command,$args);