]> ruin.nu Git - NDIRC.git/commitdiff
Move things to bot specific class + some more shared code
authorMichael Andreen <harv@ruin.nu>
Mon, 17 Aug 2009 11:50:36 +0000 (13:50 +0200)
committerMichael Andreen <harv@ruin.nu>
Mon, 17 Aug 2009 11:50:36 +0000 (13:50 +0200)
CommonStates.pm
Delling.pm [new file with mode: 0644]
ndawn.pl

index 655bbba8442c6b6eedb18fffde017c6e8ce1bdc9..7da1c512788281d2d9954689e4a9a59824576e10 100644 (file)
@@ -23,6 +23,7 @@ use warnings;
 use feature ':5.10';
 
 use POE::Session;
+use NDIRC::Dispatcher;
 
 # We registered for all events, this will produce some debug info.
 sub _default {
@@ -63,6 +64,28 @@ sub _start {
        return;
 }
 
+sub sig_usr2 {
+       my $heap = $_[HEAP];
+
+       open COMMANDS, 'commands';
+       my @commands = split /\W+/, do { local $/; <COMMANDS> };
+       close COMMANDS;
+
+       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);
+       }
+       close CHANNELS;
+
+       $heap->{disp} = $disp;
+}
+
 sub sig_DIE {
        my( $kernel,$sig, $ex ) = @_[ KERNEL,ARG0, ARG1 ];
        say "DIED!!!!!!!!!!!!!!";
diff --git a/Delling.pm b/Delling.pm
new file mode 100644 (file)
index 0000000..26e9784
--- /dev/null
@@ -0,0 +1,98 @@
+#**************************************************************************
+#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
+#                                                                         *
+#   This program is free software; you can redistribute it and/or modify  *
+#   it under the terms of the GNU General Public License as published by  *
+#   the Free Software Foundation; either version 2 of the License, or     *
+#   (at your option) any later version.                                   *
+#                                                                         *
+#   This program is distributed in the hope that it will be useful,       *
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+#   GNU General Public License for more details.                          *
+#                                                                         *
+#   You should have received a copy of the GNU General Public License     *
+#   along with this program; if not, write to the                         *
+#   Free Software Foundation, Inc.,                                       *
+#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
+#**************************************************************************/
+package NDIRC::Delling;
+
+use strict;
+use warnings;
+use feature ':5.10';
+
+use POE::Session;
+use NDIRC::Misc;
+use ND::DB;
+
+my $DBH = DB();
+my $TICK = $DBH->selectrow_array('SELECT tick()');
+
+sub irc_public {
+       my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
+       my ($nick,$username,$address) = ( split /[!@]/, $who );
+       my $channel = $where->[0];
+
+       my $irc = $sender->get_heap();
+
+       #$irc->yield(privmsg => $channel, "Authed? " . $irc->is_nick_authed($nick));
+
+       if ($msg =~ /^(\S+): (.+)$/ && $heap->{disp}->has_command('anon',$channel)){
+               my $_ = $1;
+               my $text = $2;
+               unless ($irc->is_channel_member($channel,$1) || /(Constructing|Researching)/){
+                       $msg = ".anon $_ $text";
+               }
+
+       }
+       if (parseCommand($msg,$irc,$nick,$address,$channel,$heap->{disp},DB())){
+               #Command parsed and run successfully
+       }
+}
+
+
+sub irc_msg {
+       my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
+       my ($nick,$username,$address) = ( split /[!@]/, $who );
+       my $irc = $sender->get_heap();
+
+       if (parseCommand($msg,$irc,$nick,$address,'pm',$heap->{disp},DB())){
+               #Command parsed and run successfully
+       }
+}
+
+sub irc_join {
+       my ($sender, $heap, $who, $channel) = @_[SENDER, HEAP, ARG0 .. ARG1];
+       my ($nick,$username,$address) = ( split /[!@]/, $who );
+       my $irc = $sender->get_heap();
+
+       if($heap->{disp}->has_command('voice',$channel)){
+               my $dbh = DB();
+               my $flags = $dbh->prepare_cached(q{
+SELECT DISTINCT flag
+FROM users u
+       JOIN groupmembers g USING (uid)
+       JOIN channel_group_flags gf USING (gid)
+WHERE u.hostmask = $1 AND channel = $2 AND flag IN ('o','v');
+               });
+               $flags->execute($address, $channel);
+               my $mode = '';
+               my @who;
+               while (my ($flag) = $flags->fetchrow()){
+                       $mode .= $flag;
+                       push @who, $nick;
+               }
+               say "$mode - @who";
+               $irc->yield(mode => $channel, $mode, @who) if $mode;
+       }
+}
+
+sub refresh {
+       my ($kernel,$heap) = @_[KERNEL,HEAP];
+       print 'Time: ' . time() . ' Lag: ' . $heap->{connector}->lag() . "\n";
+       $kernel->delay( refresh => 60 );
+       return;
+}
+
+1;
index e1b08a59eb21e5b930557c38882174da8064fa06..672c8ba08454501b1c386e281ae4a52ae12d5512 100755 (executable)
--- a/ndawn.pl
+++ b/ndawn.pl
@@ -29,13 +29,8 @@ use POE::Component::IRC::Plugin::BotTraffic;
 use POE::Component::IRC::Plugin::Connector;
 use POE::Component::IRC::Plugin::DCC;
 
-use ND::DB;
-use ND::Include;
-use NDIRC::Dispatcher;
-use NDIRC::Context;
-use NDIRC::Command;
-use NDIRC::Misc;
 use NDIRC::CommonStates;
+use NDIRC::Delling;
 
 my $nickname = 'ndbot';
 my $ircname = 'ND test bot';
@@ -63,106 +58,16 @@ $irc->plugin_add('Logger', POE::Component::IRC::Plugin::Logger->new(
        Strip_formatting => 1,
 ));
 
-my $DBH = DB();
-my $TICK = $DBH->selectrow_array('SELECT tick()');
-
 $ND::scanchan = '#testarmer';
 $ND::defchan = '#testarlite';
 $ND::memchan = '#testarmer';
 
 POE::Session->create(
        package_states => [
-               'NDIRC::CommonStates' => [ qw(_default _start irc_001 sig_DIE signal_handler irc_disconnected irc_invite) ],
-               main => [ qw(irc_public irc_msg refresh sig_usr2 irc_join) ],
+               'NDIRC::CommonStates' => [ qw(_default _start irc_001 sig_DIE sig_usr2 signal_handler irc_disconnected irc_invite) ],
+               'NDIRC::Delling' => [ qw(irc_public irc_msg refresh irc_join) ],
        ],
        heap => { irc => $irc},
 );
 
 $poe_kernel->run();
-
-
-sub sig_usr2 {
-       my $heap = $_[HEAP];
-
-       my $disp = new NDIRC::Dispatcher;
-
-       $disp->load(qw/Basic SMS Channel Def Intel Members PA Quotes Usermgm/);
-
-       open CHANNELS, 'channels';
-       while (<CHANNELS>){
-               print;
-               my ($chan, @types) = split /\s+/;
-               say "$chan - @types";
-               $disp->add_channel($chan,\@types);
-       }
-       close CHANNELS;
-
-       $heap->{disp} = $disp;
-}
-
-
-sub irc_public {
-       my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
-       my ($nick,$username,$address) = ( split /[!@]/, $who );
-       my $channel = $where->[0];
-
-       my $irc = $sender->get_heap();
-
-       #$irc->yield(privmsg => $channel, "Authed? " . $irc->is_nick_authed($nick));
-
-       if ($msg =~ /^(\S+): (.+)$/ && $heap->{disp}->has_command('anon',$channel)){
-               my $_ = $1;
-               my $text = $2;
-               unless ($irc->is_channel_member($channel,$1) || /(Constructing|Researching)/){
-                       $msg = ".anon $_ $text";
-               }
-
-       }
-       if (parseCommand($msg,$irc,$nick,$address,$channel,$heap->{disp},DB())){
-               #Command parsed and run successfully
-       }
-}
-
-
-sub irc_msg {
-       my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
-       my ($nick,$username,$address) = ( split /[!@]/, $who );
-       my $irc = $sender->get_heap();
-
-       if (parseCommand($msg,$irc,$nick,$address,'pm',$heap->{disp},DB())){
-               #Command parsed and run successfully
-       }
-}
-
-sub irc_join {
-       my ($sender, $heap, $who, $channel) = @_[SENDER, HEAP, ARG0 .. ARG1];
-       my ($nick,$username,$address) = ( split /[!@]/, $who );
-       my $irc = $sender->get_heap();
-
-       if($heap->{disp}->has_command('voice',$channel)){
-               my $dbh = DB();
-               my $flags = $dbh->prepare_cached(q{
-SELECT DISTINCT flag
-FROM users u
-       JOIN groupmembers g USING (uid)
-       JOIN channel_group_flags gf USING (gid)
-WHERE u.hostmask = $1 AND channel = $2 AND flag IN ('o','v');
-               });
-               $flags->execute($address, $channel);
-               my $mode = '';
-               my @who;
-               while (my ($flag) = $flags->fetchrow()){
-                       $mode .= $flag;
-                       push @who, $nick;
-               }
-               say "$mode - @who";
-               $irc->yield(mode => $channel, $mode, @who) if $mode;
-       }
-}
-
-sub refresh {
-       my ($kernel,$heap) = @_[KERNEL,HEAP];
-       print 'Time: ' . time() . ' Lag: ' . $heap->{connector}->lag() . "\n";
-       $kernel->delay( refresh => 60 );
-       return;
-}