mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Made to index from 1 instead of 0.
This commit is contained in:
parent
a8d7de246d
commit
746e292693
@ -163,7 +163,19 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
||||
necessary if the message isn't sent in the channel itself.
|
||||
"""
|
||||
channel = privmsgs.getChannel(msg, args)
|
||||
if args[-1].isdigit():
|
||||
number = args.pop()
|
||||
else:
|
||||
number = ''
|
||||
key = privmsgs.getArgs(args)
|
||||
if number:
|
||||
try:
|
||||
number = int(number)
|
||||
except ValueError:
|
||||
irc.error(msg, '%s is not a valid number.' % number)
|
||||
return
|
||||
else:
|
||||
number = 0
|
||||
db = self.getDb(channel)
|
||||
cursor = db.cursor()
|
||||
cursor.execute("""SELECT factoids.fact FROM factoids, keys WHERE
|
||||
@ -173,12 +185,19 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
||||
if cursor.rowcount == 0:
|
||||
irc.error(msg, 'No factoid matches that key.')
|
||||
else:
|
||||
if not number:
|
||||
factoids = []
|
||||
counter = 0
|
||||
counter = 1
|
||||
for result in cursor.fetchall():
|
||||
factoids.append('(#%s) %s' % (counter, result[0]))
|
||||
counter += 1
|
||||
irc.reply(msg, '%r could be %s' % (key, ', or '.join(factoids)))
|
||||
irc.reply(msg,'%r could be %s' % (key, ', or '.join(factoids)))
|
||||
else:
|
||||
try:
|
||||
irc.reply(msg, cursor.fetchall()[number-1])
|
||||
except IndexError:
|
||||
irc.error(msg, 'That\'s not a valid number for this key.')
|
||||
return
|
||||
|
||||
def lock(self, irc, msg, args):
|
||||
"""[<channel>] <key>
|
||||
@ -230,6 +249,10 @@ class Factoids(ChannelDBHandler, callbacks.Privmsg):
|
||||
channel = privmsgs.getChannel(msg, args)
|
||||
if args[-1].isdigit():
|
||||
number = int(args.pop())
|
||||
number -= 1
|
||||
if number < 0:
|
||||
irc.error(msg, 'Negative numbers aren\'t valid.')
|
||||
return
|
||||
elif args[-1] == '*':
|
||||
del args[-1]
|
||||
number = True
|
||||
|
@ -46,9 +46,10 @@ class FactoidsTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||
self.assertNotError('learn jemfinch as a crappy assembly programmer')
|
||||
self.assertRegexp('whatis jemfinch', r'.*primary author.*assembly')
|
||||
self.assertError('forget jemfinch')
|
||||
self.assertError('forget jemfinch 2')
|
||||
self.assertError('forget jemfinch 3')
|
||||
self.assertError('forget jemfinch 0')
|
||||
self.assertNotError('forget jemfinch 2')
|
||||
self.assertNotError('forget jemfinch 1')
|
||||
self.assertNotError('forget jemfinch 0')
|
||||
self.assertError('whatis jemfinch')
|
||||
self.assertError('factoidinfo jemfinch')
|
||||
|
||||
@ -58,8 +59,8 @@ class FactoidsTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||
self.assertNotError('learn foo bar as quux')
|
||||
self.assertRegexp('whatis foo bar', '.*baz.*quux')
|
||||
self.assertError('forget foo bar')
|
||||
self.assertNotError('forget foo bar 2')
|
||||
self.assertNotError('forget foo bar 1')
|
||||
self.assertNotError('forget foo bar 0')
|
||||
self.assertError('whatis foo bar')
|
||||
self.assertError('factoidinfo foo bar')
|
||||
|
||||
@ -79,6 +80,14 @@ class FactoidsTestCase(ChannelPluginTestCase, PluginDocumentation):
|
||||
self.assertRegexp('searchfactoids ke',
|
||||
'inkedmn.*strike|strike.*inkedmn')
|
||||
|
||||
def testNotZeroIndexed(self):
|
||||
self.assertNotError('learn foo as bar')
|
||||
self.assertNotRegexp('factoidinfo foo', '#0')
|
||||
self.assertNotRegexp('whatis foo', '#0')
|
||||
self.assertNotError('learn foo as baz')
|
||||
self.assertNotRegexp('factoidinfo foo', '#0')
|
||||
self.assertNotRegexp('whatis foo', '#0')
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user