diff --git a/plugins/Channel/plugin.py b/plugins/Channel/plugin.py index 851989e82..a9ec0332d 100644 --- a/plugins/Channel/plugin.py +++ b/plugins/Channel/plugin.py @@ -63,8 +63,7 @@ class Channel(callbacks.Plugin): itself. """ self._sendMsg(irc, ircmsgs.mode(channel, modes)) - mode = wrap(mode, - ['op', ('haveOp', 'change the mode'), many('something')]) + mode = wrap(mode, ['op', ('haveOp', 'change the mode'), many('something')]) def limit(self, irc, msg, args, channel, limit): """[] [] @@ -425,234 +424,264 @@ class Channel(callbacks.Plugin): if replyirc is not None: replyIrc.error(format('There is no %s on this server.', nick)) - def lobotomize(self, irc, msg, args, channel): - """[] + class lobotomy(callbacks.Commands): + def add(self, irc, msg, args, channel): + """[] - If you have the #channel,op capability, this will "lobotomize" the - bot, making it silent and unanswering to all requests made in the - channel. is only necessary if the message isn't sent in the - channel itself. - """ - c = ircdb.channels.getChannel(channel) - c.lobotomized = True - ircdb.channels.setChannel(channel, c) - irc.replySuccess() - lobotomize = wrap(lobotomize, ['op']) + If you have the #channel,op capability, this will "lobotomize" the + bot, making it silent and unanswering to all requests made in the + channel. is only necessary if the message isn't sent in + the channel itself. + """ + c = ircdb.channels.getChannel(channel) + c.lobotomized = True + ircdb.channels.setChannel(channel, c) + irc.replySuccess() + add = wrap(add, ['op']) - def unlobotomize(self, irc, msg, args, channel): - """[] + def remove(self, irc, msg, args, channel): + """[] - If you have the #channel,op capability, this will unlobotomize the bot, - making it respond to requests made in the channel again. - is only necessary if the message isn't sent in the channel - itself. - """ - c = ircdb.channels.getChannel(channel) - c.lobotomized = False - ircdb.channels.setChannel(channel, c) - irc.replySuccess() - unlobotomize = wrap(unlobotomize, ['op']) + If you have the #channel,op capability, this will unlobotomize the + bot, making it respond to requests made in the channel again. + is only necessary if the message isn't sent in the channel + itself. + """ + c = ircdb.channels.getChannel(channel) + c.lobotomized = False + ircdb.channels.setChannel(channel, c) + irc.replySuccess() + remove = wrap(remove, ['op']) - def permban(self, irc, msg, args, channel, banmask, expires): - """[] [] + def list(self, irc, msg, args): + """takes no arguments - If you have the #channel,op capability, this will effect a permanent - (persistent) ban from interacting with the bot on the given - (or the current hostmask associated with . Other plugins may - enforce this ban by actually banning users with matching hostmasks when - they join. is an optional argument specifying when (in - "seconds from now") the ban should expire; if none is given, the ban - will never automatically expire. is only necessary if the - message isn't sent in the channel itself. - """ - c = ircdb.channels.getChannel(channel) - c.addBan(banmask, expires) - ircdb.channels.setChannel(channel, c) - irc.replySuccess() - permban = wrap(permban, ['op', 'hostmask', additional('expiry', 0)]) + Returns the channels in which this bot is lobotomized. + """ + L = [] + for (channel, c) in ircdb.channels.iteritems(): + if c.lobotomized: + chancap = ircdb.makeChannelCapability(channel, 'op') + if ircdb.checkCapability(msg.prefix, 'admin') or \ + ircdb.checkCapability(msg.prefix, chancap) or \ + (channel in irc.state.channels and \ + msg.nick in irc.state.channels[channel].users): + L.append(channel) + if L: + L.sort() + s = format('I\'m currently lobotomized in %L.', L) + irc.reply(s) + else: + irc.reply('I\'m not currently lobotomized in any channels ' + 'that you\'re in.') + list = wrap(list) - def unpermban(self, irc, msg, args, channel, banmask): - """[] + class ban(callbacks.Commands): + def add(self, irc, msg, args, channel, banmask, expires): + """[] [] - If you have the #channel,op capability, this will remove the permanent - ban on . is only necessary if the message isn't - sent in the channel itself. - """ - c = ircdb.channels.getChannel(channel) - c.removeBan(banmask) - ircdb.channels.setChannel(channel, c) - irc.replySuccess() - unpermban = wrap(unpermban, ['op', 'hostmask']) + If you have the #channel,op capability, this will effect a + persistent ban from interacting with the bot on the given + (or the current hostmask associated with . Other + plugins may enforce this ban by actually banning users with + matching hostmasks when they join. is an optional + argument specifying when (in "seconds from now") the ban should + expire; if none is given, the ban will never automatically expire. + is only necessary if the message isn't sent in the + channel itself. + """ + c = ircdb.channels.getChannel(channel) + c.addBan(banmask, expires) + ircdb.channels.setChannel(channel, c) + irc.replySuccess() + add = wrap(add, ['op', 'hostmask', additional('expiry', 0)]) - def permbans(self, irc, msg, args, channel): - """[] + def remove(self, irc, msg, args, channel, banmask): + """[] - If you have the #channel,op capability, this will show you the - current bans on #channel. - """ - # XXX Add the expirations. - c = ircdb.channels.getChannel(channel) - if c.bans: - irc.reply(format('%L', map(utils.str.dqrepr, c.bans))) - else: - irc.reply('There are currently no permanent bans on %s' % channel) - permbans = wrap(permbans, ['op']) + If you have the #channel,op capability, this will remove the + persistent ban on . is only necessary if the + message isn't sent in the channel itself. + """ + c = ircdb.channels.getChannel(channel) + c.removeBan(banmask) + ircdb.channels.setChannel(channel, c) + irc.replySuccess() + remove = wrap(remove, ['op', 'hostmask']) - def ignore(self, irc, msg, args, channel, banmask, expires): - """[] [] + def list(self, irc, msg, args, channel): + """[] - If you have the #channel,op capability, this will set a permanent - (persistent) ignore on or the hostmask currently associated - with . is an optional argument specifying when (in - "seconds from now") the ignore will expire; if it isn't given, the - ignore will never automatically expire. is only necessary - if the message isn't sent in the channel itself. - """ - c = ircdb.channels.getChannel(channel) - c.addIgnore(banmask, expires) - ircdb.channels.setChannel(channel, c) - irc.replySuccess() - ignore = wrap(ignore, ['op', 'hostmask', additional('expiry', 0)]) + If you have the #channel,op capability, this will show you the + current bans on #channel. + """ + # XXX Add the expirations. + c = ircdb.channels.getChannel(channel) + if c.bans: + irc.reply(format('%L', map(utils.str.dqrepr, c.bans))) + else: + irc.reply(format('There are no persistent bans on %s.', + channel)) + list = wrap(list, ['op']) - def unignore(self, irc, msg, args, channel, banmask): - """[] + class ignore(callbacks.Commands): + def add(self, irc, msg, args, channel, banmask, expires): + """[] [] - If you have the #channel,op capability, this will remove the permanent - ignore on in the channel. is only necessary if the - message isn't sent in the channel itself. - """ - c = ircdb.channels.getChannel(channel) - c.removeIgnore(banmask) - ircdb.channels.setChannel(channel, c) - irc.replySuccess() - unignore = wrap(unignore, ['op', 'hostmask']) + If you have the #channel,op capability, this will set a persistent + ignore on or the hostmask currently + associated with . is an optional argument + specifying when (in "seconds from now") the ignore will expire; if + it isn't given, the ignore will never automatically expire. + is only necessary if the message isn't sent in the + channel itself. + """ + c = ircdb.channels.getChannel(channel) + c.addIgnore(banmask, expires) + ircdb.channels.setChannel(channel, c) + irc.replySuccess() + add = wrap(add, ['op', 'hostmask', additional('expiry', 0)]) - def ignores(self, irc, msg, args, channel): - """[] + def remove(self, irc, msg, args, channel, banmask): + """[] - Lists the hostmasks that the bot is ignoring on the given channel. - is only necessary if the message isn't sent in the channel - itself. - """ - # XXX Add the expirations. - c = ircdb.channels.getChannel(channel) - if len(c.ignores) == 0: - s = format('I\'m not currently ignoring any hostmasks in %q', - channel) - irc.reply(s) - else: - L = sorted(c.ignores) - irc.reply(utils.str.commaAndify(map(repr, L))) - ignores = wrap(ignores, ['op']) + If you have the #channel,op capability, this will remove the + persistent ignore on in the channel. is only + necessary if the message isn't sent in the channel itself. + """ + c = ircdb.channels.getChannel(channel) + c.removeIgnore(banmask) + ircdb.channels.setChannel(channel, c) + irc.replySuccess() + remove = wrap(remove, ['op', 'hostmask']) - def addcapability(self, irc, msg, args, channel, user, capabilities): - """[] [ ...] + def list(self, irc, msg, args, channel): + """[] - If you have the #channel,op capability, this will give the user - (or the user to whom maps) - the capability in the channel. is only necessary - if the message isn't sent in the channel itself. - """ - for c in capabilities.split(): - c = ircdb.makeChannelCapability(channel, c) - user.addCapability(c) - ircdb.users.setUser(user) - irc.replySuccess() - addcapability = wrap(addcapability, ['op', 'otherUser', 'capability']) + Lists the hostmasks that the bot is ignoring on the given channel. + is only necessary if the message isn't sent in the + channel itself. + """ + # XXX Add the expirations. + c = ircdb.channels.getChannel(channel) + if len(c.ignores) == 0: + s = format('I\'m not currently ignoring any hostmasks in %q', + channel) + irc.reply(s) + else: + L = sorted(c.ignores) + irc.reply(utils.str.commaAndify(map(repr, L))) + list = wrap(list, ['op']) - def removecapability(self, irc, msg, args, channel, user, capabilities): - """[] [ ...] + class capability(callbacks.Commands): + def add(self, irc, msg, args, channel, user, capabilities): + """[] [ ...] - 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. - """ - fail = [] - for c in capabilities.split(): - cap = ircdb.makeChannelCapability(channel, c) - try: - user.removeCapability(cap) - except KeyError: - fail.append(c) - ircdb.users.setUser(user) - if fail: - s = 'capability' - if len(fail) > 1: - s = utils.str.pluralize(s) - irc.error(format('That user didn\'t have the %L %s.', fail, s), - Raise=True) - irc.replySuccess() - removecapability = wrap(removecapability,['op', 'otherUser', 'capability']) + If you have the #channel,op capability, this will give the user + (or the user to whom maps) + the capability in the channel. is only + necessary if the message isn't sent in the channel itself. + """ + for c in capabilities.split(): + c = ircdb.makeChannelCapability(channel, c) + user.addCapability(c) + ircdb.users.setUser(user) + irc.replySuccess() + add = wrap(add, ['op', 'otherUser', 'capability']) - # XXX This needs to be fix0red to be like Owner.defaultcapability. Or - # something else. This is a horrible interface. - def setdefaultcapability(self, irc, msg, args, channel, v): - """[] {True|False} + def remove(self, irc, msg, args, channel, user, capabilities): + """[] [ ...] - If you have the #channel,op capability, this will set the default - response to non-power-related (that is, not {op, halfop, voice} - capabilities to be the value you give. is only necessary if - the message isn't sent in the channel itself. - """ - c = ircdb.channels.getChannel(channel) - if v: - c.setDefaultCapability(True) - else: - c.setDefaultCapability(False) - ircdb.channels.setChannel(channel, c) - irc.replySuccess() - setdefaultcapability = wrap(setdefaultcapability, ['op', 'boolean']) + 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. + """ + fail = [] + for c in capabilities.split(): + cap = ircdb.makeChannelCapability(channel, c) + try: + user.removeCapability(cap) + except KeyError: + fail.append(c) + ircdb.users.setUser(user) + if fail: + s = 'capability' + if len(fail) > 1: + s = utils.str.pluralize(s) + irc.error(format('That user didn\'t have the %L %s.', fail, s), + Raise=True) + irc.replySuccess() + remove = wrap(remove, ['op', 'otherUser', 'capability']) - def setcapability(self, irc, msg, args, channel, capabilities): - """[] [ ...] + # XXX This needs to be fix0red to be like Owner.defaultcapability. Or + # something else. This is a horrible interface. + def setdefault(self, irc, msg, args, channel, v): + """[] {True|False} - 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. - """ - chan = ircdb.channels.getChannel(channel) - for c in capabilities: - chan.addCapability(c) - ircdb.channels.setChannel(channel, chan) - irc.replySuccess() - setcapability = wrap(setcapability, ['op', many('capability')]) + If you have the #channel,op capability, this will set the default + response to non-power-related (that is, not {op, halfop, voice} + capabilities to be the value you give. is only necessary + if the message isn't sent in the channel itself. + """ + c = ircdb.channels.getChannel(channel) + if v: + c.setDefaultCapability(True) + else: + c.setDefaultCapability(False) + ircdb.channels.setChannel(channel, c) + irc.replySuccess() + setdefault = wrap(setdefault, ['op', 'boolean']) - def unsetcapability(self, irc, msg, args, channel, capabilities): - """[] [ ...] + def set(self, irc, msg, args, channel, capabilities): + """[] [ ...] - 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. - """ - chan = ircdb.channels.getChannel(channel) - fail = [] - for c in capabilities: - try: - chan.removeCapability(c) - except KeyError: - fail.append(c) - ircdb.channels.setChannel(channel, chan) - if fail: - s = 'capability' - if len(fail) > 1: - s = utils.str.pluralize(s) - irc.error(format('I do not know about the %L %s.', fail, s), - Raise=True) - irc.replySuccess() - unsetcapability = wrap(unsetcapability, ['op', many('capability')]) + 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. + """ + chan = ircdb.channels.getChannel(channel) + for c in capabilities: + chan.addCapability(c) + ircdb.channels.setChannel(channel, chan) + irc.replySuccess() + set = wrap(set, ['op', many('capability')]) - def capabilities(self, irc, msg, args, channel): - """[] + def unset(self, irc, msg, args, channel, capabilities): + """[] [ ...] - Returns the capabilities present on the . is only - necessary if the message isn't sent in the channel itself. - """ - c = ircdb.channels.getChannel(channel) - L = sorted(c.capabilities) - irc.reply(' '.join(L)) - capabilities = wrap(capabilities, ['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. + """ + chan = ircdb.channels.getChannel(channel) + fail = [] + for c in capabilities: + try: + chan.removeCapability(c) + except KeyError: + fail.append(c) + ircdb.channels.setChannel(channel, chan) + if fail: + s = 'capability' + if len(fail) > 1: + s = utils.str.pluralize(s) + irc.error(format('I do not know about the %L %s.', fail, s), + Raise=True) + irc.replySuccess() + unset = wrap(unset, ['op', many('capability')]) + + def list(self, irc, msg, args, channel): + """[] + + Returns the capabilities present on the . is + only necessary if the message isn't sent in the channel itself. + """ + c = ircdb.channels.getChannel(channel) + L = sorted(c.capabilities) + irc.reply(' '.join(L)) + list = wrap(list, ['channel']) def disable(self, irc, msg, args, channel, plugin, command): """[] [] [] @@ -737,22 +766,6 @@ class Channel(callbacks.Plugin): optional(('plugin', False)), additional('commandName')]) - def lobotomies(self, irc, msg, args): - """takes no arguments - - Returns the channels in which this bot is lobotomized. - """ - L = [] - for (channel, c) in ircdb.channels.iteritems(): - if c.lobotomized: - L.append(channel) - if L: - L.sort() - s = format('I\'m currently lobotomized in %L.', L) - irc.reply(s) - else: - irc.reply('I\'m not currently lobotomized in any channels.') - def nicks(self, irc, msg, args, channel): """[] diff --git a/plugins/Channel/test.py b/plugins/Channel/test.py index 337b49a20..ca98fa265 100644 --- a/plugins/Channel/test.py +++ b/plugins/Channel/test.py @@ -42,7 +42,7 @@ class ChannelTestCase(ChannelPluginTestCase): self.irc.state.channels[self.channel].addUser('bar') def testLobotomies(self): - self.assertRegexp('lobotomies', 'not.*any') + self.assertRegexp('lobotomy list', 'not.*any') ## def testCapabilities(self): ## self.prefix = 'foo!bar@baz' @@ -59,29 +59,29 @@ class ChannelTestCase(ChannelPluginTestCase): ## self.assertResponse('user capabilities foo', '[]') def testCapabilities(self): - self.assertNotError('channel capabilities') - 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') + self.assertNotError('channel capability list') + self.assertNotError('channel capability set -foo') + self.assertNotError('channel capability unset -foo') + self.assertError('channel capability unset -foo') + self.assertNotError('channel capability set -foo bar baz') + self.assertRegexp('channel capability list', 'baz') + self.assertNotError('channel capability unset -foo baz') + self.assertError('channel capability unset baz') def testEnableDisable(self): - self.assertNotRegexp('channel capabilities', '-Channel') + self.assertNotRegexp('channel capability list', '-Channel') self.assertError('channel enable channel') self.assertNotError('channel disable channel') - self.assertRegexp('channel capabilities', '-Channel') + self.assertRegexp('channel capability list', '-Channel') self.assertNotError('channel enable channel') - self.assertNotRegexp('channel capabilities', '-Channel') + self.assertNotRegexp('channel capability list', '-Channel') self.assertNotError('channel disable channel nicks') - self.assertRegexp('channel capabilities', '-Channel.nicks') + self.assertRegexp('channel capability list', '-Channel.nicks') self.assertNotError('channel enable channel nicks') - self.assertNotRegexp('channel capabilities', '-Channel.nicks') - self.assertNotRegexp('channel capabilities', 'nicks') + self.assertNotRegexp('channel capability list', '-Channel.nicks') + self.assertNotRegexp('channel capability list', 'nicks') self.assertNotError('channel disable nicks') - self.assertRegexp('channel capabilities', 'nicks') + self.assertRegexp('channel capability list', 'nicks') self.assertNotError('channel enable nicks') self.assertError('channel disable invalidPlugin') self.assertError('channel disable channel invalidCommand') @@ -167,24 +167,24 @@ class ChannelTestCase(ChannelPluginTestCase): ## self.assertNotRegexp('kban foobar time', 'ValueError') ## self.assertError('kban %s' % self.irc.nick) - def testPermban(self): - self.assertNotError('permban foo!bar@baz') - self.assertNotError('unpermban foo!bar@baz') + def testBan(self): + self.assertNotError('ban add foo!bar@baz') + self.assertNotError('ban remove foo!bar@baz') orig = conf.supybot.protocols.irc.strictRfc() try: conf.supybot.protocols.irc.strictRfc.setValue(True) # something wonky is going on here. irc.error (src/Channel.py|449) # is being called but the assert is failing - self.assertError('permban not!a.hostmask') - self.assertNotRegexp('permban not!a.hostmask', 'KeyError') + self.assertError('ban add not!a.hostmask') + self.assertNotRegexp('ban add not!a.hostmask', 'KeyError') finally: conf.supybot.protocols.irc.strictRfc.setValue(orig) def testIgnore(self): - self.assertNotError('Channel ignore foo!bar@baz') - self.assertResponse('Channel ignores', "'foo!bar@baz'") - self.assertNotError('Channel unignore foo!bar@baz') - self.assertError('permban not!a.hostmask') + self.assertNotError('channel ignore add foo!bar@baz') + self.assertResponse('channel ignore list', "'foo!bar@baz'") + self.assertNotError('channel ignore remove foo!bar@baz') + self.assertError('ban add not!a.hostmask') # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: