From 845dff008ed70f6b2ee31ef0dbf4e9dc2c3042eb Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 30 Jan 2011 06:29:05 +0000 Subject: [PATCH] factoids: levenshtein search working again; rate-limit working again --- PBot/Factoids.pm | 19 +++++++++++++------ PBot/VERSION.pm | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index 5ff34d74..cc6f31e6 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -203,11 +203,18 @@ sub interpreter { return undef if not length $keyword; $from = lc $from; - $ref_from = "" if not defined $ref_from; - # search for factoid against global channel and current channel (from) + # search for factoid against global channel and current channel (from unless ref_from is defined) my $original_keyword = $keyword; - ($channel, $keyword) = $self->find_factoid($from, $keyword, $arguments); + ($channel, $keyword) = $self->find_factoid($ref_from ? $ref_from : $from, $keyword, $arguments); + + if(not defined $ref_from) { + $ref_from = ""; + } else { + $ref_from = "[$ref_from] "; + } + + $arguments = "" if not defined $arguments; # if no match found, attempt to call factoid from another channel if it exists there if(not defined $keyword) { @@ -238,13 +245,13 @@ sub interpreter { elsif($found == 1) { $pbot->logger->log("Found '$original_keyword' as '$fwd_trig' in [$fwd_chan]\n"); - return $ref_from . $pbot->factoids->interpreter($fwd_chan, $nick, $user, $host, $count, $fwd_trig, $arguments, undef, "[$fwd_chan] "); + return $ref_from . $pbot->factoids->interpreter($from, $nick, $user, $host, $count, $fwd_trig, $arguments, undef, $fwd_chan); } # otherwise keyword hasn't been found, display similiar matches for all channels else { # if a non-nick argument was supplied, e.g., a sentence using the bot's nick, don't say anything - return "" if $arguments !~ /^[^.+-, ]{1,20}$/; - + return "" if length $arguments and $arguments !~ /^[^.+-, ]{1,20}$/; + # find matches from all channels my $matches = $self->factoids->levenshtein_matches('.*', lc $original_keyword); diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 86ede430..64cba503 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,7 +13,7 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 285, + BUILD_REVISION => 286, BUILD_DATE => "2011-01-29", };