X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Freaction.rb;h=f70aefa1dba83fec74867502f46571040d3ffdf2;hb=d9899b3d78d19ce9189f134ab9104374c007657f;hp=0ec75d5866847da663059f684817e8390a1b9976;hpb=9b4a429d7f672a97199d1d45efbdbdf51ddd25ad;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/reaction.rb b/data/rbot/plugins/reaction.rb index 0ec75d58..f70aefa1 100644 --- a/data/rbot/plugins/reaction.rb +++ b/data/rbot/plugins/reaction.rb @@ -66,9 +66,10 @@ class ::Reaction end @trigger = [act] if rex.sub!(%r@^([/!])(.*)\1$@, '\2') - @trigger << Regexp.new(rex) + @trigger << Regexp.new(rex, true) else - @trigger << Regexp.new(/\b#{Regexp.escape(rex)}\b/u) + rex.sub!(/^(["'])(.*)\1$/, '\2') + @trigger << Regexp.new(/\b#{Regexp.escape(rex)}\b/ui) end end @@ -213,11 +214,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) @@ -241,7 +245,7 @@ class ReactionPlugin < Plugin def find_reaction(trigger) @reactions.find { |react| - react.raw_trigger == trigger + react.raw_trigger.downcase == trigger.downcase } end