diff --git a/plugins/Topic.py b/plugins/Topic.py index fbf8a23fc..191bedab3 100644 --- a/plugins/Topic.py +++ b/plugins/Topic.py @@ -116,17 +116,19 @@ class Topic(callbacks.Privmsg): index into the topics. is only necessary if the message isn't sent in the channel itself. """ - i = privmsgs.getArgs(args) + number = privmsgs.getArgs(args) try: - i = int(i) + number = int(number) + if number >= 0: + number -= 1 except ValueError: irc.error(msg, 'The argument must be a valid integer.') return topics = irc.state.getTopic(channel).split(self.topicSeparator) try: - irc.reply(msg, topics[i]) + irc.reply(msg, topics[number]) except IndexError: - irc.error(msg, 'That\'s not a valid index.') + irc.error(msg, 'That\'s not a valid topic.') return gettopic = privmsgs.channel(gettopic) @@ -142,6 +144,8 @@ class Topic(callbacks.Privmsg): (number, regexp) = privmsgs.getArgs(args, needed=2) try: number = int(number) + if number >= 0: + number -= 1 except ValueError: irc.error(msg, 'The argument must be a number.') return @@ -187,6 +191,8 @@ class Topic(callbacks.Privmsg): """ try: number = int(privmsgs.getArgs(args)) + if number >= 0: + number -= 1 except ValueError: irc.error(msg, 'The argument must be a number.') return diff --git a/test/test_Topic.py b/test/test_Topic.py index bff35bbed..fadb4331c 100644 --- a/test/test_Topic.py +++ b/test/test_Topic.py @@ -52,9 +52,9 @@ class TopicTestCase(PluginTestCase, PluginDocumentation): _ = self.getMsg('addtopic #foo baz') self.assertRegexp('changetopic #foo -1 s/baz/biff/', r'foo.*bar.*biff') - self.assertRegexp('changetopic #foo 1 s/bar/baz/', + self.assertRegexp('changetopic #foo 2 s/bar/baz/', r'foo.*baz.*biff') - self.assertRegexp('changetopic #foo 0 s/foo/bar/', + self.assertRegexp('changetopic #foo 1 s/foo/bar/', r'bar.*baz.*biff') self.assertRegexp('changetopic #foo -2 s/baz/bazz/', r'bar.*bazz.*biff')