summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-22 07:12:41 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-22 07:12:41 +0000
commited18ba7370544244141199767365022651710021 (patch)
treeb1005ca871a432374dab1615f0c0a2dbf52fde36
parent9084fa0b0c62988319548157b3a10608c35b2120 (diff)
reaction plugin: order reaction candidates by number of captures as secondary order
-rw-r--r--data/rbot/plugins/reaction.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/data/rbot/plugins/reaction.rb b/data/rbot/plugins/reaction.rb
index 4f757ddd..8892cf7a 100644
--- a/data/rbot/plugins/reaction.rb
+++ b/data/rbot/plugins/reaction.rb
@@ -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