From 9d7c1a64c28f5ac0129f601137446c78bf40d0dc Mon Sep 17 00:00:00 2001 From: Daniel DiPaolo Date: Sun, 11 Jan 2004 23:22:59 +0000 Subject: [PATCH] Make it so that ACTIONs don't get added as factoids --- plugins/MoobotFactoids.py | 17 ++++++++++++++++- test/test_MoobotFactoids.py | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/MoobotFactoids.py b/plugins/MoobotFactoids.py index fe2360f67..8640727f0 100644 --- a/plugins/MoobotFactoids.py +++ b/plugins/MoobotFactoids.py @@ -202,6 +202,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): (fact, key) = cursor.fetchone() irc.reply("%r is %r" % (key, fact)) + def invalidCommand(self, irc, msg, tokens): key = ' '.join(tokens) key = key.rstrip('?!') @@ -231,7 +232,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): return True def addFactoid(self, irc, msg, match): - r"^(.+?)\s+(?:is|_is_)\s+(.+)" + r"^(?!\x01)(.+?)\s+(?:is|_is_)\s+(.+)" # Check and see if there is a command that matches this that didn't # get caught due to nesting # cb = callbacks.findCallbackForCommand(irc, msg) @@ -658,6 +659,20 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp): db.commit() irc.replySuccess() + def randomfactoid(self, irc, msg, args): + """ + + Displays a random factoid (along with its key) from the database. + """ + cursor = self.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.') + return + (fact, key) = cursor.fetchone() + irc.reply(msg, "Random factoid: %r is %r" % (key, fact)) + Class = MoobotFactoids # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/test/test_MoobotFactoids.py b/test/test_MoobotFactoids.py index 3e71a6a5f..0fe7c5bca 100644 --- a/test/test_MoobotFactoids.py +++ b/test/test_MoobotFactoids.py @@ -76,6 +76,8 @@ if sqlite is not None: # Check substitution self.assertNotError('who is $who') self.assertResponse('who', 'foo') + # Check that actions ("\x01ACTION...") don't match + self.assertNoResponse('\x01ACTION\x01 is doing something', 3) def testLiteral(self): self.assertError('literal moo') # no factoids yet