mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-09 19:52:37 +01:00
ToDo #1046877 : Added Enable/Disable commands
This commit is contained in:
parent
4c555d40c1
commit
3f2f500dc4
@ -659,6 +659,89 @@ class Channel(callbacks.Privmsg):
|
|||||||
irc.reply(' '.join(L))
|
irc.reply(' '.join(L))
|
||||||
capabilities = wrap(capabilities, ['channel'])
|
capabilities = wrap(capabilities, ['channel'])
|
||||||
|
|
||||||
|
def disable(self, irc, msg, args, channel, plugin, command):
|
||||||
|
"""[<channel>] [<plugin>] [<command>]
|
||||||
|
|
||||||
|
If you have the #channel,op capability, this will disable the <command>
|
||||||
|
in <channel>. If <plugin> is provided, <command> will be disabled only
|
||||||
|
for that plugin. If only <plugin> is provided, all commands in the
|
||||||
|
given plugin will be disabled. <channel> 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):
|
||||||
|
"""[<channel>] [<plugin>] [<command>]
|
||||||
|
|
||||||
|
If you have the #channel,op capability, this will enable the <command>
|
||||||
|
in <channel> if it has been disabled. If <plugin> is provided,
|
||||||
|
<command> will be enabled only for that plugin. If only <plugin> is
|
||||||
|
provided, all commands in the given plugin will be enabled. <channel>
|
||||||
|
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):
|
def lobotomies(self, irc, msg, args):
|
||||||
"""takes no arguments
|
"""takes no arguments
|
||||||
|
|
||||||
|
@ -68,6 +68,24 @@ class ChannelTestCase(ChannelPluginTestCase):
|
|||||||
self.assertNotError('channel unsetcapability -foo baz')
|
self.assertNotError('channel unsetcapability -foo baz')
|
||||||
self.assertError('channel unsetcapability 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):
|
def testUnban(self):
|
||||||
self.assertError('unban foo!bar@baz')
|
self.assertError('unban foo!bar@baz')
|
||||||
self.irc.feedMsg(ircmsgs.op(self.channel, self.nick))
|
self.irc.feedMsg(ircmsgs.op(self.channel, self.nick))
|
||||||
|
Loading…
Reference in New Issue
Block a user