mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 23:54:07 +01:00
Add checkCapabilityButIgnoreOwner converter
This commit is contained in:
parent
e705d3b5a9
commit
e8814fc07a
@ -50,11 +50,8 @@ class AutoMode(callbacks.Plugin):
|
|||||||
return
|
return
|
||||||
fallthrough = self.registryValue('fallthrough', channel)
|
fallthrough = self.registryValue('fallthrough', channel)
|
||||||
def do(type):
|
def do(type):
|
||||||
if ircdb.checkCapability(msg.prefix, 'owner') and not \
|
|
||||||
self.registryValue('owner'):
|
|
||||||
raise Continue
|
|
||||||
cap = ircdb.makeChannelCapability(channel, type)
|
cap = ircdb.makeChannelCapability(channel, type)
|
||||||
if ircdb.checkCapability(msg.prefix, cap):
|
if ircdb.checkCapability(msg.prefix, cap, ignoreOwner=True):
|
||||||
if self.registryValue(type, channel):
|
if self.registryValue(type, channel):
|
||||||
self.log.info('Sending auto-%s of %s in %s.',
|
self.log.info('Sending auto-%s of %s in %s.',
|
||||||
type, msg.prefix, channel)
|
type, msg.prefix, channel)
|
||||||
|
@ -477,6 +477,11 @@ def checkCapability(irc, msg, args, state, cap):
|
|||||||
if not ircdb.checkCapability(msg.prefix, cap):
|
if not ircdb.checkCapability(msg.prefix, cap):
|
||||||
state.errorNoCapability(cap, Raise=True)
|
state.errorNoCapability(cap, Raise=True)
|
||||||
|
|
||||||
|
def checkCapabilityButIgnoreOwner(irc, msg, args, state, cap):
|
||||||
|
cap = ircdb.canonicalCapability(cap)
|
||||||
|
if not ircdb.checkCapability(msg.prefix, cap, ignoreOwner=True):
|
||||||
|
state.errorNoCapability(cap, Raise=True)
|
||||||
|
|
||||||
def owner(irc, msg, args, state):
|
def owner(irc, msg, args, state):
|
||||||
checkCapability(irc, msg, args, state, 'owner')
|
checkCapability(irc, msg, args, state, 'owner')
|
||||||
|
|
||||||
@ -590,6 +595,7 @@ wrappers = ircutils.IrcDict({
|
|||||||
'channel': getChannel,
|
'channel': getChannel,
|
||||||
'channelDb': getChannelDb,
|
'channelDb': getChannelDb,
|
||||||
'checkCapability': checkCapability,
|
'checkCapability': checkCapability,
|
||||||
|
'checkCapabilityButIgnoreOwner': checkCapabilityButIgnoreOwner,
|
||||||
'checkChannelCapability': checkChannelCapability,
|
'checkChannelCapability': checkChannelCapability,
|
||||||
'color': getIrcColor,
|
'color': getIrcColor,
|
||||||
'commandName': getCommandName,
|
'commandName': getCommandName,
|
||||||
|
22
src/ircdb.py
22
src/ircdb.py
@ -1,6 +1,7 @@
|
|||||||
###
|
###
|
||||||
# Copyright (c) 2002-2009, Jeremiah Fincher
|
# Copyright (c) 2002-2009, Jeremiah Fincher
|
||||||
# Copyright (c) 2009, James Vega
|
# Copyright (c) 2009, James Vega
|
||||||
|
# Copyright (c) 2011, Valentin Lorentz
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -152,7 +153,7 @@ class CapabilitySet(set):
|
|||||||
elif self.__parent.__contains__(_invert(capability)):
|
elif self.__parent.__contains__(_invert(capability)):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
raise KeyError, capability
|
return False
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '%s([%s])' % (self.__class__.__name__,
|
return '%s([%s])' % (self.__class__.__name__,
|
||||||
@ -165,16 +166,16 @@ class UserCapabilitySet(CapabilitySet):
|
|||||||
self.__parent = super(UserCapabilitySet, self)
|
self.__parent = super(UserCapabilitySet, self)
|
||||||
self.__parent.__init__(*args, **kwargs)
|
self.__parent.__init__(*args, **kwargs)
|
||||||
|
|
||||||
def __contains__(self, capability):
|
def __contains__(self, capability, ignoreOwner=False):
|
||||||
capability = ircutils.toLower(capability)
|
capability = ircutils.toLower(capability)
|
||||||
if capability == 'owner' or capability == antiOwner:
|
if not ignoreOwner and capability == 'owner' or capability == antiOwner:
|
||||||
return True
|
return True
|
||||||
elif self.__parent.__contains__('owner'):
|
elif not ignoreOwner and self.__parent.__contains__('owner'):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return self.__parent.__contains__(capability)
|
return self.__parent.__contains__(capability)
|
||||||
|
|
||||||
def check(self, capability):
|
def check(self, capability, ignoreOwner=False):
|
||||||
"""Returns the appropriate boolean for whether a given capability is
|
"""Returns the appropriate boolean for whether a given capability is
|
||||||
'allowed' given its (or its anticapability's) presence in the set.
|
'allowed' given its (or its anticapability's) presence in the set.
|
||||||
Differs from CapabilitySet in that it handles the 'owner' capability
|
Differs from CapabilitySet in that it handles the 'owner' capability
|
||||||
@ -186,7 +187,7 @@ class UserCapabilitySet(CapabilitySet):
|
|||||||
return not isAntiCapability(capability)
|
return not isAntiCapability(capability)
|
||||||
else:
|
else:
|
||||||
return isAntiCapability(capability)
|
return isAntiCapability(capability)
|
||||||
elif self.__parent.__contains__('owner'):
|
elif not ignoreOwner and self.__parent.__contains__('owner'):
|
||||||
if isAntiCapability(capability):
|
if isAntiCapability(capability):
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
@ -236,7 +237,7 @@ class IrcUser(object):
|
|||||||
"""Takes from the user the given capability."""
|
"""Takes from the user the given capability."""
|
||||||
self.capabilities.remove(capability)
|
self.capabilities.remove(capability)
|
||||||
|
|
||||||
def _checkCapability(self, capability):
|
def _checkCapability(self, capability, ignoreOwner=False):
|
||||||
"""Checks the user for a given capability."""
|
"""Checks the user for a given capability."""
|
||||||
if self.ignore:
|
if self.ignore:
|
||||||
if isAntiCapability(capability):
|
if isAntiCapability(capability):
|
||||||
@ -244,7 +245,7 @@ class IrcUser(object):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return self.capabilities.check(capability)
|
return self.capabilities.check(capability, ignoreOwner)
|
||||||
|
|
||||||
def setPassword(self, password, hashed=False):
|
def setPassword(self, password, hashed=False):
|
||||||
"""Sets the user's password."""
|
"""Sets the user's password."""
|
||||||
@ -1009,7 +1010,8 @@ def _checkCapabilityForUnknownUser(capability, users=users, channels=channels):
|
|||||||
else:
|
else:
|
||||||
return _x(capability, conf.supybot.capabilities.default())
|
return _x(capability, conf.supybot.capabilities.default())
|
||||||
|
|
||||||
def checkCapability(hostmask, capability, users=users, channels=channels):
|
def checkCapability(hostmask, capability, users=users, channels=channels,
|
||||||
|
ignoreOwner=False):
|
||||||
"""Checks that the user specified by name/hostmask has the capability given.
|
"""Checks that the user specified by name/hostmask has the capability given.
|
||||||
"""
|
"""
|
||||||
if world.testing:
|
if world.testing:
|
||||||
@ -1028,7 +1030,7 @@ def checkCapability(hostmask, capability, users=users, channels=channels):
|
|||||||
return _checkCapabilityForUnknownUser(capability, users=users,
|
return _checkCapabilityForUnknownUser(capability, users=users,
|
||||||
channels=channels)
|
channels=channels)
|
||||||
if capability in u.capabilities:
|
if capability in u.capabilities:
|
||||||
return u._checkCapability(capability)
|
return u._checkCapability(capability, ignoreOwner)
|
||||||
else:
|
else:
|
||||||
if isChannelCapability(capability):
|
if isChannelCapability(capability):
|
||||||
(channel, capability) = fromChannelCapability(capability)
|
(channel, capability) = fromChannelCapability(capability)
|
||||||
|
Loading…
Reference in New Issue
Block a user