From f640ade74eb3e01f683b2c8486d2833564604e73 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 28 Oct 2014 20:33:11 +0000 Subject: [PATCH] Fix regex factoids so that regular factoid keywords have priority over regex triggers --- PBot/Factoids.pm | 32 ++++++++++++++++++++++---------- PBot/VERSION.pm | 4 ++-- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index bea95d71..23063853 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -249,22 +249,34 @@ sub find_factoid { $self->{pbot}->{logger}->log("string: $string\n") if $debug; my @result = eval { + # check factoids foreach my $channel (sort keys %{ $self->{factoids}->hash }) { if($exact_channel) { next unless $from eq lc $channel or $channel eq '.*'; } foreach my $trigger (keys %{ $self->{factoids}->hash->{$channel} }) { - if(not $exact_trigger and $self->{factoids}->hash->{$channel}->{$trigger}->{type} eq 'regex') { - $self->{pbot}->{logger}->log("checking regex $string =~ m/$trigger/i\n") if $debug; - if($string =~ m/$trigger/i) { - $self->{pbot}->{logger}->log("return regex $channel: $trigger\n") if $debug; - return ($channel, $trigger); - } - } else { - if($keyword =~ m/^\Q$trigger\E$/i) { - $self->{pbot}->{logger}->log("return $channel: $trigger\n") if $debug; - return ($channel, $trigger); + if($keyword =~ m/^\Q$trigger\E$/i) { + $self->{pbot}->{logger}->log("return $channel: $trigger\n") if $debug; + return ($channel, $trigger); + } + } + } + + # then check regex factoids + if(not $exact_trigger) { + foreach my $channel (sort keys %{ $self->{factoids}->hash }) { + if($exact_channel) { + next unless $from eq lc $channel or $channel eq '.*'; + } + + foreach my $trigger (keys %{ $self->{factoids}->hash->{$channel} }) { + if($self->{factoids}->hash->{$channel}->{$trigger}->{type} eq 'regex') { + $self->{pbot}->{logger}->log("checking regex $string =~ m/$trigger/i\n") if $debug; + if($string =~ m/$trigger/i) { + $self->{pbot}->{logger}->log("return regex $channel: $trigger\n") if $debug; + return ($channel, $trigger); + } } } } diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 6b236af7..9a1adbe5 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 => 794, - BUILD_DATE => "2014-10-13", + BUILD_REVISION => 795, + BUILD_DATE => "2014-10-28", }; 1;