From 7f22a1c9b6df6c65c2f09172c961b2c6fd87aee7 Mon Sep 17 00:00:00 2001 From: James Vega Date: Mon, 20 Sep 2004 01:33:44 +0000 Subject: [PATCH] Add rfe #1004006, {add,remove,{un,}set}capability can accept multiple capabilities. --- src/Channel.py | 69 ++++++++++++++++++++++++++------------------ test/test_Channel.py | 4 +++ 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/src/Channel.py b/src/Channel.py index 4f3a1c385..4105c8e79 100755 --- a/src/Channel.py +++ b/src/Channel.py @@ -568,47 +568,53 @@ class Channel(callbacks.Privmsg): ignores = privmsgs.checkChannelCapability(ignores, 'op') def addcapability(self, irc, msg, args, channel): - """[] + """[] [ ...] If you have the #channel,op capability, this will give the user currently identified as (or the user to whom maps) the capability in the channel. is only necessary if the message isn't sent in the channel itself. """ - (name, capability) = privmsgs.getArgs(args, 2) - capability = ircdb.makeChannelCapability(channel, capability) + (name, capabilities) = privmsgs.getArgs(args, 2) try: id = ircdb.users.getUserId(name) user = ircdb.users.getUser(id) - user.addCapability(capability) - ircdb.users.setUser(id, user) - irc.replySuccess() except KeyError: irc.errorNoUser() + for c in capability.split(): + c = ircdb.makeChannelCapability(channel, c) + user.addCapability(c) + ircdb.users.setUser(id, user) + irc.replySuccess() addcapability = privmsgs.checkChannelCapability(addcapability,'op') def removecapability(self, irc, msg, args, channel): - """[] + """[] [ ...] If you have the #channel,op capability, this will take from the user currently identified as (or the user to whom maps) the capability in the channel. is only necessary if the message isn't sent in the channel itself. """ - (name, capability) = privmsgs.getArgs(args, 2) - capability = ircdb.makeChannelCapability(channel, capability) + (name, capabilities) = privmsgs.getArgs(args, 2) try: id = ircdb.users.getUserId(name) except KeyError: irc.errorNoUser() return user = ircdb.users.getUser(id) - try: - user.removeCapability(capability) - except KeyError: - irc.error('That user doesn\'t have the %s capability.'%capability) - return + fail = [] + for c in capabilities.split(): + cap = ircdb.makeChannelCapability(channel, c) + try: + user.removeCapability(cap) + except KeyError: + fail.append(c) ircdb.users.setUser(id, user) + if fail: + irc.error('That user didn\'t have the %s %s.' % + (utils.commaAndify(fail), + utils.pluralize('capability', len(fail))), Raise=True) irc.replySuccess() removecapability = privmsgs.checkChannelCapability(removecapability, 'op') @@ -637,35 +643,42 @@ class Channel(callbacks.Privmsg): privmsgs.checkChannelCapability(setdefaultcapability, 'op') def setcapability(self, irc, msg, args, channel): - """[] + """[] [ ...] If you have the #channel,op capability, this will add the channel capability for all users in the channel. is only necessary if the message isn't sent in the channel itself. """ - capability = privmsgs.getArgs(args) - c = ircdb.channels.getChannel(channel) - c.addCapability(capability) - ircdb.channels.setChannel(channel, c) + capabilities = privmsgs.getArgs(args) + chan = ircdb.channels.getChannel(channel) + for c in capabilities.split(): + chan.addCapability(c) + ircdb.channels.setChannel(channel, chan) irc.replySuccess() setcapability = privmsgs.checkChannelCapability(setcapability, 'op') def unsetcapability(self, irc, msg, args, channel): - """[] + """[] [ ...] If you have the #channel,op capability, this will unset the channel capability so each user's specific capability or the channel default capability will take precedence. is only necessary if the message isn't sent in the channel itself. """ - capability = privmsgs.getArgs(args) - c = ircdb.channels.getChannel(channel) - try: - c.removeCapability(capability) - ircdb.channels.setChannel(channel, c) - irc.replySuccess() - except KeyError: - irc.error('I do not know about that channel capability.') + capabilities = privmsgs.getArgs(args) + chan = ircdb.channels.getChannel(channel) + fail = [] + for c in capabilities.split(): + try: + chan.removeCapability(c) + except KeyError: + fail.append(c) + ircdb.channels.setChannel(channel, chan) + if fail: + irc.error('I do not know about the %s %s.' % + (utils.commaAndify(fail), + utils.pluralize('capability', len(fail))), Raise=True) + irc.replySuccess() unsetcapability = privmsgs.checkChannelCapability(unsetcapability, 'op') def capabilities(self, irc, msg, args): diff --git a/test/test_Channel.py b/test/test_Channel.py index 18db9ba9d..fc8230477 100644 --- a/test/test_Channel.py +++ b/test/test_Channel.py @@ -59,6 +59,10 @@ class ChannelTestCase(ChannelPluginTestCase, PluginDocumentation): self.assertNotError('channel setcapability -foo') self.assertNotError('channel unsetcapability -foo') self.assertError('channel unsetcapability -foo') + self.assertNotError('channel setcapability -foo bar baz') + self.assertRegexp('channel capabilities', 'baz') + self.assertNotError('channel unsetcapability -foo baz') + self.assertError('channel unsetcapability baz') def testUnban(self): self.assertError('unban foo!bar@baz')