From 05629ec258dcfc359decc3cbc44c3345dd0eb62e Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Thu, 20 Aug 2009 00:47:24 +0200 Subject: [PATCH] Use Moose and make the bots object-oriented with Bot as base class --- CommonStates.pm => Bot.pm | 18 ++++++++++++++++-- Delling.pm | 5 ++++- Eos.pm | 5 ++++- ndawn.pl | 12 ++++++------ 4 files changed, 30 insertions(+), 10 deletions(-) rename CommonStates.pm => Bot.pm (97%) diff --git a/CommonStates.pm b/Bot.pm similarity index 97% rename from CommonStates.pm rename to Bot.pm index e46481c..a4cd6e5 100644 --- a/CommonStates.pm +++ b/Bot.pm @@ -1,5 +1,5 @@ #************************************************************************** -# Copyright (C) 2006 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 * @@ -16,12 +16,14 @@ # Free Software Foundation, Inc., * # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * #**************************************************************************/ -package NDIRC::CommonStates; +package NDIRC::Bot; use strict; use warnings; use feature ':5.10'; +use Moose; + use POE::Session; use POE::Component::IRC::Plugin::Logger; use POE::Component::IRC::Plugin::BotTraffic; @@ -191,4 +193,16 @@ sub irc_invite { $irc->yield( join => $_ ) for grep /^$channel$/i, keys %{$heap->{disp}->channels} } +sub irc_public { +} + +sub irc_msg { +} + +sub refresh { +} + +sub irc_join { +} + 1; diff --git a/Delling.pm b/Delling.pm index 362e7aa..3314159 100644 --- a/Delling.pm +++ b/Delling.pm @@ -1,5 +1,5 @@ #************************************************************************** -# Copyright (C) 2006 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 * @@ -22,6 +22,9 @@ use strict; use warnings; use feature ':5.10'; +use Moose; +extends 'NDIRC::Bot'; + use POE::Session; use NDIRC::Misc; use ND::DB; diff --git a/Eos.pm b/Eos.pm index 079b7c9..258dd72 100644 --- a/Eos.pm +++ b/Eos.pm @@ -1,5 +1,5 @@ #************************************************************************** -# Copyright (C) 2006 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 * @@ -22,6 +22,9 @@ use strict; use warnings; use feature ':5.10'; +use Moose; +extends 'NDIRC::Bot'; + use POE::Session; use NDIRC::Misc; use ND::DB; diff --git a/ndawn.pl b/ndawn.pl index ca60ea2..a14ee36 100755 --- a/ndawn.pl +++ b/ndawn.pl @@ -24,8 +24,6 @@ use warnings; use feature ':5.10'; use POE qw(Component::IRC::Qnet::State); - -use NDIRC::CommonStates; eval "require NDIRC::$ARGV[0]"; die $@ if $@; @@ -38,11 +36,13 @@ my $irc = POE::Component::IRC::Qnet::State->spawn( $irc->service_bots(QBOT => 'P@cservice.netgamers.org'); +my $bot = eval "new NDIRC::$ARGV[0]"; + POE::Session->create( - package_states => [ - 'NDIRC::CommonStates' => [ qw(_default _start irc_001 sig_DIE sig_usr1 sig_usr2 - signal_handler irc_disconnected irc_invite auth) ], - "NDIRC::$ARGV[0]" => [ qw(irc_public irc_msg refresh irc_join) ], + 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 }, ); -- 2.39.2