]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
add attribute BasicUserMessage#thread
authorYaohan Chen <yaohan.chen@gmail.com>
Tue, 27 May 2008 02:29:41 +0000 (22:29 -0400)
committerYaohan Chen <yaohan.chen@gmail.com>
Wed, 28 May 2008 01:16:26 +0000 (21:16 -0400)
this specifies whether the message handler is to be threaded, and overrides the map
option if non-nil.

lib/rbot/message.rb
lib/rbot/messagemapper.rb

index 99f4bb7f1b09ec3e10c84064c5788ed809fe1b45..ba0d8cc9762f0e851ae67abe9086b364c2c3d832 100644 (file)
@@ -132,6 +132,12 @@ module Irc
     attr_accessor :ignored
     alias :ignored? :ignored
 
+    # should the message handler be excuted in new thread?
+    # if set to true or false, this overrides :thread option in map. if it's nil,
+    # the map option takes effect
+    attr_accessor :thread
+    alias :thread? :thread
+
     # instantiate a new Message
     # bot::      associated bot class
     # server::   Server where the message took place
@@ -150,6 +156,7 @@ module Irc
       @replied = false
       @server = server
       @ignored = false
+      @thread = nil
 
       @identified = false
       if @msg_wants_id && @server.capabilities[:"identify-msg"]
index b08a503feba4b858790f4f5908d7f9ce0ffde4ff..2b9fc5e32c2a99238a79c53b469d927b9e9804b2 100644 (file)
@@ -207,7 +207,7 @@ class Bot
           debug "checking auth for #{auth}"
           if m.bot.auth.allow?(auth, m.source, m.replyto)
             debug "template match found and auth'd: #{action.inspect} #{options.inspect}"
-            if tmpl.options[:thread] || tmpl.options[:threaded]
+            if m.thread || (m.thread == nil && tmpl.options[:thread] || tmpl.options[:threaded])
               Thread.new do
                 begin
                   @parent.send(action, m, options)