From e09f2ed81505939ceea21e74da6df62b2f0036cb Mon Sep 17 00:00:00 2001 From: GLolol Date: Fri, 26 Dec 2014 03:16:51 -0500 Subject: [PATCH 1/3] Topic: allow specifying a commalist of topic numbers in 'remove' --- plugins/Topic/plugin.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/Topic/plugin.py b/plugins/Topic/plugin.py index 1419d3cc8..b48ed7bf3 100644 --- a/plugins/Topic/plugin.py +++ b/plugins/Topic/plugin.py @@ -461,10 +461,10 @@ class Topic(callbacks.Plugin): rest(('topic', False))]) @internationalizeDocstring - def remove(self, irc, msg, args, channel, number): - """[] + def remove(self, irc, msg, args, channel, numbers): + """[] - Removes topic from the topic for Topics are + Removes topics from the topic for Topics are numbered starting from 1; you can also use negative indexes to refer to topics starting the from the end of the topic. is only necessary if the message isn't sent in the channel itself. @@ -473,9 +473,15 @@ class Topic(callbacks.Plugin): capabilities = self.registryValue('requireManageCapability') irc.errorNoCapability(capabilities, Raise=True) topics = self._splitTopic(irc.state.getTopic(channel), channel) - topic = topics.pop(number) + numbers = set(numbers) + for n in numbers: + # Equivalent of marking the topic for deletion; there's no + # simple, easy way of removing multiple items from a list. + # pop() will shift the indices after every run. + topics[n] = '' + topics = [topic for topic in topics if topic != ''] self._sendTopics(irc, channel, topics) - remove = wrap(remove, ['canChangeTopic', 'topicNumber']) + remove = wrap(remove, ['canChangeTopic', commalist('topicNumber')]) @internationalizeDocstring def lock(self, irc, msg, args, channel): From 465fe857bc6f2c07e3a49532a1259e8e0bb8cfc7 Mon Sep 17 00:00:00 2001 From: GLolol Date: Fri, 26 Dec 2014 17:23:05 -0500 Subject: [PATCH 2/3] Topic: switch 'remove' to many instead of commalist --- plugins/Topic/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/Topic/plugin.py b/plugins/Topic/plugin.py index b48ed7bf3..2c074272c 100644 --- a/plugins/Topic/plugin.py +++ b/plugins/Topic/plugin.py @@ -462,7 +462,7 @@ class Topic(callbacks.Plugin): @internationalizeDocstring def remove(self, irc, msg, args, channel, numbers): - """[] + """[] [ ...] Removes topics from the topic for Topics are numbered starting from 1; you can also use negative indexes to refer @@ -481,7 +481,7 @@ class Topic(callbacks.Plugin): topics[n] = '' topics = [topic for topic in topics if topic != ''] self._sendTopics(irc, channel, topics) - remove = wrap(remove, ['canChangeTopic', commalist('topicNumber')]) + remove = wrap(remove, ['canChangeTopic', many('topicNumber')]) @internationalizeDocstring def lock(self, irc, msg, args, channel): From b81bd2589e4977b7bbccb6d77f400f0cd4051070 Mon Sep 17 00:00:00 2001 From: GLolol Date: Fri, 26 Dec 2014 17:22:35 -0500 Subject: [PATCH 3/3] Topic: add test for removing multiple topics --- plugins/Topic/test.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/Topic/test.py b/plugins/Topic/test.py index 70f6cad8e..ac4d6f1a0 100644 --- a/plugins/Topic/test.py +++ b/plugins/Topic/test.py @@ -42,6 +42,17 @@ class TopicTestCase(ChannelPluginTestCase): self.assertNotError('topic remove 1') self.assertError('topic remove 1') + def testRemoveMultiple(self): + self.assertError('topic remove 1 2') + _ = self.getMsg('topic add foo') + _ = self.getMsg('topic add bar') + _ = self.getMsg('topic add baz') + _ = self.getMsg('topic add derp') + _ = self.getMsg('topic add cheese') + self.assertNotError('topic remove 1 2') + self.assertNotError('topic remove -1 1') + self.assertError('topic remove -99 1') + def testReplace(self): _ = self.getMsg('topic add foo') _ = self.getMsg('topic add bar')