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
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 <number> 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

View File

@ -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')