Fixed greedniess of a few regexes and did some associated fixes.

This commit is contained in:
Daniel DiPaolo 2003-11-03 06:25:02 +00:00
parent bf12760108
commit cc94948d10
2 changed files with 13 additions and 2 deletions

View File

@ -284,7 +284,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
irc.reply(msg, conf.replySuccess)
def augmentFactoid(self, irc, msg, match):
r"(.+) is also (.+)"
r"(.+?) is also (.+)"
# Must be registered!
try:
id = ircdb.users.getUserId(msg.prefix)
@ -314,7 +314,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
irc.reply(msg, conf.replySuccess)
def replaceFactoid(self, irc, msg, match):
r"^no,?\s+(.+)\s+is\s+(.+)"
r"^no,?\s+(.+?)\s+is\s+(.+)"
# Must be registered!
try:
id = ircdb.users.getUserId(msg.prefix)
@ -322,6 +322,11 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
irc.error(msg, conf.replyNotRegistered)
return
key, new_fact = match.groups()
# These are okay, unless there's an _is_ in there, in which case
# we split on the leftmost one.
if '_is_' in match.group():
key, new_fact = map(str.strip, match.group().split('_is_', 1))
key = key.split(' ', 1)[1] # Take out everything to first space
cursor = self.db.cursor()
# Check and make sure it's in the DB
cursor.execute("""SELECT locked_at, fact FROM factoids

View File

@ -193,6 +193,9 @@ if sqlite is not None:
self.assertNotError('moo is foo')
self.assertNotError('moo is also bar')
self.assertResponse('moo', 'moo is foo, or bar')
self.assertNotError('moo is bar _is_ foo')
self.assertNotError('moo is bar is also foo')
self.assertResponse('moo is bar', 'moo is bar is foo, or foo')
def testReplaceFactoid(self):
self.assertNotError('moo is foo')
@ -202,6 +205,9 @@ if sqlite is not None:
self.assertResponse('moo', 'moo is baz')
self.assertNotError('lock moo')
self.assertError('no moo is qux')
self.assertNotError('foo is bar _is_ foo')
self.assertNotError('no foo is bar _is_ baz')
self.assertResponse('foo is bar', 'foo is bar is baz')
def testRegexpNotCalledIfAlreadyHandled(self):
self.assertResponse('echo foo is bar', 'foo is bar')