]> ruin.nu Git - NDIRC.git/commitdiff
A bit more for the common states
authorMichael Andreen <harv@ruin.nu>
Mon, 17 Aug 2009 15:31:45 +0000 (17:31 +0200)
committerMichael Andreen <harv@ruin.nu>
Mon, 17 Aug 2009 15:31:45 +0000 (17:31 +0200)
CommonStates.pm
ndawn.pl

index 7da1c512788281d2d9954689e4a9a59824576e10..dd35657a0ac6f96d44926d9612a41b5e96a3ae2b 100644 (file)
@@ -23,6 +23,11 @@ use warnings;
 use feature ':5.10';
 
 use POE::Session;
 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::DCC;
+
 use NDIRC::Dispatcher;
 
 # We registered for all events, this will produce some debug info.
 use NDIRC::Dispatcher;
 
 # We registered for all events, this will produce some debug info.
@@ -52,6 +57,18 @@ sub _start {
        $kernel->sig( USR2 => 'sig_usr2' );
        $kernel->sig( INT => 'signal_handler' );
 
        $kernel->sig( USR2 => 'sig_usr2' );
        $kernel->sig( INT => 'signal_handler' );
 
+       $irc->plugin_add( 'BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new() );
+       $irc->plugin_add( 'DCC', POE::Component::IRC::Plugin::DCC->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();
        $irc->plugin_add( 'Connector' => $heap->{connector} );
 
        $heap->{connector} = POE::Component::IRC::Plugin::Connector->new();
        $irc->plugin_add( 'Connector' => $heap->{connector} );
 
@@ -64,6 +81,11 @@ sub _start {
        return;
 }
 
        return;
 }
 
+sub sig_usr1 {
+       my $kernel = $_[KERNEL];
+       $kernel->yield( 'refresh' );
+}
+
 sub sig_usr2 {
        my $heap = $_[HEAP];
 
 sub sig_usr2 {
        my $heap = $_[HEAP];
 
@@ -71,12 +93,12 @@ sub sig_usr2 {
        my @commands = split /\W+/, do { local $/; <COMMANDS> };
        close COMMANDS;
 
        my @commands = split /\W+/, do { local $/; <COMMANDS> };
        close COMMANDS;
 
+       say "Loading commands from: @commands";
        my $disp = new NDIRC::Dispatcher;
        $disp->load(@commands);
 
        open CHANNELS, 'channels';
        while (<CHANNELS>){
        my $disp = new NDIRC::Dispatcher;
        $disp->load(@commands);
 
        open CHANNELS, 'channels';
        while (<CHANNELS>){
-               print;
                my ($chan, @types) = split /\s+/;
                say "$chan - @types";
                $disp->add_channel($chan,\@types);
                my ($chan, @types) = split /\s+/;
                say "$chan - @types";
                $disp->add_channel($chan,\@types);
@@ -104,10 +126,9 @@ sub signal_handler {
        my ($kernel, $signal_name, $heap) = @_[KERNEL, ARG0, HEAP];
        print "First session caught SIG$signal_name\n";
 
        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') {
        given($signal_name){
                when ('INT') {
+                       exit unless $heap->{irc}->connected;
                        $heap->{irc}->yield(quit => 'Bye!');
                        $kernel->sig_handled();
                }
                        $heap->{irc}->yield(quit => 'Bye!');
                        $kernel->sig_handled();
                }
index 672c8ba08454501b1c386e281ae4a52ae12d5512..f2eafaa9f74c7dbeb16599badcadf953ffb62509 100755 (executable)
--- a/ndawn.pl
+++ b/ndawn.pl
@@ -24,10 +24,6 @@ use warnings;
 use feature ':5.10';
 use POE qw(Component::IRC::Qnet::State);
 
 use feature ':5.10';
 use POE qw(Component::IRC::Qnet::State);
 
-use POE::Component::IRC::Plugin::Logger;
-use POE::Component::IRC::Plugin::BotTraffic;
-use POE::Component::IRC::Plugin::Connector;
-use POE::Component::IRC::Plugin::DCC;
 
 use NDIRC::CommonStates;
 use NDIRC::Delling;
 
 use NDIRC::CommonStates;
 use NDIRC::Delling;
@@ -46,25 +42,14 @@ my $irc = POE::Component::IRC::Qnet::State->spawn(
 
 $irc->service_bots(QBOT => 'P@cservice.netgamers.org');
 
 
 $irc->service_bots(QBOT => 'P@cservice.netgamers.org');
 
-$irc->plugin_add( 'BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new() );
-$irc->plugin_add( 'DCC', POE::Component::IRC::Plugin::DCC->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,
-));
-
 $ND::scanchan = '#testarmer';
 $ND::defchan = '#testarlite';
 $ND::memchan = '#testarmer';
 
 POE::Session->create(
        package_states => [
 $ND::scanchan = '#testarmer';
 $ND::defchan = '#testarlite';
 $ND::memchan = '#testarmer';
 
 POE::Session->create(
        package_states => [
-               'NDIRC::CommonStates' => [ qw(_default _start irc_001 sig_DIE sig_usr2 signal_handler irc_disconnected irc_invite) ],
+               'NDIRC::CommonStates' => [ qw(_default _start irc_001 sig_DIE sig_usr1 sig_usr2
+                       signal_handler irc_disconnected irc_invite) ],
                'NDIRC::Delling' => [ qw(irc_public irc_msg refresh irc_join) ],
        ],
        heap => { irc => $irc},
                'NDIRC::Delling' => [ qw(irc_public irc_msg refresh irc_join) ],
        ],
        heap => { irc => $irc},