From 077978bfa1e32bb836b68ff59be1eac57fd8dfda Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 13 Jul 2014 07:06:04 +0000 Subject: [PATCH] Add -h option to `aka` command to show full hostmasks --- PBot/MessageHistory.pm | 40 ++++++++++++++++++++++++++++++++-------- PBot/VERSION.pm | 4 ++-- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/PBot/MessageHistory.pm b/PBot/MessageHistory.pm index 4ac63df5..dacd0653 100644 --- a/PBot/MessageHistory.pm +++ b/PBot/MessageHistory.pm @@ -65,29 +65,53 @@ sub add_message { sub list_also_known_as { my ($self, $from, $nick, $user, $host, $arguments) = @_; + my $usage = "Usage: aka [-h] "; + if(not length $arguments) { - return "Usage: aka "; + return $usage; } - my @akas = $self->{database}->get_also_known_as($arguments); + my $getopt_error; + local $SIG{__WARN__} = sub { + $getopt_error = shift; + chomp $getopt_error; + }; + + my $show_hostmasks; + my ($ret, $args) = GetOptionsFromString($arguments, + 'h' => \$show_hostmasks); + + return "$getopt_error -- $usage" if defined $getopt_error; + return "Too many arguments -- $usage" if @$args > 1; + return "Missing argument -- $usage" if @$args != 1; + + my @akas = $self->{database}->get_also_known_as(@$args[0]); if(@akas) { - my $result = "$arguments also known as: "; + my $result = "@$args[0] also known as: "; my %uniq; foreach my $aka (@akas) { - my ($nick) = $aka =~ /^([^!]+)!/; - $uniq{$nick} = $nick; + if (not $show_hostmasks) { + my ($nick) = $aka =~ /^([^!]+)!/; + $uniq{$nick} = $nick; + } else { + $uniq{$aka} = $aka; + } } my $sep = ""; foreach my $aka (sort keys %uniq) { - next if $aka =~ /^Guest\d+$/; + next if $aka =~ /^Guest\d+(!.*)?$/; $result .= "$sep$aka"; - $sep = ", "; + if ($show_hostmasks) { + $sep = ",\n"; + } else { + $sep = ", "; + } } return $result; } else { - return "I don't know anybody named $arguments."; + return "I don't know anybody named @$args[0]."; } } diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 488e183d..3666cc93 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,8 +13,8 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 732, - BUILD_DATE => "2014-07-12", + BUILD_REVISION => 733, + BUILD_DATE => "2014-07-13", }; 1;