diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-09-21 14:24:17 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2007-09-21 14:24:17 +0000 |
commit | b19343b91d2e02ee6e26898f2e80b5780a420cb4 (patch) | |
tree | d8721e4397eb52c252af9002cd28ee0e197dd7f7 /data/rbot | |
parent | e8d40e56a452afcfa11568db3822d03ea1cf53b9 (diff) |
reaction plugin: use the longest-matching trigger, not the first one found
Diffstat (limited to 'data/rbot')
-rw-r--r-- | data/rbot/plugins/reaction.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/data/rbot/plugins/reaction.rb b/data/rbot/plugins/reaction.rb index ad8f2431..ee8abbd5 100644 --- a/data/rbot/plugins/reaction.rb +++ b/data/rbot/plugins/reaction.rb @@ -213,11 +213,14 @@ class ReactionPlugin < Plugin return unless PrivMessage === m debug "testing #{m} for reactions" return if @reactions.empty? - wanted = @reactions.find { |react| - react === m - } - return unless wanted - match = wanted === m + candidates = @reactions.map { |react| + blob = react === m + blob ? [blob, react] : nil + }.compact + return if candidates.empty? + match, wanted = candidates.sort { |m1, m2| + m1.first[0].length <=> m2.first[0].length + }.last matched = match[0] stuff = match.post_match.strip target, what = stuff.split(/\s+/, 2) |