From 3128255c0f664f0d2375c9502d2cf44d2e9dd01b Mon Sep 17 00:00:00 2001 From: James Vega Date: Tue, 17 Feb 2004 21:41:52 +0000 Subject: [PATCH] MoobotFactoids.randomfactoid must've felt so lonely not having anyone to test that he was ok. Add that to him having an unwanted msg lying around, and he must've been quite sad. --- plugins/MoobotFactoids.py | 7 ++++--- test/test_MoobotFactoids.py | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/MoobotFactoids.py b/plugins/MoobotFactoids.py index d27abbefb..7283b5469 100644 --- a/plugins/MoobotFactoids.py +++ b/plugins/MoobotFactoids.py @@ -681,14 +681,15 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): Displays a random factoid (along with its key) from the database. """ - cursor = self.db.cursor() + db = self.dbHandler.getDb() + cursor = db.cursor() cursor.execute("""SELECT fact, key FROM factoids ORDER BY random() LIMIT 1""") if cursor.rowcount == 0: - irc.error(msg, 'No factoids in the database.') + irc.error('No factoids in the database.') return (fact, key) = cursor.fetchone() - irc.reply(msg, 'Random factoid: "%s" is "%s"' % (key, fact)) + irc.reply('Random factoid: "%s" is "%s"' % (key, fact)) Class = MoobotFactoids diff --git a/test/test_MoobotFactoids.py b/test/test_MoobotFactoids.py index 6a8f82424..b0c6ce8d4 100644 --- a/test/test_MoobotFactoids.py +++ b/test/test_MoobotFactoids.py @@ -339,6 +339,11 @@ if sqlite is not None: MFconf.showFactoidIfOnlyOneMatch.setValue(False) self.assertResponse('listkeys foo', 'Key search for "foo" ' '(1 found): "foo"') + + def testRandomFactoid(self): + self.assertNotError('foo is bar') + self.assertNotError('bar is baz') + self.assertRegexp('randomfactoid', r'bar|baz') # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: