]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
reaction: fix trigger regex to work with non-alphanumeric start/end.
authorSpencer Rinehart <anubis@overthemonkey.com>
Mon, 9 Mar 2009 16:07:38 +0000 (12:07 -0400)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Mon, 9 Mar 2009 19:31:38 +0000 (20:31 +0100)
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.

data/rbot/plugins/reaction.rb

index 55fabcdbe4eea4a537e7bd95606aaa2e600f8373..8f2a1637d4a180ab7a585e494eca834e9f5739f2 100644 (file)
@@ -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