summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2009-01-25 01:44:55 -0500
committerdoy <doy@tozt.net>2009-01-25 01:44:55 -0500
commit72af015df49a30bd8e4f72e4926a7ffb5d1eddd3 (patch)
tree5413c70e95364d59d93bfcbfd28ed00964480498 /lib
parentdfd11a941cf5412f9f2a626030733c289b2acbc2 (diff)
downloadbot-games-72af015df49a30bd8e4f72e4926a7ffb5d1eddd3.tar.gz
bot-games-72af015df49a30bd8e4f72e4926a7ffb5d1eddd3.zip
handle initialization better - make sure init is called before taking any turns, but don't call it if we're just doing a command (to make "!24 -help" work properly)
Diffstat (limited to 'lib')
-rw-r--r--lib/Bot/Games.pm15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Bot/Games.pm b/lib/Bot/Games.pm
index e97644a..aef9a18 100644
--- a/lib/Bot/Games.pm
+++ b/lib/Bot/Games.pm
@@ -20,6 +20,13 @@ has active_games => (
default => sub { {} },
);
+has done_init => (
+ is => 'ro',
+ isa => 'HashRef[Bool]',
+ lazy => 1,
+ default => sub { {} },
+);
+
sub _get_command {
my ($game, $action) = @_;
my $method_meta = $game->meta->find_method_by_name($action);
@@ -41,13 +48,17 @@ sub said {
my $output;
my $game = $self->active_games->{$game_name};
- if (!defined $game || !defined $action) {
+ if (!defined $game) {
my $game_package = $self->game_package($game_name);
eval "require $game_package";
$game = $game_package->new;
$self->active_games->{$game_name} = $game;
- return $self->_format($game->init($args->{who}))
+ $self->done_init->{$game_name} = 0;
+ }
+ if (!$self->done_init->{$game_name} && $action !~ /^-/) {
+ $self->say(%$args, body => $self->_format($game->init($args->{who})))
if $game->can('init');
+ $self->done_init->{$game_name} = 1;
}
return unless defined $action;