]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
fake messages will use the originating message's reply method
authorYaohan Chen <yaohan.chen@gmail.com>
Mon, 23 Jun 2008 23:30:29 +0000 (19:30 -0400)
committerYaohan Chen <yaohan.chen@gmail.com>
Tue, 24 Jun 2008 15:31:22 +0000 (11:31 -0400)
this allows shell plugin to capture replies of a command even if this command is
run because of a fake message

lib/rbot/core/utils/extends.rb

index de6a7db4f1cbfe7743be516db68629c2b1619d82..59f5be76a874653e477a1c1d22d4f3a12b883fd1 100644 (file)
@@ -418,6 +418,14 @@ module ::Irc
           raise RecurseTooDeep if o[:depth] > MAX_RECURSE_DEPTH
           new_m = o[:class].new(o[:bot], o[:server], o[:source], o[:target], string)
           new_m.recurse_depth = o[:depth]
+          # if "from" message is given, the created message will reply to "from"
+          if from
+            class << new_m
+              self
+            end.send(:define_method, :reply) do |*args|
+              from.reply *args
+            end
+          end
           return new_m unless o[:delegate]
           method = o[:class].to_s.gsub(/^Irc::|Message$/,'').downcase
           method = 'privmsg' if method == 'priv'