From d91cc33c58eb529eb01f3b8c83f70ebb4bc9d623 Mon Sep 17 00:00:00 2001 From: James Vega Date: Tue, 9 Dec 2003 14:05:32 +0000 Subject: [PATCH] Added Topic.reorder --- plugins/Topic.py | 36 ++++++++++++++++++++++++++++++++++++ test/test_Topic.py | 8 ++++++++ 2 files changed, 44 insertions(+) diff --git a/plugins/Topic.py b/plugins/Topic.py index 69cc349c8..b177ee2f4 100644 --- a/plugins/Topic.py +++ b/plugins/Topic.py @@ -124,6 +124,42 @@ class Topic(callbacks.Privmsg, configurable.Mixin): irc.queueMsg(ircmsgs.topic(channel, newtopic)) shuffle = privmsgs.checkChannelCapability(shuffle, 'topic') + def reorder(self, irc, msg, args, channel): + """[] [ ...] + + Reorders the topics from in the order of the specified + arguments. is a one-based index into the topics. + is only necessary if the message isn't sent in the channel + itself. + """ + topics = self._splitTopic(irc.state.getTopic(channel), channel) + if topics: + num = len(topics) + order = ('',)*num + order = privmsgs.getArgs(args, required=num) + for i,p in enumerate(order): + try: + p = int(p) + if p > 0: + order[i] = p - 1 + elif p == 0: + irc.error(msg, '0 is not a valid topic number.') + return + else: + order[i] = num + p + except ValueError: + irc.error(msg, 'The positions must be valid integers.') + return + try: + newtopics = [topics[i] for i in order] + newtopic = self._joinTopic(newtopics, channel) + irc.queueMsg(ircmsgs.topic(channel, newtopic)) + except IndexError: + irc.error(msg, 'An invalid topic number was specified.') + else: + irc.error(msg, 'There are no topics to reorder.') + reorder = privmsgs.checkChannelCapability(reorder, 'topic') + def get(self, irc, msg, args, channel): """[] diff --git a/test/test_Topic.py b/test/test_Topic.py index ebfcd188f..873ea9b07 100644 --- a/test/test_Topic.py +++ b/test/test_Topic.py @@ -86,6 +86,14 @@ class TopicTestCase(ChannelPluginTestCase, PluginDocumentation): m = self.getMsg('topic add bar') self.failUnless('<==>' in m.args[1]) + def testReorder(self): + _ = self.getMsg('topic add foo') + _ = self.getMsg('topic add bar') + _ = self.getMsg('topic add baz') + self.assertHelp('topic reorder') + self.assertRegexp('topic reorder 2 1 3', r'bar.*foo.*baz') + self.assertRegexp('topic reorder 3 -2 1', r'baz.*foo.*bar') + self.assertError('topic reorder 0 1 2') # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: