diff options
author | David Phillips <david@yeah.nah.nz> | 2018-10-15 13:05:20 +1300 |
---|---|---|
committer | David Phillips <david@yeah.nah.nz> | 2018-10-15 13:05:20 +1300 |
commit | 7ebdcce5c312cd262e13f040e9dae55b708a915d (patch) | |
tree | 5b4adba266fd4c8e2b727b82f959c13618aa9b75 | |
parent | a52d8fb14d6f120dbc49fb2526c70d12b2f57407 (diff) | |
download | idalius-7ebdcce5c312cd262e13f040e9dae55b708a915d.tar.xz |
Titilate: Allow semi-overlap of triggers
-rw-r--r-- | Plugin/Titillate.pm | 20 |
1 files 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; } |