From 2faeeb2de885d68a877e6adf6f1b0c4e69fb640d Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sat, 15 Mar 2014 08:07:05 +0000 Subject: [PATCH] Add -nick/-channel/-text options to quotegrabs rq command (also retaining original syntax) --- PBot/Quotegrabs.pm | 26 ++++++++++++++++++-------- PBot/VERSION.pm | 4 ++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/PBot/Quotegrabs.pm b/PBot/Quotegrabs.pm index 65f0db14..c4fb29e4 100644 --- a/PBot/Quotegrabs.pm +++ b/PBot/Quotegrabs.pm @@ -407,9 +407,7 @@ sub show_quotegrab { sub show_random_quotegrab { my ($self, $from, $nick, $user, $host, $arguments) = @_; my @quotes = (); - my $nick_search = ".*"; - my $channel_search = $from; - my $text_search = ".*"; + my ($nick_search, $channel_search, $text_search); if(not defined $from) { $self->{pbot}->logger->log("Command missing ~from parameter!\n"); @@ -417,14 +415,26 @@ sub show_random_quotegrab { } if(defined $arguments) { - ($nick_search, $channel_search, $text_search) = split /\s+/, $arguments; + $nick_search = $1 if $arguments =~ s/-nick\s+(\S+)//g; + $channel_search = $1 if $arguments =~ s/-channel\s+(\S+)//g; + $text_search = $1 if $arguments =~ s/-text\s+(\S+)//g; + + $arguments =~ s/^\s+//; + $arguments =~ s/\s+$//; + + my ($possible_nick_search, $possible_channel_search, $possible_text_search) = split /\s+/, $arguments; + + $nick_search = $possible_nick_search if not defined $nick_search; + $channel_search = $possible_channel_search if not defined $channel_search; + $text_search = $possible_text_search if not defined $text_search; + if(not defined $channel_search) { $channel_search = $from; } } $nick_search = '.*' if not defined $nick_search; - $channel_search = '.*' if not defined $channel_search; + $channel_search = '.*' if not defined $channel_search or $channel_search !~ /^#/; $text_search = '.*' if not defined $text_search; eval { @@ -457,7 +467,7 @@ sub show_random_quotegrab { $result .= "matching '$text_search' "; } - return $result . "yet (use `rq ` to specify the correct channel).. Use `grab` to grab a quote.";; + return $result . "yet (use `rq ` to specify the correct channel). Use `grab` to grab a quote.";; } my $quotegrab = $quotes[int rand($#quotes + 1)]; @@ -465,9 +475,9 @@ sub show_random_quotegrab { my ($first_nick) = split /\+/, $quotegrab->{nick}, 2; if($text =~ s/^\/me\s+//) { - return "$quotegrab->{id}: * $first_nick $text"; + return "$quotegrab->{id}: " . ($channel_search eq '.*' ? "[$quotegrab->{channel}] " : "") . "* $first_nick $text"; } else { - return "$quotegrab->{id}: <$first_nick> $text"; + return "$quotegrab->{id}: " . ($channel_search eq '.*' ? "[$quotegrab->{channel}] " : "") . "<$first_nick> $text"; } } diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index fcd3d57a..60092fdd 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 => 526, - BUILD_DATE => "2014-03-14", + BUILD_REVISION => 527, + BUILD_DATE => "2014-03-15", }; 1;