From 7ebdcce5c312cd262e13f040e9dae55b708a915d Mon Sep 17 00:00:00 2001 From: David Phillips Date: Mon, 15 Oct 2018 13:05:20 +1300 Subject: Titilate: Allow semi-overlap of triggers --- Plugin/Titillate.pm | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Plugin/Titillate.pm b/Plugin/Titillate.pm index a113fc0..9afb1c6 100644 --- a/Plugin/Titillate.pm +++ b/Plugin/Titillate.pm @@ -22,19 +22,17 @@ sub on_message { my ($self, $logger, $me, $who, $where, $raw_what, $what, $irc) = @_; my $gathered = ""; my @expressions = (keys %{$config->{triggers}}); - my $expression = join '|', @expressions; - while ($what =~ /($expression)/gi) { - my $matched = $1; - my $key; - # figure out which key matched - foreach (@expressions) { - if ($matched =~ /$_/i) { - $key = $_; - last; - } + my %responses; + + # FIXME still doesn't support overlap like 'foo' with 'fooo' + foreach (@expressions) { + my $e = $_; + while ($what =~ /($e)/gi) { + $responses{$-[0]} = $config->{triggers}->{$e}; } - $gathered .= $config->{triggers}->{$key}; } + $gathered .= $responses{$_} foreach (sort { $a <=> $b } (keys %responses)); + return $gathered; } -- cgit v1.1