@perm = {}\r
end\r
\r
+ # Inspection simply inspects the internal hash\r
+ def inspect\r
+ @perm.inspect\r
+ end\r
+\r
# Sets the permission for command _cmd_ to _val_,\r
- # creating intermediate permissions if needed.\r
#\r
def set_permission(cmd, val)\r
- raise TypeError, "#{val.inspect} must be true or false" unless [true,false].include?(val)\r
Irc::error_if_not_command(cmd)\r
- @perm[cmd.command] = val\r
+ case val\r
+ when true, false\r
+ @perm[cmd.command] = val\r
+ when nil\r
+ @perm.delete(cmd.command)\r
+ else\r
+ raise TypeError, "#{val.inspect} must be true or false" unless [true,false].include?(val)\r
+ end\r
+ end\r
+\r
+ # Resets the permission for command _cmd_\r
+ #\r
+ def reset_permission(cmd)\r
+ set_permission(cmd, nil)\r
end\r
\r
# Tells if command _cmd_ is permitted. We do this by returning\r
end\r
end\r
\r
+ # Resets the permission for command _cmd_ on channel _chan_\r
+ #\r
+ def reset_permission(cmd, chan ="*")\r
+ set_permission(cmd, nil, chan)\r
+ end\r
+\r
# Checks if BotUser is allowed to do something on channel _chan_,\r
# or on all channels if _chan_ is nil\r
#\r
end\r
\r
\r
- # This is the anonymous BotUser: it's used for all users which haven't\r
+ # This is the default BotUser: it's used for all users which haven't\r
# identified with the bot\r
#\r
- class AnonBotUserClass < BotUser\r
+ class DefaultBotUserClass < BotUser\r
include Singleton\r
def initialize\r
- super("anonymous")\r
+ super("everyone")\r
+ @default_perm = PermissionSet.new\r
end\r
private :login, :add_netmask, :delete_netmask\r
\r
- # Anon knows everybody\r
+ # Sets the default permission for the default user (i.e. the ones\r
+ # set by the BotModule writers) on all channels\r
+ #\r
+ def set_default_permission(cmd, val)\r
+ @default_perm.set_permission(Command.new(cmd), val)\r
+ debug "Default permissions now:\n#{@default_perm.inspect}"\r
+ end\r
+\r
+ # default knows everybody\r
+ #\r
def knows?(user)\r
Irc::error_if_not_user(user)\r
return true\r
super\r
add_netmask("*!*@*")\r
end\r
+\r
+ # DefaultBotUser will check the default_perm after checking\r
+ # the global ones\r
+ # or on all channels if _chan_ is nil\r
+ #\r
+ def permit?(cmd, chan=nil)\r
+ allow = super(cmd, chan)\r
+ if allow.nil? && chan.nil?\r
+ allow = @default_perm.permit?(cmd)\r
+ end\r
+ return allow\r
+ end\r
end\r
\r
- # Returns the only instance of AnonBotUserClass\r
+ # Returns the only instance of DefaultBotUserClass\r
#\r
- def Auth.anonbotuser\r
- return AnonBotUserClass.instance\r
+ def Auth.defaultbotuser\r
+ return DefaultBotUserClass.instance\r
end\r
\r
# This is the BotOwner: he can do everything\r
class AuthManagerClass\r
include Singleton\r
\r
+ attr_reader :everyone\r
+ attr_reader :botowner\r
+\r
# The instance manages two <code>Hash</code>es: one that maps\r
# <code>Irc::User</code>s onto <code>BotUser</code>s, and the other that maps\r
# usernames onto <code>BotUser</code>\r
def initialize\r
+ @everyone = Auth::defaultbotuser\r
+ @botowner = Auth::botowner\r
bot_associate(nil)\r
end\r
\r
def reset_hashes\r
@botusers = Hash.new\r
@allbotusers = Hash.new\r
- [Auth::anonbotuser, Auth::botowner].each { |x| @allbotusers[x.username.to_sym] = x }\r
+ [everyone, botowner].each { |x|\r
+ @allbotusers[x.username.to_sym] = x\r
+ }\r
end\r
\r
# load botlist from userfile\r
# Maps <code>Irc::User</code> to BotUser\r
def irc_to_botuser(ircuser)\r
Irc::error_if_not_user(ircuser)\r
- return @botusers[ircuser] || Auth::anonbotuser\r
+ # TODO check netmasks\r
+ return @botusers[ircuser] || everyone\r
end\r
\r
# creates a new BotUser\r
# is returned:\r
# * associated BotUser on _chan_\r
# * associated BotUser on all channels\r
- # * anonbotuser on _chan_\r
- # * anonbotuser on all channels\r
+ # * everyone on _chan_\r
+ # * everyone on all channels\r
#\r
def permit?(user, cmdtxt, chan=nil)\r
botuser = irc_to_botuser(user)\r
allow = botuser.permit?(cmd)\r
return allow unless allow.nil?\r
\r
- unless botuser == Auth::anonbotuser\r
- allow = Auth::anonbotuser.permit?(cmd, chan) if chan\r
+ unless botuser == everyone\r
+ allow = everyone.permit?(cmd, chan) if chan\r
return allow unless allow.nil?\r
- allow = Auth::anonbotuser.permit?(cmd)\r
+ allow = everyone.permit?(cmd)\r
return allow unless allow.nil?\r
end\r
\r