Changed supybot.capabilities to an ircdb.CapabilitySet instead of a ircutils.IrcSet.

This commit is contained in:
Jeremy Fincher 2004-08-27 04:48:16 +00:00
parent f0a5207117
commit f4c384a274
2 changed files with 34 additions and 36 deletions

View File

@ -252,36 +252,6 @@ registerGlobalValue(supybot, 'channels',
SpaceSeparatedSetOfChannels([], """Determines what channels the bot will SpaceSeparatedSetOfChannels([], """Determines what channels the bot will
join when it connects to the server.""")) join when it connects to the server."""))
class DefaultCapabilities(registry.SpaceSeparatedListOfStrings):
List = ircutils.IrcSet
# We use a keyword argument trick here to prevent eval'ing of code that
# changes allowDefaultOwner from affecting this. It's not perfect, but
# it's still an improvement, raising the bar for potential crackers.
def setValue(self, v, allowDefaultOwner=allowDefaultOwner):
registry.SpaceSeparatedListOfStrings.setValue(self, v)
if '-owner' not in self.value and not allowDefaultOwner:
print '*** You must run supybot with the --allow-default-owner'
print '*** option in order to allow a default capability of owner.'
print '*** Don\'t do that, it\'s dumb.'
self.value.add('-owner')
###
# supybot.capabilities
###
registerGlobalValue(supybot, 'capabilities',
DefaultCapabilities(['-owner', '-admin', '-trusted'], """These are the
capabilities that are given to everyone by default. If they are normal
capabilities, then the user will have to have the appropriate
anti-capability if you want to override these capabilities; if they are
anti-capabilities, then the user will have to have the actual capability
to override these capabilities. See docs/CAPABILITIES if you don't
understand why these default to what they do."""))
registerGlobalValue(supybot.capabilities, 'default',
registry.Boolean(True, """Determines whether the bot by default will allow
users to have a capability. If this is disabled, a user must explicitly
have the capability for whatever command he wishes to run."""))
### ###
# Reply/error tweaking. # Reply/error tweaking.
### ###

View File

@ -46,6 +46,7 @@ import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
import supybot.world as world import supybot.world as world
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
import supybot.registry as registry
import supybot.unpreserve as unpreserve import supybot.unpreserve as unpreserve
def fromChannelCapability(capability): def fromChannelCapability(capability):
@ -928,9 +929,7 @@ def _checkCapabilityForUnknownUser(capability, users=users, channels=channels):
pass pass
defaultCapabilities = conf.supybot.capabilities() defaultCapabilities = conf.supybot.capabilities()
if capability in defaultCapabilities: if capability in defaultCapabilities:
return True return defaultCapabilities.check(capability)
elif invertCapability(capability) in defaultCapabilities:
return False
else: else:
return _x(capability, conf.supybot.capabilities.default()) return _x(capability, conf.supybot.capabilities.default())
@ -970,9 +969,7 @@ def checkCapability(hostmask, capability, users=users, channels=channels):
return _x(capability, c.defaultAllow) return _x(capability, c.defaultAllow)
defaultCapabilities = conf.supybot.capabilities() defaultCapabilities = conf.supybot.capabilities()
if capability in defaultCapabilities: if capability in defaultCapabilities:
return True return defaultCapabilities.check(capability)
elif invertCapability(capability) in defaultCapabilities:
return False
else: else:
return _x(capability, conf.supybot.capabilities.default()) return _x(capability, conf.supybot.capabilities.default())
@ -995,5 +992,36 @@ def checkCapabilities(hostmask, capabilities, requireAll=False):
else: else:
return False return False
###
# supybot.capabilities
###
class DefaultCapabilities(registry.SpaceSeparatedListOfStrings):
List = CapabilitySet
# We use a keyword argument trick here to prevent eval'ing of code that
# changes allowDefaultOwner from affecting this. It's not perfect, but
# it's still an improvement, raising the bar for potential crackers.
def setValue(self, v, allowDefaultOwner=conf.allowDefaultOwner):
registry.SpaceSeparatedListOfStrings.setValue(self, v)
if '-owner' not in self.value and not allowDefaultOwner:
print '*** You must run supybot with the --allow-default-owner'
print '*** option in order to allow a default capability of owner.'
print '*** Don\'t do that, it\'s dumb.'
self.value.add('-owner')
conf.registerGlobalValue(conf.supybot, 'capabilities',
DefaultCapabilities(['-owner', '-admin', '-trusted'], """These are the
capabilities that are given to everyone by default. If they are normal
capabilities, then the user will have to have the appropriate
anti-capability if you want to override these capabilities; if they are
anti-capabilities, then the user will have to have the actual capability
to override these capabilities. See docs/CAPABILITIES if you don't
understand why these default to what they do."""))
conf.registerGlobalValue(conf.supybot.capabilities, 'default',
registry.Boolean(True, """Determines whether the bot by default will allow
users to have a capability. If this is disabled, a user must explicitly
have the capability for whatever command he wishes to run."""))
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: