X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=ndawn.pl;h=a14ee36fe319bef16eaaeb34b7eda5d8c3e5acf3;hb=82c9be26b28b12fded144d363ef81a6047e20d11;hp=6ddc8f74d44d134e80c95c03bf194e68166fd0aa;hpb=4f1948e0fe10075464732db5cc2168207c00c7aa;p=NDIRC.git diff --git a/ndawn.pl b/ndawn.pl old mode 100644 new mode 100755 index 6ddc8f7..a14ee36 --- a/ndawn.pl +++ b/ndawn.pl @@ -1,5 +1,7 @@ +#!/usr/bin/perl -w + #************************************************************************** -# Copyright (C) 2008 by Michael Andreen * +# Copyright (C) 2009 by Michael Andreen * # * # 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 * @@ -15,75 +17,34 @@ # along with this program; if not, write to the * # Free Software Foundation, Inc., * # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -#**************************************************************************/ +#************************************************************************** use strict; use warnings; -use vars qw($VERSION %IRSSI); - -use Irssi; -use Irssi::Irc; - -$VERSION = "0.1"; -%IRSSI = ( - authors => "harv", - contact => "harv\@ruin.nu", - name => "NewDawn testbot script", - description => "Testbot used for implementing commands for nd bots", - license => "GPL-2 or (at your option) any later version", - url => "", - changed => "", -); - -$ND::refresh = 0; - -$SIG{USR1} = sub{ - print "USR1"; - $ND::refresh = 1; -}; - +use feature ':5.10'; +use POE qw(Component::IRC::Qnet::State); -use again 'ND::DB'; -use again 'ND::Include'; -use again 'NDIRC::Dispatcher'; -use again 'NDIRC::Context'; -use again 'NDIRC::Command'; -use again 'NDIRC::Misc'; +eval "require NDIRC::$ARGV[0]"; -my $DBH = DB(); -my $TICK = $DBH->selectrow_array('SELECT tick()'); +die $@ if $@; -my $disp = new NDIRC::Dispatcher; +# We create a new PoCo-IRC object +my $irc = POE::Component::IRC::Qnet::State->spawn( + nick => $ARGV[0], + ircname => 'ND bot', +) or die "Oh noooo! $!"; -$disp->load('Basic'); +$irc->service_bots(QBOT => 'P@cservice.netgamers.org'); -$disp->add_channel('#testarlite', ['pub','help']); -$disp->add_channel('#testarmer', ['pub','help']); - -sub event_pubmsg { - my ($server, $msg, $nick, $address, $channel) = @_; - - if (parseCommand($msg,$server,$nick,$address,$channel,$disp,DB())){ - #Command parsed and run successfully - } -} - -sub event_privmsg { - my ($server, $msg, $nick, $address) = @_; - - if (parseCommand($msg,$server,$nick,$address,'pm',$disp,DB())){ - #Command parsed and run successfully - } -} - -sub refresh { - print "SiG" if $ND::refresh; - $ND::refresh = 0; -} - -Irssi::timeout_add(60*1000, 'refresh', undef); -Irssi::timeout_add(1000, sub{refresh if $ND::refresh}, undef); -Irssi::signal_add('message public','event_pubmsg'); -Irssi::signal_add('message private','event_privmsg'); +my $bot = eval "new NDIRC::$ARGV[0]"; +POE::Session->create( + object_states => [ + $bot => [ qw(_default _start irc_001 sig_DIE sig_usr1 sig_usr2 + signal_handler irc_disconnected irc_invite auth + irc_public irc_msg refresh irc_join) ], + ], + heap => { irc => $irc }, +); +$poe_kernel->run();