From 3f2f500dc4c9789edf3294e6f5b99a5c98bfa141 Mon Sep 17 00:00:00 2001 From: Kevin Murphy Date: Thu, 28 Oct 2004 06:37:39 +0000 Subject: [PATCH] ToDo #1046877 : Added Enable/Disable commands --- src/Channel.py | 83 ++++++++++++++++++++++++++++++++++++++++++++ test/test_Channel.py | 18 ++++++++++ 2 files changed, 101 insertions(+) diff --git a/src/Channel.py b/src/Channel.py index 023b7f8bc..5c27f08f8 100755 --- a/src/Channel.py +++ b/src/Channel.py @@ -658,6 +658,89 @@ class Channel(callbacks.Privmsg): L = sorted(c.capabilities) irc.reply(' '.join(L)) capabilities = wrap(capabilities, ['channel']) + + def disable(self, irc, msg, args, channel, plugin, command): + """[] [] [] + + If you have the #channel,op capability, this will disable the + in . If is provided, will be disabled only + for that plugin. If only is provided, all commands in the + given plugin will be disabled. is only necessary if the + message isn't sent in the channel itself. + """ + chan = ircdb.channels.getChannel(channel) + failMsg = '' + if plugin: + s = '-%s' % plugin.name() + if command: + if plugin.isCommand(command): + s = '-%s.%s' % (plugin.name(), command) + else: + failMsg = 'The %s plugin does not have a command called %s.'\ + % (plugin.name(), command) + elif command: + # findCallbackForCommand + if irc.findCallbackForCommand(command): + s = '-%s' % command + else: + failMsg = 'No plugin or command named %s could be found.'\ + % (command) + else: + raise callbacks.ArgumentError + if failMsg: + irc.error(failMsg) + else: + chan.addCapability(s) + ircdb.channels.setChannel(channel, chan) + irc.replySuccess() + disable = wrap(disable, [('checkChannelCapability', 'op'), + optional(('plugin', False)), + additional('commandName')]) + + def enable(self, irc, msg, args, channel, plugin, command): + """[] [] [] + + If you have the #channel,op capability, this will enable the + in if it has been disabled. If is provided, + will be enabled only for that plugin. If only is + provided, all commands in the given plugin will be enabled. + is only necessary if the message isn't sent in the channel itself. + """ + chan = ircdb.channels.getChannel(channel) + failMsg = '' + if plugin: + s = '-%s' % plugin.name() + if command: + if plugin.isCommand(command): + s = '-%s.%s' % (plugin.name(), command) + else: + failMsg = 'The %s plugin does not have a command called %s.'\ + % (plugin.name(), command) + elif command: + # findCallbackForCommand + if irc.findCallbackForCommand(command): + s = '-%s' % command + else: + failMsg = 'No plugin or command named %s could be found.'\ + % (command) + else: + raise callbacks.ArgumentError + if failMsg: + irc.error(failMsg) + else: + fail = [] + try: + chan.removeCapability(s) + except KeyError: + fail.append(s) + ircdb.channels.setChannel(channel, chan) + if fail: + irc.error('%s was not disabled.' % s[1:]) + else: + irc.replySuccess() + enable = wrap(enable, [('checkChannelCapability', 'op'), + optional(('plugin', False)), + additional('commandName')]) def lobotomies(self, irc, msg, args): """takes no arguments diff --git a/test/test_Channel.py b/test/test_Channel.py index 4a2884698..63bfd6757 100644 --- a/test/test_Channel.py +++ b/test/test_Channel.py @@ -67,6 +67,24 @@ class ChannelTestCase(ChannelPluginTestCase): self.assertRegexp('channel capabilities', 'baz') self.assertNotError('channel unsetcapability -foo baz') self.assertError('channel unsetcapability baz') + + def testEnableDisable(self): + self.assertNotRegexp('channel capabilities', '-Channel') + self.assertError('channel enable channel') + self.assertNotError('channel disable channel') + self.assertRegexp('channel capabilities', '-Channel') + self.assertNotError('channel enable channel') + self.assertNotRegexp('channel capabilities', '-Channel') + self.assertNotError('channel disable channel nicks') + self.assertRegexp('channel capabilities', '-Channel.nicks') + self.assertNotError('channel enable channel nicks') + self.assertNotRegexp('channel capabilities', '-Channel.nicks') + self.assertNotRegexp('channel capabilities', 'nicks') + self.assertNotError('channel disable nicks') + self.assertRegexp('channel capabilities', 'nicks') + self.assertNotError('channel enable nicks') + self.assertError('channel disable invalidPlugin') + self.assertError('channel disable channel invalidCommand') def testUnban(self): self.assertError('unban foo!bar@baz')