]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
fake message: set replied on reply
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 31 Dec 2010 09:20:55 +0000 (10:20 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 31 Dec 2010 09:20:55 +0000 (10:20 +0100)
Although the reply method for fake messages was actually relying on the
original, we still need to set 'replied' to prevent the fake message
from being wrongly delegated to 'unreplied'.

The most obvious bug this commit fixes is the potentially infinite loop
triggered by defining a command reaction triggered by the command name
itself (e.g. reply to ping with cmd:ping).

data/rbot/plugins/reaction.rb
lib/rbot/core/utils/extends.rb

index d3f4b558da83b195b47c4505b4e5ce2a7252b2ba..879b89fa4735b5286d18afb3f3b17b55d9f9b5d4 100644 (file)
@@ -238,7 +238,7 @@ class ReactionPlugin < Plugin
 
   def unreplied(m)
     return unless PrivMessage === m
-    debug "testing #{m} for reactions"
+    debug "testing #{m.inspect} for reactions"
     return if @reactions.empty?
     candidates = @reactions.map { |react|
       blob = react === m
index 84833d9f89acde3aa676624c2057b1917eb8cdbd..d734db6120b7ae9518ca2d8d94a690868e13da13 100644 (file)
@@ -510,12 +510,16 @@ module ::Irc
           new_m = o[:class].new(o[:bot], o[:server], o[:source], o[:target], string)
           new_m.recurse_depth = o[:depth]
           if from
-            # the created message will reply to the originating message
+            # the created message will reply to the originating message, but we
+            # must remember to set 'replied' on the fake message too, to
+            # prevent infinite loops that could be created for example with the reaction
+            # plugin by setting up a reaction to ping with cmd:ping
             class << new_m
               self
             end.send(:define_method, :reply) do |*args|
               debug "replying to '#{from.message}' with #{args.first}"
               from.reply(*args)
+              new_m.replied = true
             end
             # the created message will follow originating message's in_thread
             new_m.in_thread = from.in_thread if from.respond_to?(:in_thread)