From a5b3b9addd33c39628a443458c28abbc85bf74eb Mon Sep 17 00:00:00 2001 From: "Robert \"ar\" Gerus" Date: Sun, 9 Jun 2013 15:19:06 +0200 Subject: [PATCH] Some stubs for access levels. --- plugins/commands.rb | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/plugins/commands.rb b/plugins/commands.rb index 9c111dd..12350fb 100644 --- a/plugins/commands.rb +++ b/plugins/commands.rb @@ -5,10 +5,23 @@ class Repost attr_accessor :commands def register_command(keyword, &code) - # Yes, that's a copy-paste of the register_trigger method and that - # violates DRY. I feel a bit bad about it, but not that much. - self.commands = [] if self.triggers.nil? - self.commands << {:keyword => keyword, :code => code} + begin + access_level = Config[:commands][keyword.to_sym][:access_level].nil? ? 5 : Config[keyword.to_sym][:access_level] + rescue NoMethodError + access_level = 5 + end + + self.commands = [] if self.commands.nil? + self.commands << { + :keyword => keyword, + :access_level => access_level, + :code => code + } + end + + # just a stub for now + def access_level(user, target) + 99 end end @@ -55,9 +68,10 @@ Client.register_trigger("PRIVMSG") { |msg| Client.commands.each do |cmd| # couldn't inline the if into second argument of Client.privmsg() call if command.downcase == cmd[:keyword] then - # we actually expect for the command to return some message for - # for the user - Client.privmsg(target, reply_prefix + cmd[:code].call(arguments)) + next if cmd[:access_level] > Client.access_level(msg[:prefix], target) + retval = cmd[:code].call(arguments) + # if the command returned a String, we want to show it + Client.privmsg(target, reply_prefix + retval) if retval.instance_of? String end end if not ( Client.commands.nil? or command.nil? ) }