diff options
author | Yaohan Chen <yaohan.chen@gmail.com> | 2008-06-23 23:29:51 -0400 |
---|---|---|
committer | Yaohan Chen <yaohan.chen@gmail.com> | 2008-06-24 11:31:22 -0400 |
commit | 9ad6b29acc7c96c394f470f261cea7331004110b (patch) | |
tree | a9d6f2b078b99db833c3af8e1ccf5b5df9fd55f7 /lib/rbot | |
parent | 5c832c68f93277a8a0bcfa8f30493924b938a360 (diff) |
fake_message duplicates m.reply and m.in_thread from the :from message
this makes it possible to create a fake message, override its reply method in order
to get its "return value", even if the fake message will be handled by creating
another fake message.
Diffstat (limited to 'lib/rbot')
-rw-r--r-- | lib/rbot/core/utils/extends.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb index 59f5be76..bc0eeb46 100644 --- a/lib/rbot/core/utils/extends.rb +++ b/lib/rbot/core/utils/extends.rb @@ -400,6 +400,10 @@ module ::Irc # the :target, the message :class and whether or not to :delegate. To # initialize these entries from an existing message, you can use :from # + # Additionally, if :from is given, the reply method of created message + # is overriden to reply to :from instead. The #in_thread attribute + # for created mesage is also copied from :from + # # If you don't specify a :from you should specify a :source. # def fake_message(string, opts={}) @@ -418,13 +422,16 @@ 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 + # the created message will reply to the originating message class << new_m self end.send(:define_method, :reply) do |*args| + debug "replying to '#{from.message}' with #{args.first}" from.reply *args end + # the created message will follow originating message's in_thread + new_m.in_thread = from.in_thread if from.respond_to?(:in_thread) end return new_m unless o[:delegate] method = o[:class].to_s.gsub(/^Irc::|Message$/,'').downcase |