X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fmessagemapper.rb;h=3966bc17f7360ec3853cda6995c479d3ab9e7590;hb=8218e3f05e8ccd95497dd3c7aa115cfde8b01a40;hp=d85f0b14aa69e448bfdddff2e2193e594a71cea4;hpb=1fbb090ea91ab20916b3698d8afd6e300673b826;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/messagemapper.rb b/lib/rbot/messagemapper.rb index d85f0b14..3966bc17 100644 --- a/lib/rbot/messagemapper.rb +++ b/lib/rbot/messagemapper.rb @@ -199,12 +199,12 @@ class Bot # # Further examples: # - # # match 'karmastats' and call my stats() method - # plugin.map 'karmastats', :action => 'stats' - # # match 'karma' with an optional 'key' and call my karma() method - # plugin.map 'karma :key', :defaults => {:key => false} - # # match 'karma for something' and call my karma() method - # plugin.map 'karma for :key' + # # match 'pointstats' and call my stats() method + # plugin.map 'pointstats', :action => 'stats' + # # match 'points' with an optional 'key' and call my points() method + # plugin.map 'points :key', :defaults => {:key => false} + # # match 'points for something' and call my points() method + # plugin.map 'points for :key' # # # two matches, one for public messages in a channel, one for # # private messages which therefore require a channel argument @@ -245,9 +245,9 @@ class Bot return false if @templates.empty? failures = [] @templates.each do |tmpl| - options = tmpl.recognize(m) - if options.kind_of? Failure - failures << options + params = tmpl.recognize(m) + if params.kind_of? Failure + failures << params else action = tmpl.options[:action] unless @parent.respond_to?(action) @@ -257,8 +257,12 @@ class Bot auth = tmpl.options[:full_auth_path] 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 !m.in_thread && (tmpl.options[:thread] || tmpl.options[:threaded]) + debug "template match found and auth'd: #{action.inspect} #{params.inspect}" + if !m.in_thread and (tmpl.options[:thread] or tmpl.options[:threaded]) and + (defined? WebServiceUser and not m.source.instance_of? WebServiceUser) + # Web service: requests are handled threaded anyway and we want to + # wait for the responses. + # since the message action is in a separate thread, the message may be # delegated to unreplied() before the thread has a chance to actually # mark it as replied. since threading is used mostly for commands that @@ -267,14 +271,14 @@ class Bot m.replied = true Thread.new do begin - @parent.send(action, m, options) + @parent.send(action, m, params) rescue Exception => e error "In threaded action: #{e.message}" debug e.backtrace.join("\n") end end else - @parent.send(action, m, options) + @parent.send(action, m, params) end return true