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' );
118 sub clear_constraint {
122 if (ref $tc eq 'MooseX::Meta::TypeConstraint::Structured'){
123 for my $t (@{$tc->{type_constraints}}){
124 clear_constraint($t);
128 if (ref $tc eq 'Moose::Meta::TypeConstraint::Parameterized'){
129 clear_constraint($tc->{type_parameter});
131 last if ref $tc eq 'HASH';
132 last if ref $tc eq '';
133 if (defined $tc->{_type_constraint}){
134 $tc = $tc->{_type_constraint};
135 }elsif(defined $tc->{__type_constraint}){
136 $tc = $tc->{__type_constraint};
146 for my $a (@{$ins->{attributes}}){
147 for my $m (@{$a->{associated_methods}}){
150 clear_constraint($a->{isa});
157 for my $m (values %{$c->meta->{methods}}){
158 clear_constraint($m->{type_constraint});
160 my $ps = $m->{parsed_signature};
161 for my $p (@{$ps->{_positional_params}->{params}}){
162 clear_metains($p->{__MOP__}->{_meta_instance});
167 clear_metains($c->meta->{_meta_instance});
174 for my $c (values %{$self->disp->commands}){
178 $self->disp($self->_build_disp);
183 my $disp = new NDIRC::Dispatcher;
185 if (my $commands = new IO::File 'commands'){
186 my @commands = split /\W+/, do{local $/; <$commands>};
187 say "Loading commands from: @commands";
188 $disp->load(@commands);
191 my $channels = new IO::File 'channels' or die $!;;
193 my ($chan, @types) = split /\s+/;
194 say "$chan - @types";
195 if ($chan =~ /^(.*):(.*)$/){
197 $disp->set_target($2,$chan);
199 $disp->add_channel($chan,\@types);
206 my( $kernel,$sig, $ex ) = @_[ KERNEL,ARG0, ARG1 ];
207 say "DIED!!!!!!!!!!!!!!";
209 # $ex is the exception hash
210 warn "$$: error in event: $ex->{error_str}";
211 $kernel->sig_handled();
213 # Send the signal to session that sent the original event.
214 #if( $ex->{source_session} ne $_[SESSION] ) {
215 #$kernel->signal( $ex->{source_session}, 'DIE', $sig, $ex );
220 my ($kernel, $signal_name, $heap) = @_[KERNEL, ARG0, HEAP];
221 print "First session caught SIG$signal_name\n";
225 exit unless $heap->{irc}->connected;
227 $heap->{irc}->yield(quit => 'Bye!');
228 $kernel->sig_handled();
231 #$kernel->sig_handled();
234 sub irc_disconnected {
235 my ($sender,$heap) = @_[SENDER,HEAP];
237 exit if $heap->{INT};
241 my ($self,$sender,$kernel) = @_[OBJECT,SENDER,KERNEL];
243 # Since this is an irc_* event, we can get the component's object by
244 # accessing the heap of the sender. Then we register and connect to the
246 my $irc = $sender->get_heap();
248 print "Connected to ", $irc->server_name(), "\n";
250 $kernel->yield( 'auth' );
251 $irc->yield( mode => $irc->nick_name, '+ix');
253 # we join our channels
254 $irc->yield( join => $_ ) for grep /^#/, keys %{$self->disp->channels};
259 my ($self,$sender, $who, $channel) = @_[OBJECT,SENDER, ARG0 .. ARG1];
260 my $irc = $sender->get_heap();
262 $irc->yield( join => $_ ) for grep /^$channel$/i, keys %{$self->disp->channels}
266 $_[ARG2] = irc_to_utf8 $_[ARG2];
270 $_[ARG2] = irc_to_utf8 $_[ARG2];
280 my ($self, $msg, $server, $nick, $address, $channel, $model) = @_;
282 return if $channel !~ /^#/ && $msg =~ /^~/;
283 $msg = ".$msg" if $channel !~ /^#/ && $msg =~ /^[^.!]/;
285 my ($p,$command,$args) = ($msg =~ /^([.!~])(\S+)(?: (.+))?/);
287 if ($msg =~ m{http://[\w.]+/.+?scan(_id|_grp)?=(\w+)}){
288 if (!$command || $command =~ m{^http://}){
289 ($p,$command,$args) = ('.','addscan',$msg);
290 }elsif($command ne 'addscan'){
291 $self->parseCommand (".addscan $msg", $server, $nick, $address, $channel, $model)
295 return 0 unless $self->disp->has_command($command,$channel);
300 $reply_string = "privmsg $nick";
303 $reply_string = "privmsg $channel";
306 $reply_string = "notice $nick";
310 $address =~ s/.*@(.*)/$1/;
311 my $c = NDIRC::Context->new({
318 reply_string => $reply_string,
321 return $self->disp->run_command($c,$command,$args);