X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=CommonStates.pm;h=dd35657a0ac6f96d44926d9612a41b5e96a3ae2b;hb=dffb2b9f212ffb49763d329bc8ca044d95e72da1;hp=655bbba8442c6b6eedb18fffde017c6e8ce1bdc9;hpb=e8c94cdebefdc428ea92fde6db63f18d3e8399b2;p=NDIRC.git diff --git a/CommonStates.pm b/CommonStates.pm index 655bbba..dd35657 100644 --- a/CommonStates.pm +++ b/CommonStates.pm @@ -23,6 +23,12 @@ 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::DCC; + +use NDIRC::Dispatcher; # We registered for all events, this will produce some debug info. sub _default { @@ -51,6 +57,18 @@ sub _start { $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} ); @@ -63,6 +81,33 @@ sub _start { return; } +sub sig_usr1 { + my $kernel = $_[KERNEL]; + $kernel->yield( 'refresh' ); +} + +sub sig_usr2 { + my $heap = $_[HEAP]; + + open COMMANDS, 'commands'; + my @commands = split /\W+/, do { local $/; }; + close COMMANDS; + + say "Loading commands from: @commands"; + my $disp = new NDIRC::Dispatcher; + $disp->load(@commands); + + open CHANNELS, 'channels'; + while (){ + my ($chan, @types) = split /\s+/; + say "$chan - @types"; + $disp->add_channel($chan,\@types); + } + close CHANNELS; + + $heap->{disp} = $disp; +} + sub sig_DIE { my( $kernel,$sig, $ex ) = @_[ KERNEL,ARG0, ARG1 ]; say "DIED!!!!!!!!!!!!!!"; @@ -81,10 +126,9 @@ 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->{irc}->yield(quit => 'Bye!'); $kernel->sig_handled(); }