aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@yeah.nah.nz>2018-10-15 13:05:20 +1300
committerDavid Phillips <david@yeah.nah.nz>2018-10-15 13:05:20 +1300
commit7ebdcce5c312cd262e13f040e9dae55b708a915d (patch)
tree5b4adba266fd4c8e2b727b82f959c13618aa9b75
parenta52d8fb14d6f120dbc49fb2526c70d12b2f57407 (diff)
downloadidalius-7ebdcce5c312cd262e13f040e9dae55b708a915d.tar.xz
Titilate: Allow semi-overlap of triggers
-rw-r--r--Plugin/Titillate.pm20
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;
}