make 'factoids info' include usage count in output. add test for same.

This commit is contained in:
Daniel Folkinshteyn 2010-04-01 00:51:25 -04:00
parent 32c718ca66
commit 97149b403a
2 changed files with 11 additions and 4 deletions

View File

@ -424,18 +424,19 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
irc.error('No factoid matches that key.')
return
(id, locked) = map(int, results[0])
cursor.execute("""SELECT added_by, added_at FROM factoids
cursor.execute("""SELECT added_by, added_at, usage_count FROM factoids
WHERE key_id=?
ORDER BY id""", (id,))
factoids = cursor.fetchall()
L = []
counter = 0
for (added_by, added_at) in factoids:
for (added_by, added_at, usage_count) in factoids:
counter += 1
added_at = time.strftime(conf.supybot.reply.format.time(),
time.localtime(int(added_at)))
L.append(format('#%i was added by %s at %s',
counter, added_by, added_at))
L.append(format('#%i was added by %s at %s, and has been recalled '
'%n',
counter, added_by, added_at, (usage_count, 'time')))
factoids = '; '.join(L)
s = format('Key %q is %s and has %n associated with it: %s',
key, locked and 'locked' or 'not locked',

View File

@ -125,6 +125,12 @@ class FactoidsTestCase(ChannelPluginTestCase):
self.assertNotError('learn foo as bar')
self.assertNotRegexp('info foo', '2 factoids')
def testInfoUsageCount(self):
self.assertNotError('learn moo as cow')
self.assertRegexp('info moo', 'recalled 0 times')
self.assertNotError('whatis moo')
self.assertRegexp('info moo', 'recalled 1 time')
def testLearnSeparator(self):
self.assertError('learn foo is bar')
self.assertNotError('learn foo as bar')