From: Spencer Rinehart Date: Mon, 9 Mar 2009 16:07:38 +0000 (-0400) Subject: reaction: fix trigger regex to work with non-alphanumeric start/end. X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=07edf3c56db6d05346a3e2dbfff12698e543c090;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git reaction: fix trigger regex to work with non-alphanumeric start/end. only match on word boundaries at an end of a trigger if the character at that end of the trigger is a word character. In other words, the trigger "test" should require word boundaries on each side, but the trigger "@test" should only require one on the right side. --- diff --git a/data/rbot/plugins/reaction.rb b/data/rbot/plugins/reaction.rb index 55fabcdb..8f2a1637 100644 --- a/data/rbot/plugins/reaction.rb +++ b/data/rbot/plugins/reaction.rb @@ -69,7 +69,9 @@ class ::Reaction @trigger << Regexp.new(rex, true) else rex.sub!(/^(["'])(.*)\1$/, '\2') - @trigger << Regexp.new(/\b#{Regexp.escape(rex)}(?:\b|$)/ui) + prepend = ( rex =~ /^\w/ ? '(?:\b)' : '') + append = ( rex =~ /\w$/ ? '(?:\b|$)' : '') + @trigger << Regexp.new(/#{prepend}#{Regexp.escape(rex)}#{append}/ui) end end