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
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? )
}