]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
reaction plugin: order reaction candidates by number of captures as secondary order
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sat, 22 Sep 2007 07:12:41 +0000 (07:12 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sat, 22 Sep 2007 07:12:41 +0000 (07:12 +0000)
data/rbot/plugins/reaction.rb

index 4f757ddd5adf0be122a90c6385d1a66b74e85250..8892cf7a13d5fc29504b985d8b23aa5f319893db 100644 (file)
@@ -220,7 +220,10 @@ class ReactionPlugin < Plugin
     }.compact
     return if candidates.empty?
     match, wanted = candidates.sort { |m1, m2|
-      m1.first[0].length <=> m2.first[0].length
+      # Order by longest matching text first,
+      # and by number of captures second
+      longer = m1.first[0].length <=> m2.first[0].length
+      longer == 0 ? m1.first.length <=> m2.first.length : longer
     }.last
     matched = match[0]
     before = match.pre_match.strip