]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/reaction.rb
rss: allow easier customization of output formats
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / reaction.rb
index 55fabcdbe4eea4a537e7bd95606aaa2e600f8373..6bbd08e39f10b8a89ebc4034389b1f5053b56e96 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
 
@@ -261,18 +263,21 @@ class ReactionPlugin < Plugin
     reply = wanted.pick_reply
     debug "picked #{reply}"
     return unless reply
-    args = reply.apply(subs)
-    if args[0] == :cmd
+    act, arg = reply.apply(subs)
+    case act
+    when :cmd
       begin
         # Pass the new message back to the bot.
         # FIXME Maybe we should do it the alias way, only calling
         # @bot.plugins.privmsg() ?
-        fake_message(@bot.nick+": "+args[1], :from => m)
+        fake_message(@bot.nick+": "+arg, :from => m)
       rescue RecurseTooDeep => e
         error e
       end
+    when :reply
+      m.plainreply arg
     else
-      m.__send__(*args)
+      m.__send__(act, arg)
     end
   end