From: Giuseppe Bilotta Date: Fri, 21 Sep 2007 14:24:17 +0000 (+0000) Subject: reaction plugin: use the longest-matching trigger, not the first one found X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=b19343b91d2e02ee6e26898f2e80b5780a420cb4;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git reaction plugin: use the longest-matching trigger, not the first one found --- 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)