+ def find_auth(pseudo)
+ k = pseudo.plugin.intern
+ cmds = @bot.plugins.commands
+ auth = nil
+ if cmds.has_key?(k)
+ cmds[k][:botmodule].handler.each do |tmpl|
+ options = tmpl.recognize(pseudo)
+ next if options.kind_of? MessageMapper::Failure
+ auth = tmpl.options[:full_auth_path]
+ break
+ end
+ end
+ return auth
+ end
+
+ def auth_allow_deny(m, p)
+ begin
+ botuser = @bot.auth.get_botuser(p[:user].sub(/^all$/,"everyone"))
+ rescue
+ return m.reply(_("couldn't find botuser %{name}") % {:name => p[:user]})
+ end
+
+ if p[:where].to_s.empty?
+ where = :*
+ else
+ where = m.parse_channel_list(p[:where].to_s).first # should only be one anyway
+ end
+
+ if p.has_key? :auth_path
+ auth_path = p[:auth_path]
+ else
+ # pseudo-message to find the template. The source is ignored, and the
+ # target is set according to where the template should be checked
+ # (public or private)
+ # This might still fail in the case of 'everywhere' for commands there are
+ # really only private
+ case where
+ when :"?"
+ pseudo_target = @bot.myself
+ when :*
+ pseudo_target = m.channel
+ else
+ pseudo_target = m.server.channel(where)
+ end
+
+ pseudo = PrivMessage.new(bot, m.server, m.source, pseudo_target, p[:stuff].to_s)
+
+ auth_path = find_auth(pseudo)
+ end
+ debug auth_path
+
+ if auth_path
+ allow = p[:allow]
+ if @bot.auth.permit?(botuser, auth_path, where)
+ return m.reply(_("%{user} can already do that") % {:user => botuser}) if allow
+ else
+ return m.reply(_("%{user} can't do that already") % {:user => botuser}) if !allow
+ end
+ cmd = PrivMessage.new(bot, m.server, m.source, m.target, "permissions set %{sign}%{path} %{where} for %{user}" % {
+ :path => auth_path,
+ :user => p[:user],
+ :sign => (allow ? '+' : '-'),
+ :where => p[:where].to_s
+ })
+ handle(cmd)
+ else
+ m.reply(_("sorry, %{cmd} doesn't look like a valid command. maybe you misspelled it, or you need to specify it should be in private?") % {
+ :cmd => p[:stuff].to_s
+ })
+ end
+ end
+
+ def auth_allow(m, p)
+ auth_allow_deny(m, p.merge(:allow => true))
+ end
+
+ def auth_deny(m, p)
+ auth_allow_deny(m, p.merge(:allow => false))
+ end
+