From c49bd6f88f45952550630609fcf55190caa3fef1 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 2 Apr 2003 11:08:34 +0000 Subject: [PATCH] Fixed handling of channel capabilities --- plugins/Topic.py | 11 ++++++++-- src/ChannelCommands.py | 49 ++++++++++++++++++++++-------------------- src/ircdb.py | 33 +++++++++++++++------------- 3 files changed, 53 insertions(+), 40 deletions(-) diff --git a/plugins/Topic.py b/plugins/Topic.py index 690bf13e6..be25102a9 100644 --- a/plugins/Topic.py +++ b/plugins/Topic.py @@ -64,7 +64,10 @@ class Topic(callbacks.Privmsg): irc.error(msg, s) return currentTopic = irc.state.getTopic(channel) - name = ircdb.users.getUserName(msg.prefix) + try: + name = ircdb.users.getUserName(msg.prefix) + except KeyError: + name = msg.nick formattedTopic = self.topicFormatter % (topic, name) if currentTopic: newTopic = self.topicSeparator.join((currentTopic, @@ -126,7 +129,11 @@ class Topic(callbacks.Privmsg): topic = topics.pop(number) debug.printf(topic) (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')): irc.error('You can only remove your own topics.') return diff --git a/src/ChannelCommands.py b/src/ChannelCommands.py index ef88bce00..604967133 100755 --- a/src/ChannelCommands.py +++ b/src/ChannelCommands.py @@ -301,44 +301,36 @@ class ChannelCommands(callbacks.Privmsg): capability = ircdb.makeChannelCapability(channel, 'op') if ircdb.checkCapability(msg.prefix, capability): c = ircdb.channels.getChannel(channel) - if v == 'True' or v == 'False': - if v == 'True': - c.setDefaultCapability(True) - elif v == 'False': - c.setDefaultCapability(False) - ircdb.channels.setChannel(channel, c) - irc.reply(msg, conf.replySuccess) + v = v.capitalize() + if v == 'True': + c.setDefaultCapability(True) + elif v == 'False': + c.setDefaultCapability(False) else: s = 'The default value must be either True or False.' irc.error(msg, s) + return + ircdb.channels.setChannel(channel, c) + irc.reply(msg, conf.replySuccess) else: irc.error(msg, conf.replyNoCapability % capability) def setchancapability(self, irc, msg, args): - """[] + """[] The argument is only necessary if the message isn't being sent in the channel itself. If you have the #channel.op capability, - this will set the channel capability for all users in the + this will add the channel capability for all users in the channel. """ channel = privmsgs.getChannel(msg, args) neededcapability = ircdb.makeChannelCapability(channel, 'op') if ircdb.checkCapability(msg.prefix, neededcapability): - (capability, value) = privmsgs.getArgs(args, 2) - 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.addCapability(capability, value) - ircdb.channels.setChannel(channel, c) - irc.reply(msg, conf.replySuccess) - else: - s = 'Value of the capability must be True or False' - irc.error(msg, s) + capability = privmsgs.getArgs(args) + c = ircdb.channels.getChannel(channel) + c.addCapability(capability) + ircdb.channels.setChannel(channel, c) + irc.reply(msg, conf.replySuccess) else: irc.error(msg, conf.replyNoCapability % neededcapability) @@ -362,6 +354,17 @@ class ChannelCommands(callbacks.Privmsg): else: irc.error(msg, conf.replyNoCapability % neededcapability) + def chancapabilities(self, irc, msg, args): + """[] + + The argument is only necessary if the message isn't being + sent in the channel itself. Returns the capabilities present on the + . + """ + channel = privmsgs.getChannel(msg, args) + c = ircdb.channels.getChannel(channel) + irc.reply(msg, ', '.join(c.capabilities)) + Class = ChannelCommands diff --git a/src/ircdb.py b/src/ircdb.py index 3abe43810..e59bbbfa8 100644 --- a/src/ircdb.py +++ b/src/ircdb.py @@ -158,7 +158,7 @@ class IrcUser(object): class IrcChannel(object): """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, lobotomized=False, defaultAllow=True): self.defaultAllow = defaultAllow @@ -171,13 +171,13 @@ class IrcChannel(object): else: self.ignores = ignores if capabilities is None: - self.capabilities = {} + self.capabilities = set() else: self.capabilities = capabilities for capability in self.defaultOff: if capability not in self.capabilities: - self.capabilities[capability] = False + self.capabilities.add(makeAntiCapability(capability)) self.lobotomized = lobotomized def __repr__(self): @@ -205,22 +205,23 @@ class IrcChannel(object): def removeIgnore(self, hostmask): self.ignores = [s for s in self.ignores if s != hostmask] - def addCapability(self, capability, value): - self.capabilities[capability] = value + def addCapability(self, capability): + self.capabilities.add(capability) def removeCapability(self, capability): - del self.capabilities[capability] + self.capabilities.remove(capability) - def setDefaultCapability(self, v): - self.defaultAllow = v + def setDefaultCapability(self, b): + self.defaultAllow = b def checkCapability(self, capability): if capability in self.capabilities: - return self.capabilities[capability] - elif isAntiCapability(capability): - return not self.defaultAllow + return True else: - return self.defaultAllow + if isAntiCapability(capability): + return not self.defaultAllow + else: + return self.defaultAllow def checkIgnored(self, hostmask): if self.lobotomized: @@ -424,6 +425,7 @@ def checkCapability(hostmask, capability, users=users, channels=channels): try: (channel, capability) = fromChannelCapability(capability) except ValueError: # unpack list of wrong size + debug.printf('Invalid channel capability in checkCapability') return False # stupid, invalid capability. # Now, go fetch the channel and check to see what it thinks about # said capability. @@ -447,13 +449,14 @@ def checkCapability(hostmask, capability, users=users, channels=channels): if isChannelCapability(capability): # First check to see if the user has the capability already; if so, # it can be returned without checking the channel. - try: - return u.checkCapability(capability) - except KeyError: + if u.checkCapability(capability): + return True + else: # User doesn't have the capability. Check the channel. try: (channel, capability) = fromChannelCapability(capability) except ValueError: + debug.printf('Invalid channel capability in checkCapability') return False # stupid, invalid capability. c = channels.getChannel(channel) # And return the channel's opinion.