]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
reaction plugin: use the longest-matching trigger, not the first one found
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 21 Sep 2007 14:24:17 +0000 (14:24 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 21 Sep 2007 14:24:17 +0000 (14:24 +0000)
data/rbot/plugins/reaction.rb

index ad8f2431a571994a4dd8b004280a11daf10cec14..ee8abbd54b67237778ac292f18ecc8031dfa815b 100644 (file)
@@ -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)