MoobotFactoids should be pretty dang close to finished now. Got the "_is_"

syntax working just fine.
This commit is contained in:
Daniel DiPaolo 2003-10-29 03:01:02 +00:00
parent 0c96bf73a7
commit f0b850118b
2 changed files with 22 additions and 4 deletions

View File

@ -186,6 +186,7 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
def invalidCommand(self, irc, msg, tokens): def invalidCommand(self, irc, msg, tokens):
key = ' '.join(tokens) key = ' '.join(tokens)
key = key.rstrip('?!')
if key.startswith('\x01'): if key.startswith('\x01'):
return return
# Check the factoid db for an appropriate reply # Check the factoid db for an appropriate reply
@ -211,7 +212,15 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
return True return True
def addFactoid(self, irc, msg, match): def addFactoid(self, irc, msg, match):
r"^(?!no\s+)(.+)\s+is\s+(?!also)(.+)" r"^(.+)\s+(?:is|_is_)\s+(.+)"
# First, check and see if the entire message matches a factoid key
cursor = self.db.cursor()
cursor.execute("""SELECT * FROM factoids WHERE key LIKE %s""",
match.group().rstrip('?! '))
if cursor.rowcount != 0:
self.invalidCommand(irc, msg, callbacks.tokenize(match.group()))
return
# Okay, we are REALLY adding stuff
# Must be registered! # Must be registered!
try: try:
id = ircdb.users.getUserId(msg.prefix) id = ircdb.users.getUserId(msg.prefix)
@ -219,13 +228,16 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
irc.error(msg, conf.replyNotRegistered) irc.error(msg, conf.replyNotRegistered)
return return
key, fact = match.groups() key, 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, fact = map(str.strip, match.group().split('_is_', 1))
# Strip the key of punctuation and spaces # Strip the key of punctuation and spaces
key = key.strip('?!') key = key.rstrip('?! ')
cursor = self.db.cursor()
# Check and make sure it's not in the DB already # Check and make sure it's not in the DB already
cursor.execute("""SELECT * FROM factoids WHERE key LIKE %s""", key) cursor.execute("""SELECT * FROM factoids WHERE key LIKE %s""", key)
if cursor.rowcount != 0: if cursor.rowcount != 0:
irc.error(msg, "Factoid %r already exists." % key) irc.error(msg, 'Factoid %r already exists.' % key)
return return
# Otherwise, # Otherwise,
cursor.execute("""INSERT INTO factoids VALUES cursor.execute("""INSERT INTO factoids VALUES

View File

@ -75,6 +75,12 @@ if sqlite is not None:
self.assertResponse('MOO', 'foo') self.assertResponse('MOO', 'foo')
self.assertResponse('mOo', 'foo') self.assertResponse('mOo', 'foo')
self.assertResponse('MoO', 'foo') self.assertResponse('MoO', 'foo')
# Check the "_is_" ability
self.assertNotError('delete moo')
self.assertNotError('moo _is_ <reply>foo')
self.assertResponse('moo', 'foo')
self.assertNotError('foo is bar _is_ baz')
self.assertResponse('foo is bar', 'foo is bar is baz')
def testFactinfo(self): def testFactinfo(self):
self.assertNotError('moo is <reply>foo') self.assertNotError('moo is <reply>foo')