This class describes a permission set
Create a new (empty) PermissionSet
# File lib/rbot/botuser.rb, line 149 def initialize @perm = {} end
Inspection simply inspects the internal hash
# File lib/rbot/botuser.rb, line 154 def inspect @perm.inspect end
Tells if command cmd is permitted. We do this by returning the value of the deepest Irc::Bot::Auth::Command#path that matches.
# File lib/rbot/botuser.rb, line 181 def permit?(str) cmd = str.to_irc_auth_command # TODO user-configurable list of always-allowed commands, # for admins that want to set permissions -* for everybody return true if cmd.command == :login allow = nil cmd.path.reverse.each { |k| if @perm.has_key?(k) allow = @perm[k] break end } return allow end
Resets the permission for command cmd
# File lib/rbot/botuser.rb, line 174 def reset_permission(cmd) set_permission(cmd, nil) end
Sets the permission for command cmd to val,
# File lib/rbot/botuser.rb, line 160 def set_permission(str, val) cmd = str.to_irc_auth_command case val when true, false @perm[cmd.command] = val when nil @perm.delete(cmd.command) else raise TypeError, "#{val.inspect} must be true or false" unless [true,false].include?(val) end end