]> ruin.nu Git - NDIRC.git/blobdiff - CommonStates.pm
Removed the global variables for special chans, using targets hashref in Dispatcher...
[NDIRC.git] / CommonStates.pm
index 655bbba8442c6b6eedb18fffde017c6e8ce1bdc9..e46481cdc0f648f93e27539a14cf4368ca880ef9 100644 (file)
@@ -23,6 +23,15 @@ use warnings;
 use feature ':5.10';
 
 use POE::Session;
+use POE::Component::IRC::Plugin::Logger;
+use POE::Component::IRC::Plugin::BotTraffic;
+use POE::Component::IRC::Plugin::Connector;
+use POE::Component::IRC::Plugin::AutoJoin;
+use POE::Component::IRC::Plugin::NickReclaim;
+
+use NDIRC::Dispatcher;
+
+use IO::File;
 
 # We registered for all events, this will produce some debug info.
 sub _default {
@@ -51,18 +60,77 @@ sub _start {
        $kernel->sig( USR2 => 'sig_usr2' );
        $kernel->sig( INT => 'signal_handler' );
 
-       $heap->{connector} = POE::Component::IRC::Plugin::Connector->new();
+       $irc->plugin_add( 'NickReclaim', POE::Component::IRC::Plugin::NickReclaim->new() );
+       $irc->plugin_add( 'AutoJoin', POE::Component::IRC::Plugin::NickReclaim->new() );
+       $irc->plugin_add( 'BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new() );
+       $irc->plugin_add('Logger', POE::Component::IRC::Plugin::Logger->new(
+               Path    => 'irclogs',
+               DCC     => 0,
+               Private => 1,
+               Public  => 1,
+               Sort_by_date => 1,
+               Strip_color => 1,
+               Strip_formatting => 1,
+       ));
+
+       $heap->{connector} = POE::Component::IRC::Plugin::Connector->new(
+               servers => ['irc.netgamers.org', 'underworld.no.eu.netgamers.org'
+                       ,'firefly.no.eu.netgamers.org', 'underworld.ca.us.netgamers.org' ]
+       );
        $irc->plugin_add( 'Connector' => $heap->{connector} );
 
        $kernel->signal($session => 'USR2');
 
        $irc->yield( register => 'all' );
-       $irc->yield( connect => { } );
+       $irc->yield( connect => { server => 'irc.netgamers.org' } );
 
        $kernel->delay( refresh => 60 );
        return;
 }
 
+sub auth {
+       my $heap = $_[HEAP];
+
+       if (my $f =  new IO::File 'auth'){
+               my $user = <$f>;
+               chomp $user;
+               my $pass = <$f>;
+               chomp $pass;
+               $heap->{irc}->yield(qbot_auth => $user => $pass);
+       }
+}
+
+sub sig_usr1 {
+       my ($kernel,$heap) = @_[KERNEL,HEAP];
+
+       $kernel->yield( 'refresh' );
+}
+
+sub sig_usr2 {
+       my $heap = $_[HEAP];
+
+       my $disp = new NDIRC::Dispatcher;
+
+       if (my $commands = new IO::File 'commands'){
+               my @commands = split /\W+/, do{local $/; <$commands>};
+               say "Loading commands from: @commands";
+               $disp->load(@commands);
+       }
+
+       my $channels = new IO::File 'channels';
+       while (<$channels>){
+               my ($chan, @types) = split /\s+/;
+               say "$chan - @types";
+               if ($chan =~ /^(.*):(.*)$/){
+                       $chan = $1;
+                       $disp->set_target($2,$chan);
+               }
+               $disp->add_channel($chan,\@types);
+       }
+
+       $heap->{disp} = $disp;
+}
+
 sub sig_DIE {
        my( $kernel,$sig, $ex ) = @_[ KERNEL,ARG0, ARG1 ];
        say "DIED!!!!!!!!!!!!!!";
@@ -81,10 +149,10 @@ sub signal_handler {
        my ($kernel, $signal_name, $heap) = @_[KERNEL, ARG0, HEAP];
        print "First session caught SIG$signal_name\n";
 
-       $heap->{irc}->yield(privmsg => '#testarlite', "SIGNAL $signal_name!");
-
        given($signal_name){
                when ('INT') {
+                       exit unless $heap->{irc}->connected;
+                       $heap->{INT} = 1;
                        $heap->{irc}->yield(quit => 'Bye!');
                        $kernel->sig_handled();
                }
@@ -95,11 +163,11 @@ sub signal_handler {
 sub irc_disconnected {
        my ($sender,$heap) = @_[SENDER,HEAP];
 
-       exit;
+       exit if $heap->{INT};
 }
 
 sub irc_001 {
-       my ($sender,$heap) = @_[SENDER,HEAP];
+       my ($sender,$heap,$kernel) = @_[SENDER,HEAP,KERNEL];
 
        # Since this is an irc_* event, we can get the component's object by
        # accessing the heap of the sender. Then we register and connect to the
@@ -108,6 +176,9 @@ sub irc_001 {
 
        print "Connected to ", $irc->server_name(), "\n";
 
+       $kernel->yield( 'auth' );
+       $irc->yield( mode => $irc->nick_name, '+ix');
+
        # we join our channels
        $irc->yield( join => $_ ) for grep /^#/, keys %{$heap->{disp}->channels};
        return;