def handle(m)
return false if @templates.empty?
failures = []
@templates.each do |tmpl|
next unless tmpl
botmodule = @parent.plugins[tmpl.botmodule]
options, failure = tmpl.recognize(m)
if options.nil?
failures << [tmpl, failure]
else
action = tmpl.options[:action]
unless botmodule.respond_to?(action)
failures << [tmpl, "#{botmodule} does not respond to action #{action}"]
next
end
auth = tmpl.options[:full_auth_path]
debug "checking auth for #{auth}"
if m.bot.auth.allow?(auth, m.source, '?')
debug "template match found and auth'd: #{action.inspect} #{options.inspect}"
return :return => botmodule.send(action, m, options)
end
debug "auth failed for #{auth}"
return false
end
end
failures.each {|f, r|
debug "#{f.inspect} => #{r}"
}
debug "no handler found"
return false
end