From b19343b91d2e02ee6e26898f2e80b5780a420cb4 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Fri, 21 Sep 2007 14:24:17 +0000 Subject: [PATCH] reaction plugin: use the longest-matching trigger, not the first one found --- data/rbot/plugins/reaction.rb | 13 ++++++++----- 1 file 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) -- 2.39.5