Fix bug #1093594, UnboundLocalError

This commit is contained in:
James Vega 2004-12-31 04:18:02 +00:00
parent a6a45f9dc3
commit a4545d45a7
2 changed files with 11 additions and 2 deletions

View File

@ -553,6 +553,9 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
isAre = None
else:
value = self.db.getAre(channel, key)
else:
self.log.debug('Returning early: Got a bad isAre value.')
return
except dbi.InvalidDBError, e:
self._error('Unable to access db: %s' % e)
return
@ -730,6 +733,11 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
r"^(.+?)\s+(?<!\\)(was|is|am|were|are)\s+(also\s+)?(.+?)[?!. ]*$"
(key, isAre, also, value) = match.groups()
key = key.replace('\\', '')
isAre = isAre.lower()
if isAre in ('was', 'is', 'am'):
isAre = 'is'
else:
isAre = 'are'
if key.lower() in ('where', 'what', 'who', 'wtf'):
# It's a question.
if msg.addressed or \
@ -739,10 +747,9 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
if not msg.addressed and \
not self.registryValue('unaddressed.snarfDefinitions'):
return
isAre = isAre.lower()
if self.added:
return
if isAre in ('was', 'is', 'am'):
if isAre == 'is':
if self.db.hasIs(dynamic.channel, key):
oldValue = self.db.getIs(dynamic.channel, key)
if oldValue.lower() == value.lower():

View File

@ -52,6 +52,7 @@ class InfobotTestCase(ChannelPluginTestCase):
m = self.getMsg('bar is at http://foo.com/')
self.failUnless(self._endRe.sub('', m.args[1]) in confirms)
self.assertRegexp('bar?', r'bar.*is.*http://foo.com/')
self.assertRegexp('what was bar?', r'http://foo.com/')
finally:
ibot.unaddressed.snarfDefinitions.setValue(learn)
ibot.unaddressed.answerQuestions.setValue(answer)
@ -87,6 +88,7 @@ class InfobotTestCase(ChannelPluginTestCase):
self.assertSnarfRegexp('bars?', 'bars.*are.*dirty')
self.assertSnarfNoResponse('bars are not dirty', 2)
self.assertSnarfNotRegexp('bars?', 'not')
self.assertSnarfRegexp('what were bars?', 'dirty')
finally:
ibot.unaddressed.snarfDefinitions.setValue(learn)
ibot.unaddressed.answerQuestions.setValue(answer)