From cc94948d1078b6b48b19387af7bba41fe588420a Mon Sep 17 00:00:00 2001 From: Daniel DiPaolo Date: Mon, 3 Nov 2003 06:25:02 +0000 Subject: [PATCH] Fixed greedniess of a few regexes and did some associated fixes. --- plugins/MoobotFactoids.py | 9 +++++++-- test/test_MoobotFactoids.py | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/MoobotFactoids.py b/plugins/MoobotFactoids.py index 6fb4953d4..999217424 100644 --- a/plugins/MoobotFactoids.py +++ b/plugins/MoobotFactoids.py @@ -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 diff --git a/test/test_MoobotFactoids.py b/test/test_MoobotFactoids.py index bbf9f9061..bb24a739f 100644 --- a/test/test_MoobotFactoids.py +++ b/test/test_MoobotFactoids.py @@ -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')