From f4c384a274d5b71a0ae687b677bdc0d7ed00e212 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Fri, 27 Aug 2004 04:48:16 +0000 Subject: [PATCH] Changed supybot.capabilities to an ircdb.CapabilitySet instead of a ircutils.IrcSet. --- src/conf.py | 30 ------------------------------ src/ircdb.py | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/conf.py b/src/conf.py index 382b30d04..701d398fe 100644 --- a/src/conf.py +++ b/src/conf.py @@ -252,36 +252,6 @@ registerGlobalValue(supybot, 'channels', SpaceSeparatedSetOfChannels([], """Determines what channels the bot will 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. ### diff --git a/src/ircdb.py b/src/ircdb.py index 954ca2aa3..4c986f693 100644 --- a/src/ircdb.py +++ b/src/ircdb.py @@ -46,6 +46,7 @@ import supybot.conf as conf import supybot.utils as utils import supybot.world as world import supybot.ircutils as ircutils +import supybot.registry as registry import supybot.unpreserve as unpreserve def fromChannelCapability(capability): @@ -928,9 +929,7 @@ def _checkCapabilityForUnknownUser(capability, users=users, channels=channels): pass defaultCapabilities = conf.supybot.capabilities() if capability in defaultCapabilities: - return True - elif invertCapability(capability) in defaultCapabilities: - return False + return defaultCapabilities.check(capability) else: return _x(capability, conf.supybot.capabilities.default()) @@ -970,9 +969,7 @@ def checkCapability(hostmask, capability, users=users, channels=channels): return _x(capability, c.defaultAllow) defaultCapabilities = conf.supybot.capabilities() if capability in defaultCapabilities: - return True - elif invertCapability(capability) in defaultCapabilities: - return False + return defaultCapabilities.check(capability) else: return _x(capability, conf.supybot.capabilities.default()) @@ -995,5 +992,36 @@ def checkCapabilities(hostmask, capabilities, requireAll=False): else: 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: