summaryrefslogtreecommitdiffstats
path: root/lib/Bot/Games.pm
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2009-01-26 00:12:36 -0500
committerdoy <doy@tozt.net>2009-01-26 00:12:36 -0500
commitee0258b8dd7f70267b52c3275fa52d596621171a (patch)
tree0bb05c6685847c5ac783cc38c1c2ab2a340f8784 /lib/Bot/Games.pm
parent6bf405053fae5d67184eaa3c757a9fe87b49e48b (diff)
downloadbot-games-ee0258b8dd7f70267b52c3275fa52d596621171a.tar.gz
bot-games-ee0258b8dd7f70267b52c3275fa52d596621171a.zip
allow abbreviations and aliases for game names
Diffstat (limited to 'lib/Bot/Games.pm')
-rw-r--r--lib/Bot/Games.pm24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/Bot/Games.pm b/lib/Bot/Games.pm
index 52be3a9..36544fc 100644
--- a/lib/Bot/Games.pm
+++ b/lib/Bot/Games.pm
@@ -34,6 +34,15 @@ has done_init => (
default => sub { {} },
);
+has alias => (
+ is => 'ro',
+ isa => 'HashRef[Str]',
+ default => sub { {
+ sg => 'superghost',
+ xg => 'xghost',
+ } },
+);
+
my $say;
my $say_args;
@@ -67,7 +76,8 @@ sub said {
$game_name =~ s/^-//;
$action = '-help';
}
- return unless $self->valid_game($game_name);
+ $game_name = $self->find_game($game_name);
+ return unless $game_name;
my $output;
my $game = $self->active_games->{$game_name};
@@ -137,6 +147,18 @@ sub game_list {
$self->games;
}
+sub find_game {
+ my $self = shift;
+ my ($abbrev) = @_;
+ return $abbrev if $self->valid_game($abbrev);
+ return $self->alias->{$abbrev}
+ if exists $self->alias->{$abbrev}
+ && $self->valid_game($self->alias->{$abbrev});
+ my @possibilities = grep { /^$abbrev/ } $self->game_list;
+ return $possibilities[0] if @possibilities == 1;
+ return;
+}
+
sub _format {
my $self = shift;
my ($to_print) = @_;