Some stubs for access levels.

master
Robert "ar" Gerus 2013-06-09 15:19:06 +02:00
parent c6563eea1b
commit a5b3b9addd
1 changed files with 21 additions and 7 deletions

View File

@ -5,10 +5,23 @@ class Repost
attr_accessor :commands attr_accessor :commands
def register_command(keyword, &code) def register_command(keyword, &code)
# Yes, that's a copy-paste of the register_trigger method and that begin
# violates DRY. I feel a bit bad about it, but not that much. access_level = Config[:commands][keyword.to_sym][:access_level].nil? ? 5 : Config[keyword.to_sym][:access_level]
self.commands = [] if self.triggers.nil? rescue NoMethodError
self.commands << {:keyword => keyword, :code => code} 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
end end
@ -55,9 +68,10 @@ Client.register_trigger("PRIVMSG") { |msg|
Client.commands.each do |cmd| Client.commands.each do |cmd|
# couldn't inline the if into second argument of Client.privmsg() call # couldn't inline the if into second argument of Client.privmsg() call
if command.downcase == cmd[:keyword] then if command.downcase == cmd[:keyword] then
# we actually expect for the command to return some message for next if cmd[:access_level] > Client.access_level(msg[:prefix], target)
# for the user retval = cmd[:code].call(arguments)
Client.privmsg(target, reply_prefix + 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
end if not ( Client.commands.nil? or command.nil? ) end if not ( Client.commands.nil? or command.nil? )
} }