Made indexing start from 1 instead of 0.

This commit is contained in:
Jeremy Fincher 2003-10-02 05:58:53 +00:00
parent 747b20d04e
commit a8d7de246d
2 changed files with 12 additions and 6 deletions

View File

@ -116,17 +116,19 @@ class Topic(callbacks.Privmsg):
index into the topics. <channel> is only necessary if the message index into the topics. <channel> is only necessary if the message
isn't sent in the channel itself. isn't sent in the channel itself.
""" """
i = privmsgs.getArgs(args) number = privmsgs.getArgs(args)
try: try:
i = int(i) number = int(number)
if number >= 0:
number -= 1
except ValueError: except ValueError:
irc.error(msg, 'The argument must be a valid integer.') irc.error(msg, 'The argument must be a valid integer.')
return return
topics = irc.state.getTopic(channel).split(self.topicSeparator) topics = irc.state.getTopic(channel).split(self.topicSeparator)
try: try:
irc.reply(msg, topics[i]) irc.reply(msg, topics[number])
except IndexError: except IndexError:
irc.error(msg, 'That\'s not a valid index.') irc.error(msg, 'That\'s not a valid topic.')
return return
gettopic = privmsgs.channel(gettopic) gettopic = privmsgs.channel(gettopic)
@ -142,6 +144,8 @@ class Topic(callbacks.Privmsg):
(number, regexp) = privmsgs.getArgs(args, needed=2) (number, regexp) = privmsgs.getArgs(args, needed=2)
try: try:
number = int(number) number = int(number)
if number >= 0:
number -= 1
except ValueError: except ValueError:
irc.error(msg, 'The <number> argument must be a number.') irc.error(msg, 'The <number> argument must be a number.')
return return
@ -187,6 +191,8 @@ class Topic(callbacks.Privmsg):
""" """
try: try:
number = int(privmsgs.getArgs(args)) number = int(privmsgs.getArgs(args))
if number >= 0:
number -= 1
except ValueError: except ValueError:
irc.error(msg, 'The argument must be a number.') irc.error(msg, 'The argument must be a number.')
return return

View File

@ -52,9 +52,9 @@ class TopicTestCase(PluginTestCase, PluginDocumentation):
_ = self.getMsg('addtopic #foo baz') _ = self.getMsg('addtopic #foo baz')
self.assertRegexp('changetopic #foo -1 s/baz/biff/', self.assertRegexp('changetopic #foo -1 s/baz/biff/',
r'foo.*bar.*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') r'foo.*baz.*biff')
self.assertRegexp('changetopic #foo 0 s/foo/bar/', self.assertRegexp('changetopic #foo 1 s/foo/bar/',
r'bar.*baz.*biff') r'bar.*baz.*biff')
self.assertRegexp('changetopic #foo -2 s/baz/bazz/', self.assertRegexp('changetopic #foo -2 s/baz/bazz/',
r'bar.*bazz.*biff') r'bar.*bazz.*biff')