diff --git a/plugins/Config/plugin.py b/plugins/Config/plugin.py index 80737ab94..167f98cd8 100644 --- a/plugins/Config/plugin.py +++ b/plugins/Config/plugin.py @@ -205,13 +205,13 @@ class Config(callbacks.Plugin): value = _('Global: %s; %s: %s') % (value, msg.args[0], s) if hasattr(group, 'value'): if not group._private: - irc.reply(value) + return (value, None) else: capability = getCapability(group._name) if ircdb.checkCapability(msg.prefix, capability): - irc.reply(value, private=True) + return (value, True) else: - irc.errorNoCapability(capability) + irc.errorNoCapability(capability, Raise=True) else: irc.error(_('That registry variable has no value. Use the list ' 'command in this plugin to see what variables are ' @@ -226,28 +226,42 @@ class Config(callbacks.Plugin): if ircdb.checkCapability(msg.prefix, capability): # I think callCommand catches exceptions here. Should it? group.set(value) - irc.replySuccess() else: - irc.errorNoCapability(capability) + irc.errorNoCapability(capability, Raise=True) @internationalizeDocstring - def channel(self, irc, msg, args, channel, group, value): + def channel(self, irc, msg, args, channels, group, value): """[] [] If is given, sets the channel configuration variable for to for . Otherwise, returns the current channel configuration value of . is only necessary if the - message isn't sent in the channel itself.""" + message isn't sent in the channel itself. More than one channel may + be given at once by separating them with commas.""" if not group.channelValue: irc.error(_('That configuration variable is not a channel-specific ' 'configuration variable.')) return - group = group.get(channel) if value is not None: - self._setValue(irc, msg, group, value) + for channel in channels: + assert irc.isChannel(channel) + self._setValue(irc, msg, group.get(channel), value) + irc.replySuccess() else: - self._getValue(irc, msg, group) - channel = wrap(channel, ['channel', 'settableConfigVar', + values = [] + private = None + for channel in channels: + (value, private_value) = self._getValue(irc, msg, group.get(channel)) + values.append(value) + if private_value: + private = True + if len(channels) > 1: + irc.reply('; '.join([ + '%s: %s' % (channel, value) + for value in values])) + else: + irc.reply(values[0]) + channel = wrap(channel, ['channels', 'settableConfigVar', additional('text')]) @internationalizeDocstring @@ -260,8 +274,10 @@ class Config(callbacks.Plugin): """ if value is not None: self._setValue(irc, msg, group, value) + irc.replySuccess() else: - self._getValue(irc, msg, group, addChannel=group.channelValue) + (value, private) = self._getValue(irc, msg, group, addChannel=group.channelValue) + irc.reply(value, private=private) config = wrap(config, ['settableConfigVar', additional('text')]) @internationalizeDocstring diff --git a/plugins/Config/test.py b/plugins/Config/test.py index 7e9195d04..7ccd11765 100644 --- a/plugins/Config/test.py +++ b/plugins/Config/test.py @@ -167,5 +167,20 @@ class ConfigTestCase(ChannelPluginTestCase): self.assertResponse('config plugins.Config.%s' % var_name, 'Global: 0; #test: 1') + def testChannel(self): + self.assertResponse('config reply.whenAddressedBy.strings ^', + 'The operation succeeded.') + self.assertResponse('config channel reply.whenAddressedBy.strings @', + 'The operation succeeded.') + self.assertResponse('config channel reply.whenAddressedBy.strings', '@') + self.assertNotError('config channel reply.whenAddressedBy.strings $') + self.assertResponse('config channel #testchan1 reply.whenAddressedBy.strings', '^') + self.assertResponse('config channel #testchan2 reply.whenAddressedBy.strings', '^') + self.assertNotError('config channel #testchan1,#testchan2 reply.whenAddressedBy.strings .') + self.assertResponse('config channel reply.whenAddressedBy.strings', '$') + self.assertResponse('config channel #testchan1 reply.whenAddressedBy.strings', '.') + self.assertResponse('config channel #testchan2 reply.whenAddressedBy.strings', '.') + + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/src/commands.py b/src/commands.py index 8596ae0fa..0582bf7b4 100644 --- a/src/commands.py +++ b/src/commands.py @@ -488,6 +488,16 @@ def getChannel(irc, msg, args, state): state.channel = channel state.args.append(channel) +def getChannels(irc, msg, args, state): + if args and all(map(irc.isChannel, args[0].split(','))): + channels = args.pop(0).split(',') + elif irc.isChannel(msg.args[0]): + channels = [msg.args[0]] + else: + state.log.debug('Raising ArgumentError because there is no channel.') + raise callbacks.ArgumentError + state.args.append(channels) + def getChannelDb(irc, msg, args, state, **kwargs): channelSpecific = conf.supybot.databases.plugins.channelSpecific try: @@ -730,6 +740,7 @@ wrappers = ircutils.IrcDict({ 'isGranted': getHaveHalfopPlus, # Backward compatibility 'capability': getSomethingNoSpaces, 'channel': getChannel, + 'channels': getChannels, 'channelOrGlobal': getChannelOrGlobal, 'channelDb': getChannelDb, 'checkCapability': checkCapability,