mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Fixed handling of channel capabilities
This commit is contained in:
parent
2b2f9356e0
commit
c49bd6f88f
@ -64,7 +64,10 @@ class Topic(callbacks.Privmsg):
|
|||||||
irc.error(msg, s)
|
irc.error(msg, s)
|
||||||
return
|
return
|
||||||
currentTopic = irc.state.getTopic(channel)
|
currentTopic = irc.state.getTopic(channel)
|
||||||
|
try:
|
||||||
name = ircdb.users.getUserName(msg.prefix)
|
name = ircdb.users.getUserName(msg.prefix)
|
||||||
|
except KeyError:
|
||||||
|
name = msg.nick
|
||||||
formattedTopic = self.topicFormatter % (topic, name)
|
formattedTopic = self.topicFormatter % (topic, name)
|
||||||
if currentTopic:
|
if currentTopic:
|
||||||
newTopic = self.topicSeparator.join((currentTopic,
|
newTopic = self.topicSeparator.join((currentTopic,
|
||||||
@ -126,7 +129,11 @@ class Topic(callbacks.Privmsg):
|
|||||||
topic = topics.pop(number)
|
topic = topics.pop(number)
|
||||||
debug.printf(topic)
|
debug.printf(topic)
|
||||||
(topic, name) = self.topicUnformatter.match(topic).groups()
|
(topic, name) = self.topicUnformatter.match(topic).groups()
|
||||||
if name != ircdb.users.getUserName(msg.prefix) and \
|
try:
|
||||||
|
username = ircdb.users.getUserName(msg.prefix)
|
||||||
|
except KeyError:
|
||||||
|
username = msg.nick
|
||||||
|
if name != username and \
|
||||||
not ircdb.checkCapabilities(msg.prefix, ('op', 'admin')):
|
not ircdb.checkCapabilities(msg.prefix, ('op', 'admin')):
|
||||||
irc.error('You can only remove your own topics.')
|
irc.error('You can only remove your own topics.')
|
||||||
return
|
return
|
||||||
|
@ -301,44 +301,36 @@ class ChannelCommands(callbacks.Privmsg):
|
|||||||
capability = ircdb.makeChannelCapability(channel, 'op')
|
capability = ircdb.makeChannelCapability(channel, 'op')
|
||||||
if ircdb.checkCapability(msg.prefix, capability):
|
if ircdb.checkCapability(msg.prefix, capability):
|
||||||
c = ircdb.channels.getChannel(channel)
|
c = ircdb.channels.getChannel(channel)
|
||||||
if v == 'True' or v == 'False':
|
v = v.capitalize()
|
||||||
if v == 'True':
|
if v == 'True':
|
||||||
c.setDefaultCapability(True)
|
c.setDefaultCapability(True)
|
||||||
elif v == 'False':
|
elif v == 'False':
|
||||||
c.setDefaultCapability(False)
|
c.setDefaultCapability(False)
|
||||||
ircdb.channels.setChannel(channel, c)
|
|
||||||
irc.reply(msg, conf.replySuccess)
|
|
||||||
else:
|
else:
|
||||||
s = 'The default value must be either True or False.'
|
s = 'The default value must be either True or False.'
|
||||||
irc.error(msg, s)
|
irc.error(msg, s)
|
||||||
|
return
|
||||||
|
ircdb.channels.setChannel(channel, c)
|
||||||
|
irc.reply(msg, conf.replySuccess)
|
||||||
else:
|
else:
|
||||||
irc.error(msg, conf.replyNoCapability % capability)
|
irc.error(msg, conf.replyNoCapability % capability)
|
||||||
|
|
||||||
def setchancapability(self, irc, msg, args):
|
def setchancapability(self, irc, msg, args):
|
||||||
"""[<channel>] <capability> <True|False>
|
"""[<channel>] <capability>
|
||||||
|
|
||||||
The <channel> argument is only necessary if the message isn't being
|
The <channel> argument is only necessary if the message isn't being
|
||||||
sent in the channel itself. If you have the #channel.op capability,
|
sent in the channel itself. If you have the #channel.op capability,
|
||||||
this will set the channel capability <capability> for all users in the
|
this will add the channel capability <capability> for all users in the
|
||||||
channel.
|
channel.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
neededcapability = ircdb.makeChannelCapability(channel, 'op')
|
neededcapability = ircdb.makeChannelCapability(channel, 'op')
|
||||||
if ircdb.checkCapability(msg.prefix, neededcapability):
|
if ircdb.checkCapability(msg.prefix, neededcapability):
|
||||||
(capability, value) = privmsgs.getArgs(args, 2)
|
capability = privmsgs.getArgs(args)
|
||||||
value = value.capitalize()
|
|
||||||
if value == 'True' or value == 'False':
|
|
||||||
if value == 'True':
|
|
||||||
value = True
|
|
||||||
elif value == 'False':
|
|
||||||
value = False
|
|
||||||
c = ircdb.channels.getChannel(channel)
|
c = ircdb.channels.getChannel(channel)
|
||||||
c.addCapability(capability, value)
|
c.addCapability(capability)
|
||||||
ircdb.channels.setChannel(channel, c)
|
ircdb.channels.setChannel(channel, c)
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
else:
|
|
||||||
s = 'Value of the capability must be True or False'
|
|
||||||
irc.error(msg, s)
|
|
||||||
else:
|
else:
|
||||||
irc.error(msg, conf.replyNoCapability % neededcapability)
|
irc.error(msg, conf.replyNoCapability % neededcapability)
|
||||||
|
|
||||||
@ -362,6 +354,17 @@ class ChannelCommands(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
irc.error(msg, conf.replyNoCapability % neededcapability)
|
irc.error(msg, conf.replyNoCapability % neededcapability)
|
||||||
|
|
||||||
|
def chancapabilities(self, irc, msg, args):
|
||||||
|
"""[<channel>]
|
||||||
|
|
||||||
|
The <channel> argument is only necessary if the message isn't being
|
||||||
|
sent in the channel itself. Returns the capabilities present on the
|
||||||
|
<channel>.
|
||||||
|
"""
|
||||||
|
channel = privmsgs.getChannel(msg, args)
|
||||||
|
c = ircdb.channels.getChannel(channel)
|
||||||
|
irc.reply(msg, ', '.join(c.capabilities))
|
||||||
|
|
||||||
|
|
||||||
Class = ChannelCommands
|
Class = ChannelCommands
|
||||||
|
|
||||||
|
29
src/ircdb.py
29
src/ircdb.py
@ -158,7 +158,7 @@ class IrcUser(object):
|
|||||||
class IrcChannel(object):
|
class IrcChannel(object):
|
||||||
"""This class holds the capabilities, bans, and ignores of a channel.
|
"""This class holds the capabilities, bans, and ignores of a channel.
|
||||||
"""
|
"""
|
||||||
defaultOff = ['op', 'halfop', 'voice', 'protected']
|
defaultOff = ('op', 'halfop', 'voice', 'protected')
|
||||||
def __init__(self, bans=None, ignores=None, capabilities=None,
|
def __init__(self, bans=None, ignores=None, capabilities=None,
|
||||||
lobotomized=False, defaultAllow=True):
|
lobotomized=False, defaultAllow=True):
|
||||||
self.defaultAllow = defaultAllow
|
self.defaultAllow = defaultAllow
|
||||||
@ -171,13 +171,13 @@ class IrcChannel(object):
|
|||||||
else:
|
else:
|
||||||
self.ignores = ignores
|
self.ignores = ignores
|
||||||
if capabilities is None:
|
if capabilities is None:
|
||||||
self.capabilities = {}
|
self.capabilities = set()
|
||||||
else:
|
else:
|
||||||
self.capabilities = capabilities
|
self.capabilities = capabilities
|
||||||
|
|
||||||
for capability in self.defaultOff:
|
for capability in self.defaultOff:
|
||||||
if capability not in self.capabilities:
|
if capability not in self.capabilities:
|
||||||
self.capabilities[capability] = False
|
self.capabilities.add(makeAntiCapability(capability))
|
||||||
self.lobotomized = lobotomized
|
self.lobotomized = lobotomized
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -205,19 +205,20 @@ class IrcChannel(object):
|
|||||||
def removeIgnore(self, hostmask):
|
def removeIgnore(self, hostmask):
|
||||||
self.ignores = [s for s in self.ignores if s != hostmask]
|
self.ignores = [s for s in self.ignores if s != hostmask]
|
||||||
|
|
||||||
def addCapability(self, capability, value):
|
def addCapability(self, capability):
|
||||||
self.capabilities[capability] = value
|
self.capabilities.add(capability)
|
||||||
|
|
||||||
def removeCapability(self, capability):
|
def removeCapability(self, capability):
|
||||||
del self.capabilities[capability]
|
self.capabilities.remove(capability)
|
||||||
|
|
||||||
def setDefaultCapability(self, v):
|
def setDefaultCapability(self, b):
|
||||||
self.defaultAllow = v
|
self.defaultAllow = b
|
||||||
|
|
||||||
def checkCapability(self, capability):
|
def checkCapability(self, capability):
|
||||||
if capability in self.capabilities:
|
if capability in self.capabilities:
|
||||||
return self.capabilities[capability]
|
return True
|
||||||
elif isAntiCapability(capability):
|
else:
|
||||||
|
if isAntiCapability(capability):
|
||||||
return not self.defaultAllow
|
return not self.defaultAllow
|
||||||
else:
|
else:
|
||||||
return self.defaultAllow
|
return self.defaultAllow
|
||||||
@ -424,6 +425,7 @@ def checkCapability(hostmask, capability, users=users, channels=channels):
|
|||||||
try:
|
try:
|
||||||
(channel, capability) = fromChannelCapability(capability)
|
(channel, capability) = fromChannelCapability(capability)
|
||||||
except ValueError: # unpack list of wrong size
|
except ValueError: # unpack list of wrong size
|
||||||
|
debug.printf('Invalid channel capability in checkCapability')
|
||||||
return False # stupid, invalid capability.
|
return False # stupid, invalid capability.
|
||||||
# Now, go fetch the channel and check to see what it thinks about
|
# Now, go fetch the channel and check to see what it thinks about
|
||||||
# said capability.
|
# said capability.
|
||||||
@ -447,13 +449,14 @@ def checkCapability(hostmask, capability, users=users, channels=channels):
|
|||||||
if isChannelCapability(capability):
|
if isChannelCapability(capability):
|
||||||
# First check to see if the user has the capability already; if so,
|
# First check to see if the user has the capability already; if so,
|
||||||
# it can be returned without checking the channel.
|
# it can be returned without checking the channel.
|
||||||
try:
|
if u.checkCapability(capability):
|
||||||
return u.checkCapability(capability)
|
return True
|
||||||
except KeyError:
|
else:
|
||||||
# User doesn't have the capability. Check the channel.
|
# User doesn't have the capability. Check the channel.
|
||||||
try:
|
try:
|
||||||
(channel, capability) = fromChannelCapability(capability)
|
(channel, capability) = fromChannelCapability(capability)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
debug.printf('Invalid channel capability in checkCapability')
|
||||||
return False # stupid, invalid capability.
|
return False # stupid, invalid capability.
|
||||||
c = channels.getChannel(channel)
|
c = channels.getChannel(channel)
|
||||||
# And return the channel's opinion.
|
# And return the channel's opinion.
|
||||||
|
Loading…
Reference in New Issue
Block a user