Made MoobotFactoids case insensitive, and added tests to make sure that

case-insensitivity works.
This commit is contained in:
Daniel DiPaolo 2003-10-24 01:03:18 +00:00
parent f0574da59a
commit 1b25a207bf
2 changed files with 14 additions and 10 deletions

View File

@ -205,7 +205,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
return
# Check the factoid db for an appropriate reply
cursor = self.db.cursor()
cursor.execute("""SELECT fact FROM factoids WHERE key = %s""", key)
cursor.execute("""SELECT fact FROM factoids WHERE key LIKE %s""", key)
if cursor.rowcount == 0:
text = self._getDunno(msg.nick)
irc.reply(msg, text, prefixName=False)
@ -249,7 +249,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
key, fact = match.groups()
cursor = self.db.cursor()
# Check and make sure it's not in the DB already
cursor.execute("""SELECT * FROM factoids WHERE key = %s""", key)
cursor.execute("""SELECT * FROM factoids WHERE key LIKE %s""", key)
if cursor.rowcount != 0:
irc.error(msg, "Factoid '%s' already exists." % key)
return
@ -273,7 +273,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
cursor = self.db.cursor()
# Check and make sure it's in the DB
cursor.execute("""SELECT locked_at, fact FROM factoids
WHERE key = %s""", key)
WHERE key LIKE %s""", key)
if cursor.rowcount == 0:
irc.error(msg, "Factoid '%s' not found." % key)
return
@ -308,7 +308,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
cursor = self.db.cursor()
# Check and make sure it's in the DB
cursor.execute("""SELECT locked_at, fact FROM factoids
WHERE key = %s""", key)
WHERE key LIKE %s""", key)
if cursor.rowcount == 0:
irc.error(msg, "Factoid '%s' not found." % key)
return
@ -338,7 +338,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
cursor = self.db.cursor()
# Check and make sure it's in the DB
cursor.execute("""SELECT locked_at, fact FROM factoids
WHERE key = %s""", key)
WHERE key LIKE %s""", key)
if cursor.rowcount == 0:
irc.error(msg, "Factoid '%s' not found." % key)
return
@ -367,7 +367,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
"""
key = privmsgs.getArgs(args, needed=1)
cursor = self.db.cursor()
cursor.execute("""SELECT fact FROM factoids WHERE key = %s""", key)
cursor.execute("""SELECT fact FROM factoids WHERE key LIKE %s""", key)
if cursor.rowcount == 0:
irc.error(msg, "No such factoid: %s" % key)
return
@ -388,7 +388,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
cursor.execute("""SELECT created_by, created_at, modified_by,
modified_at, last_requested_by, last_requested_at,
requested_count, locked_at FROM
factoids WHERE key = %s""", key)
factoids WHERE key LIKE %s""", key)
if cursor.rowcount == 0:
irc.error(msg, "No such factoid: %s" % key)
return
@ -432,7 +432,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
key = privmsgs.getArgs(args, needed=1)
cursor = self.db.cursor()
cursor.execute("""SELECT created_by, locked_at FROM factoids
WHERE key = %s""", key)
WHERE key LIKE %s""", key)
if cursor.rowcount == 0:
irc.error(msg, "No such factoid: %s" % key)
return
@ -559,7 +559,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
key = privmsgs.getArgs(args, needed=1)
cursor = self.db.cursor()
cursor.execute("""SELECT key, locked_at FROM factoids
WHERE key = %s""", key)
WHERE key LIKE %s""", key)
if cursor.rowcount == 0:
irc.error(msg, "No such factoid: %s" % key)
return

View File

@ -66,6 +66,10 @@ if sqlite is not None:
# Test and make sure it's parsing
self.assertNotError('moo4 is <reply>(1|2|3)')
self.assertRegexp('moo4', '^(1|2|3)$')
# Check case-insensitivity
self.assertResponse('MOO', 'foo')
self.assertResponse('mOo', 'foo')
self.assertResponse('MoO', 'foo')
def testFactinfo(self):
self.assertNotError('moo is <reply>foo')
@ -206,7 +210,7 @@ if sqlite is not None:
def testDunnoAdd(self):
self.assertNotError('dunnoadd moo')
self.assertResponse('asdfagagfosdfk', 'moo (#1)')
self.assertResponse('asdfagagfosdfk', 'moo')
def testDunnoRemove(self):
self.assertNotError('dunnoadd moo')