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 #**************************************************************************/
28 use POE::Component::IRC::Plugin::Logger;
29 use POE::Component::IRC::Plugin::BotTraffic;
30 use POE::Component::IRC::Plugin::Connector;
31 use POE::Component::IRC::Plugin::AutoJoin;
32 use POE::Component::IRC::Plugin::NickReclaim;
34 use NDIRC::Dispatcher;
44 # We registered for all events, this will produce some debug info.
46 my ($event, $args) = @_[ARG0 .. $#_];
47 my @output = ( "$event: " );
49 for my $arg (@$args) {
50 if ( ref $arg eq 'ARRAY' ) {
51 push( @output, '[' . join(', ', @$arg ) . ']' );
54 push ( @output, "'$arg'" );
57 print join ' ', @output, "\n";
62 my ($kernel,$heap,$session) = @_[KERNEL,HEAP,SESSION];
64 # retrieve our component's object from the heap where we stashed it
65 my $irc = $heap->{irc};
66 $kernel->sig( DIE => 'sig_DIE' );
67 $kernel->sig( USR1 => 'sig_usr1' );
68 $kernel->sig( USR2 => 'sig_usr2' );
69 $kernel->sig( INT => 'signal_handler' );
71 $irc->plugin_add( 'NickReclaim', POE::Component::IRC::Plugin::NickReclaim->new() );
72 $irc->plugin_add( 'AutoJoin', POE::Component::IRC::Plugin::NickReclaim->new() );
73 $irc->plugin_add( 'BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new() );
74 $irc->plugin_add('Logger', POE::Component::IRC::Plugin::Logger->new(
81 Strip_formatting => 1,
84 $heap->{connector} = POE::Component::IRC::Plugin::Connector->new(
85 servers => ['irc.netgamers.org', 'underworld.no.eu.netgamers.org'
86 ,'firefly.no.eu.netgamers.org', 'underworld.ca.us.netgamers.org' ]
88 $irc->plugin_add( 'Connector' => $heap->{connector} );
90 $irc->yield( register => 'all' );
91 $irc->yield( connect => { server => 'irc.netgamers.org' } );
93 $kernel->delay( refresh => 60 );
100 if (my $f = new IO::File 'auth'){
105 $heap->{irc}->yield(qbot_auth => $user => $pass);
110 my ($kernel,$heap) = @_[KERNEL,HEAP];
112 $kernel->yield( 'refresh' );
118 $self->disp($self->_build_disp);
123 my $disp = new NDIRC::Dispatcher;
125 if (my $commands = new IO::File 'commands'){
126 my @commands = split /\W+/, do{local $/; <$commands>};
127 say "Loading commands from: @commands";
128 $disp->load(@commands);
131 my $channels = new IO::File 'channels' or die $!;;
133 my ($chan, @types) = split /\s+/;
134 say "$chan - @types";
135 if ($chan =~ /^(.*):(.*)$/){
137 $disp->set_target($2,$chan);
139 $disp->add_channel($chan,\@types);
146 my( $kernel,$sig, $ex ) = @_[ KERNEL,ARG0, ARG1 ];
147 say "DIED!!!!!!!!!!!!!!";
149 # $ex is the exception hash
150 warn "$$: error in event: $ex->{error_str}";
151 $kernel->sig_handled();
153 # Send the signal to session that sent the original event.
154 #if( $ex->{source_session} ne $_[SESSION] ) {
155 #$kernel->signal( $ex->{source_session}, 'DIE', $sig, $ex );
160 my ($kernel, $signal_name, $heap) = @_[KERNEL, ARG0, HEAP];
161 print "First session caught SIG$signal_name\n";
165 exit unless $heap->{irc}->connected;
167 $heap->{irc}->yield(quit => 'Bye!');
168 $kernel->sig_handled();
171 #$kernel->sig_handled();
174 sub irc_disconnected {
175 my ($sender,$heap) = @_[SENDER,HEAP];
177 exit if $heap->{INT};
181 my ($self,$sender,$kernel) = @_[OBJECT,SENDER,KERNEL];
183 # Since this is an irc_* event, we can get the component's object by
184 # accessing the heap of the sender. Then we register and connect to the
186 my $irc = $sender->get_heap();
188 print "Connected to ", $irc->server_name(), "\n";
190 $kernel->yield( 'auth' );
191 $irc->yield( mode => $irc->nick_name, '+ix');
193 # we join our channels
194 $irc->yield( join => $_ ) for grep /^#/, keys %{$self->disp->channels};
199 my ($self,$sender, $who, $channel) = @_[OBJECT,SENDER, ARG0 .. ARG1];
200 my $irc = $sender->get_heap();
202 $irc->yield( join => $_ ) for grep /^$channel$/i, keys %{$self->disp->channels}
218 my ($self, $msg, $server, $nick, $address, $channel, $model) = @_;
220 return if $channel !~ /^#/ && $msg =~ /^~/;
221 $msg = ".$msg" if $channel !~ /^#/ && $msg =~ /^[^.!]/;
223 my ($p,$command,$args) = ($msg =~ /^([.!~])(\S+)(?: (.+))?/);
225 if ($msg =~ m{http://[\w.]+/.+?scan(_id|_grp)?=(\w+)}){
226 if (!$command || $command =~ m{^http://}){
227 ($p,$command,$args) = ('.','addscan',$msg);
228 }elsif($command ne 'addscan'){
229 $self->parseCommand (".addscan $msg", $server, $nick, $address, $channel, $model)
233 return 0 unless $self->disp->has_command($command,$channel);
238 $reply_string = "privmsg $nick";
241 $reply_string = "privmsg $channel";
244 $reply_string = "notice $nick";
248 $address =~ s/.*@(.*)/$1/;
249 my $c = NDIRC::Context->new({
256 reply_string => $reply_string,
259 return $self->disp->run_command($c,$command,$args);