From 97149b403a84ffde4b7fbc3abba58c8b77854c9e Mon Sep 17 00:00:00 2001 From: Daniel Folkinshteyn Date: Thu, 1 Apr 2010 00:51:25 -0400 Subject: [PATCH] make 'factoids info' include usage count in output. add test for same. --- plugins/Factoids/plugin.py | 9 +++++---- plugins/Factoids/test.py | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/Factoids/plugin.py b/plugins/Factoids/plugin.py index 37f655aba..88789445f 100644 --- a/plugins/Factoids/plugin.py +++ b/plugins/Factoids/plugin.py @@ -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', diff --git a/plugins/Factoids/test.py b/plugins/Factoids/test.py index ae35271a9..8127c801d 100644 --- a/plugins/Factoids/test.py +++ b/plugins/Factoids/test.py @@ -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')