diff --git a/PBot/Changes b/PBot/Changes index 9308ead8..c29f8406 100644 --- a/PBot/Changes +++ b/PBot/Changes @@ -9,9 +9,9 @@ # # TODO: Ignorelist needs to save and load from file, use regex hash keys/search parameters. # -# 0.6.2-beta (03/25/10): 'list messages' command significant improved -- can use regexs search parameters. +# 0.6.3-beta (03/26/10): Improved !find command by adding optional -owner and -by search parameters. +# 0.6.2-beta (03/25/10): 'list messages' command significantly improved -- can use regexs search parameters. # Added optional regex search to 'rq' quotegrab command to match against quotegrab text. -# Channel chat messages easier to read in log (from anti-flood module). # 0.6.1-beta (03/23/10): Quotegrab ids properly adjusted when deleting quotegrab. # Admins loads from file, uses regex hash keys. # Lots of misc tweaks and improvements throughout. diff --git a/PBot/FactoidCommands.pm b/PBot/FactoidCommands.pm index 5731f662..ee4d40a5 100644 --- a/PBot/FactoidCommands.pm +++ b/PBot/FactoidCommands.pm @@ -265,7 +265,7 @@ sub histogram { $i++; last if $i >= 10; } - return "$factoid_count factoid_count, top 10 submitters: $text"; + return "$factoid_count factoids, top 10 submitters: $text"; } sub show { @@ -422,35 +422,77 @@ sub find { my $self = shift; my ($from, $nick, $user, $host, $arguments) = @_; my $factoids = $self->{pbot}->factoids->factoids; - my $i = 0; my $text; my $type; - foreach my $command (sort keys %{ $factoids }) { - if(exists $factoids->{$command}{text} || exists $factoids->{$command}{regex}) { - $type = 'text' if(exists $factoids->{$command}{text}); - $type = 'regex' if(exists $factoids->{$command}{regex}); - # $self->{pbot}->logger->log("Checking [$command], type: [$type]\n"); - eval { - my $regex = qr/$arguments/; - if($factoids->{$command}{$type} =~ /$regex/i || $command =~ /$regex/i) - { - $i++; - $text .= "$command "; - } - }; - return "/msg $nick $arguments: $@" if $@; + if(not defined $arguments) { + return "/msg $nick Usage: !find [-owner nick] [-by nick] [text]"; + } + + my ($owner, $by); + + $owner = $1 if $arguments =~ s/-owner\s+([^\b\s]+)//i; + $by = $1 if $arguments =~ s/-by\s+([^\b\s]+)//i; + + $owner = '.*' if not defined $owner; + $by = '.*' if not defined $by; + + $arguments =~ s/^\s+//; + $arguments =~ s/\s+$//; + $arguments =~ s/\s+/ /g; + + my $argtype = undef; + + if($owner ne '.*') { + $argtype = "owned by $owner"; + } + + if($by ne '.*') { + if(not defined $argtype) { + $argtype = "last referenced by $by"; + } else { + $argtype .= " and last referenced by $by"; } } - + + if($arguments ne "") { + if(not defined $argtype) { + $argtype = "with text matching '$arguments'"; + } else { + $argtype .= " and with text matching '$arguments'"; + } + } + + if(not defined $argtype) { + return "/msg $nick Usage: !find [-owner nick] [-by nick] [text]"; + } + + my $i = 0; + eval { + foreach my $command (sort keys %{ $factoids }) { + if(exists $factoids->{$command}{text} || exists $factoids->{$command}{regex}) { + $type = 'text' if(exists $factoids->{$command}{text}); + $type = 'regex' if(exists $factoids->{$command}{regex}); + + if($factoids->{$command}{owner} =~ /$owner/i && $factoids->{$command}{ref_user} =~ /$by/i) { + next if($arguments ne "" && $factoids->{$command}{$type} !~ /$arguments/i && $command !~ /$arguments/i); + $i++; + $text .= "$command "; + } + } + } + }; + + return "/msg $nick $arguments: $@" if $@; + if($i == 1) { chop $text; $type = 'text' if exists $factoids->{$text}{text}; $type = 'regex' if exists $factoids->{$text}{regex}; - return "found one match: '$text' is '$factoids->{$text}{$type}'"; + return "found one factoid " . $argtype . ": '$text' is '$factoids->{$text}{$type}'"; } else { - return "$i factoids contain '$arguments': $text" unless $i == 0; - return "No factoids contain '$arguments'"; + return "$i factoids " . $argtype . ": $text" unless $i == 0; + return "No factoids " . $argtype; } } diff --git a/PBot/PBot.pm b/PBot/PBot.pm index a0a80773..c0cdb27e 100644 --- a/PBot/PBot.pm +++ b/PBot/PBot.pm @@ -9,7 +9,7 @@ use strict; use warnings; use vars qw($VERSION); -$VERSION = "0.6.2-beta"; +$VERSION = "0.6.3-beta"; # unbuffer stdout STDOUT->autoflush(1);