def handle(m)
return false if @templates.empty?
failures = []
@templates.each do |tmpl|
options, failure = tmpl.recognize(m)
if options.nil?
failures << [tmpl, failure]
else
action = tmpl.options[:action] ? tmpl.options[:action] : tmpl.items[0]
next unless @parent.respond_to?(action)
auth = tmpl.options[:auth] ? tmpl.options[:auth] : tmpl.items[0]
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}"
@parent.send(action, m, options)
return true
end
debug "auth failed for #{auth}"
return false
end
end
debug failures.inspect
debug "no handler found, trying fallback"
if @fallback != nil && @parent.respond_to?(@fallback)
if m.bot.auth.allow?(@fallback, m.source, m.replyto)
@parent.send(@fallback, m, {})
return true
end
end
return false
end