From: Giuseppe Bilotta Date: Sat, 22 Sep 2007 07:12:41 +0000 (+0000) Subject: reaction plugin: order reaction candidates by number of captures as secondary order X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=ed18ba7370544244141199767365022651710021;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git reaction plugin: order reaction candidates by number of captures as secondary order --- 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