Make it so that ACTIONs don't get added as factoids

This commit is contained in:
Daniel DiPaolo 2004-01-11 23:22:59 +00:00
parent 13e0447ea5
commit 9d7c1a64c2
2 changed files with 18 additions and 1 deletions

View File

@ -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):
"""<takes no arguments>
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:

View File

@ -76,6 +76,8 @@ if sqlite is not None:
# Check substitution
self.assertNotError('who is <reply>$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