summaryrefslogtreecommitdiffstats
path: root/lib/Bot
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2009-01-25 16:52:07 -0500
committerdoy <doy@tozt.net>2009-01-25 16:52:07 -0500
commit99ef5f93750eb53c4b976a710c7e5a2fdcdeb8f6 (patch)
tree1e90d78f7c49489730f8b141ef709dfcb2ec4bb3 /lib/Bot
parent90b080af6b0e42b817413e9da6484311cdae18d0 (diff)
downloadbot-games-99ef5f93750eb53c4b976a710c7e5a2fdcdeb8f6.tar.gz
bot-games-99ef5f93750eb53c4b976a710c7e5a2fdcdeb8f6.zip
allow marking commands as requiring an init call before being called - default everything to this
Diffstat (limited to 'lib/Bot')
-rw-r--r--lib/Bot/Games.pm4
-rw-r--r--lib/Bot/Games/Meta/Role/Attribute.pm7
-rw-r--r--lib/Bot/Games/Meta/Role/Command.pm6
3 files changed, 17 insertions, 0 deletions
diff --git a/lib/Bot/Games.pm b/lib/Bot/Games.pm
index 654f288..ad65db8 100644
--- a/lib/Bot/Games.pm
+++ b/lib/Bot/Games.pm
@@ -77,6 +77,10 @@ sub said {
# XXX: maybe the meta stuff should get pushed out into the plugins
# themselves, and this should become $game->meta->get_command or so?
if (my $method_meta = _get_command($game, $action)) {
+ if ($method_meta->needs_init) {
+ $self->$say($game->init($args->{who})) if $game->can('init');
+ $self->done_init->{$game_name} = 1;
+ }
$self->$say($method_meta->execute($game, $arg,
{player => $args->{who}}));
}
diff --git a/lib/Bot/Games/Meta/Role/Attribute.pm b/lib/Bot/Games/Meta/Role/Attribute.pm
index 70d36e6..e82ce58 100644
--- a/lib/Bot/Games/Meta/Role/Attribute.pm
+++ b/lib/Bot/Games/Meta/Role/Attribute.pm
@@ -8,6 +8,12 @@ has command => (
default => 0,
);
+has needs_init => (
+ is => 'rw',
+ isa => 'Bool',
+ default => 0,
+);
+
around accessor_metaclass => sub {
my $orig = shift;
my $self = shift;
@@ -25,6 +31,7 @@ after install_accessors => sub {
return unless $self->command;
my $method_meta = $self->get_read_method_ref;
$method_meta->pass_args(0);
+ $method_meta->needs_init($self->needs_init);
};
no Moose::Role;
diff --git a/lib/Bot/Games/Meta/Role/Command.pm b/lib/Bot/Games/Meta/Role/Command.pm
index 7c1c892..79db8b1 100644
--- a/lib/Bot/Games/Meta/Role/Command.pm
+++ b/lib/Bot/Games/Meta/Role/Command.pm
@@ -8,6 +8,12 @@ has pass_args => (
default => 1,
);
+has needs_init => (
+ is => 'rw',
+ isa => 'Bool',
+ default => 1,
+);
+
around execute => sub {
my $orig = shift;
my $self = shift;