mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-06 17:44:09 +01:00
Better emulation of Infobot wrt overwriting factoids and missing factoids.
This commit is contained in:
parent
82a055c466
commit
cb42006490
@ -503,16 +503,25 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
|
|
||||||
def confirm(self, irc=None, msg=None):
|
def confirm(self, irc=None, msg=None):
|
||||||
if self.registryValue('personality'):
|
if self.registryValue('personality'):
|
||||||
self.reply(self.db.getConfirm(), irc=irc, msg=msg)
|
s = self.db.getConfirm()
|
||||||
else:
|
else:
|
||||||
assert self.irc is not None
|
s = conf.supybot.replies.success()
|
||||||
self.reply(conf.supybot.replies.success())
|
self.reply(s, irc=irc, msg=msg)
|
||||||
|
|
||||||
|
def missing(self, fact, irc=None, msg=None):
|
||||||
|
if msg is None:
|
||||||
|
assert self.msg is not None
|
||||||
|
msg = self.msg
|
||||||
|
self.reply('I didn\'t have anything matching %s, %s.' %
|
||||||
|
(utils.quoted(fact), msg.nick),
|
||||||
|
irc=irc, msg=msg)
|
||||||
|
|
||||||
def dunno(self, irc=None, msg=None):
|
def dunno(self, irc=None, msg=None):
|
||||||
if self.registryValue('personality'):
|
if self.registryValue('personality'):
|
||||||
self.reply(self.db.getDunno(), irc=irc, msg=msg)
|
s = self.db.getDunno()
|
||||||
else:
|
else:
|
||||||
self.reply(self.registryValue('boringDunno'), irc=irc, msg=msg)
|
s = self.registryValue('boringDunno')
|
||||||
|
self.reply(s, irc=irc, msg=msg)
|
||||||
|
|
||||||
def factoid(self, key, irc=None, msg=None, dunno=True, prepend='',
|
def factoid(self, key, irc=None, msg=None, dunno=True, prepend='',
|
||||||
isAre=None):
|
isAre=None):
|
||||||
@ -568,10 +577,16 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
s = prepend + s
|
s = prepend + s
|
||||||
self.reply(s, irc=irc, msg=msg)
|
self.reply(s, irc=irc, msg=msg)
|
||||||
|
|
||||||
def normalize(self, s):
|
_iAm = (re.compile(r'^i am ', re.I), '%s is ')
|
||||||
|
_my = (re.compile(r'^my ', re.I), '%s\'s ')
|
||||||
|
_your = (re.compile(r'^your ', re.I), '%s\'s ')
|
||||||
|
def normalize(self, s, bot, nick):
|
||||||
s = ircutils.stripFormatting(s)
|
s = ircutils.stripFormatting(s)
|
||||||
s = s.strip() # After stripFormatting for formatted spaces.
|
s = s.strip() # After stripFormatting for formatted spaces.
|
||||||
s = utils.normalizeWhitespace(s)
|
s = utils.normalizeWhitespace(s)
|
||||||
|
s = self._iAm[0].sub(self._iAm[1] % nick, s)
|
||||||
|
s = self._my[0].sub(self._my[1] % nick, s)
|
||||||
|
s = self._your[0].sub(self._your[1] % bot, s)
|
||||||
contractions = [('what\'s', 'what is'), ('where\'s', 'where is'),
|
contractions = [('what\'s', 'what is'), ('where\'s', 'where is'),
|
||||||
('who\'s', 'who is'), ('wtf\'s', 'wtf is'),]
|
('who\'s', 'who is'), ('wtf\'s', 'wtf is'),]
|
||||||
for (contraction, replacement) in contractions:
|
for (contraction, replacement) in contractions:
|
||||||
@ -593,7 +608,10 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
return
|
return
|
||||||
# For later dynamic scoping
|
# For later dynamic scoping
|
||||||
channel = plugins.getChannel(msg.args[0])
|
channel = plugins.getChannel(msg.args[0])
|
||||||
payload = self.normalize(msg.args[1])
|
s = callbacks.addressed(irc.nick, msg)
|
||||||
|
payload = self.normalize(s or msg.args[1], irc.nick, msg.nick)
|
||||||
|
if s:
|
||||||
|
msg.tag('addressed', payload)
|
||||||
msg = ircmsgs.IrcMsg(args=(msg.args[0], payload), msg=msg)
|
msg = ircmsgs.IrcMsg(args=(msg.args[0], payload), msg=msg)
|
||||||
self.__parent.doPrivmsg(irc, msg)
|
self.__parent.doPrivmsg(irc, msg)
|
||||||
finally:
|
finally:
|
||||||
@ -622,9 +640,8 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
pass
|
pass
|
||||||
if deleted:
|
if deleted:
|
||||||
self.confirm()
|
self.confirm()
|
||||||
else:
|
elif msg.addressed:
|
||||||
# XXX: Should this be genericified?
|
self.missing(fact, irc=irc, msg=msg)
|
||||||
self.reply('I\'ve never heard of %s, %s!' % (fact, msg.nick))
|
|
||||||
|
|
||||||
def doForce(self, irc, msg, match):
|
def doForce(self, irc, msg, match):
|
||||||
r"^no,\s+(\w+,\s+)?(.+?)\s+(?<!\\)(was|is|am|were|are)\s+(.+?)[?!. ]*$"
|
r"^no,\s+(\w+,\s+)?(.+?)\s+(?<!\\)(was|is|am|were|are)\s+(.+?)[?!. ]*$"
|
||||||
@ -647,18 +664,27 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
isAre = isAre.lower()
|
isAre = isAre.lower()
|
||||||
if self.added:
|
if self.added:
|
||||||
return
|
return
|
||||||
|
channel = dynamic.channel
|
||||||
if isAre in ('was', 'is', 'am'):
|
if isAre in ('was', 'is', 'am'):
|
||||||
if self.db.hasIs(dynamic.channel, key):
|
if self.db.hasIs(channel, key):
|
||||||
|
oldValue = self.db.getIs(channel, key)
|
||||||
|
if oldValue.lower() == value.lower():
|
||||||
|
self.reply('I already had it that way, %s.' % msg.nick)
|
||||||
|
return
|
||||||
self.log.debug('Forcing %s to %s.',
|
self.log.debug('Forcing %s to %s.',
|
||||||
utils.quoted(key), utils.quoted(value))
|
utils.quoted(key), utils.quoted(value))
|
||||||
self.added = True
|
self.added = True
|
||||||
self.db.setIs(dynamic.channel, key, value)
|
self.db.setIs(channel, key, value)
|
||||||
else:
|
else:
|
||||||
if self.db.hasAre(dynamic.channel, key):
|
if self.db.hasAre(channel, key):
|
||||||
|
oldValue = self.db.getAre(channel, key)
|
||||||
|
if oldValue.lower() == value.lower():
|
||||||
|
self.reply('I already had it that way, %s.' % msg.nick)
|
||||||
|
return
|
||||||
self.log.debug('Forcing %s to %s.',
|
self.log.debug('Forcing %s to %s.',
|
||||||
utils.quoted(key), utils.quoted(value))
|
utils.quoted(key), utils.quoted(value))
|
||||||
self.added = True
|
self.added = True
|
||||||
self.db.setAre(dynamic.channel, key, value)
|
self.db.setAre(channel, key, value)
|
||||||
self.confirm()
|
self.confirm()
|
||||||
|
|
||||||
def doChange(self, irc, msg, match):
|
def doChange(self, irc, msg, match):
|
||||||
@ -684,8 +710,7 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
if changed:
|
if changed:
|
||||||
self.confirm()
|
self.confirm()
|
||||||
else:
|
else:
|
||||||
# XXX: Should this be genericified?
|
self.missing(fact, irc=irc, msg=msg)
|
||||||
self.reply('I\'ve never heard of %s, %s!' % (fact, msg.nick))
|
|
||||||
|
|
||||||
def doUnknown(self, irc, msg, match):
|
def doUnknown(self, irc, msg, match):
|
||||||
r"^(.+?)\s*(\?[?!. ]*)?$"
|
r"^(.+?)\s*(\?[?!. ]*)?$"
|
||||||
@ -718,22 +743,18 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
return
|
return
|
||||||
if isAre in ('was', 'is', 'am'):
|
if isAre in ('was', 'is', 'am'):
|
||||||
if self.db.hasIs(dynamic.channel, key):
|
if self.db.hasIs(dynamic.channel, key):
|
||||||
|
oldValue = self.db.getIs(dynamic.channel, key)
|
||||||
|
if oldValue.lower() == value.lower():
|
||||||
|
self.reply('I already had it that way, %s.' % msg.nick)
|
||||||
|
return
|
||||||
if also:
|
if also:
|
||||||
self.log.debug('Adding %s to %s.',
|
self.log.debug('Adding %s to %s.',
|
||||||
utils.quoted(key), utils.quoted(value))
|
utils.quoted(key), utils.quoted(value))
|
||||||
value = '%s or %s' % (self.db.getIs(dynamic.channel, key),
|
value = '%s or %s' % (oldValue, value)
|
||||||
value)
|
|
||||||
elif not msg.addressed:
|
|
||||||
value = self.db.getIs(dynamic.channel, key)
|
|
||||||
if initialIs.get(key) != value:
|
|
||||||
self.reply('... but %s is %s, %s ...' %
|
|
||||||
(key, value, msg.nick), substitute=False)
|
|
||||||
return
|
|
||||||
elif msg.addressed:
|
elif msg.addressed:
|
||||||
value = self.db.getIs(dynamic.channel, key)
|
|
||||||
if initialIs.get(key) != value:
|
if initialIs.get(key) != value:
|
||||||
self.reply('But %s is %s, %s.' %
|
self.reply('... but %s is %s ...' %
|
||||||
(key, value, msg.nick), substitute=False)
|
(key, oldValue), substitute=False)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.log.debug('Already have a %s key.',
|
self.log.debug('Already have a %s key.',
|
||||||
@ -743,22 +764,18 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
self.db.setIs(dynamic.channel, key, value)
|
self.db.setIs(dynamic.channel, key, value)
|
||||||
else:
|
else:
|
||||||
if self.db.hasAre(dynamic.channel, key):
|
if self.db.hasAre(dynamic.channel, key):
|
||||||
|
oldValue = self.db.getAre(dynamic.channel, key)
|
||||||
|
if oldValue.lower() == value.lower():
|
||||||
|
self.reply('I already had it that way, %s.' % msg.nick)
|
||||||
|
return
|
||||||
if also:
|
if also:
|
||||||
self.log.debug('Adding %s to %s.',
|
self.log.debug('Adding %s to %s.',
|
||||||
utils.quoted(key), utils.quoted(value))
|
utils.quoted(key), utils.quoted(value))
|
||||||
value = '%s or %s' % (self.db.getAre(dynamic.channel, key),
|
value = '%s or %s' % (oldValue, value)
|
||||||
value)
|
|
||||||
elif not msg.addressed:
|
|
||||||
value = self.db.getAre(dynamic.channel, key)
|
|
||||||
if initialAre.get(key) != value:
|
|
||||||
self.reply('... but %s are %s, %s ...' %
|
|
||||||
(key, value, msg.nick), substitute=False)
|
|
||||||
return
|
|
||||||
elif msg.addressed:
|
elif msg.addressed:
|
||||||
value = self.db.getAre(dynamic.channel, key)
|
|
||||||
if initialAre.get(key) != value:
|
if initialAre.get(key) != value:
|
||||||
self.reply('But %s are %s, %s.' %
|
self.reply('... but %s are %s ...' %
|
||||||
(key, value, msg.nick), substitute=False)
|
(key, oldValue), substitute=False)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.log.debug('Already have a %s key.',
|
self.log.debug('Already have a %s key.',
|
||||||
|
@ -46,7 +46,7 @@ class InfobotTestCase(ChannelPluginTestCase):
|
|||||||
self.assertSnarfNoResponse('foo is at http://bar.com/', 2)
|
self.assertSnarfNoResponse('foo is at http://bar.com/', 2)
|
||||||
self.assertRegexp('infobot stats', '1 modification')
|
self.assertRegexp('infobot stats', '1 modification')
|
||||||
self.assertRegexp('infobot status', '1 modification')
|
self.assertRegexp('infobot status', '1 modification')
|
||||||
self.assertSnarfRegexp('foo?', r'http://bar.com/')
|
self.assertSnarfRegexp('foo?', r'foo.*is.*http://bar.com/')
|
||||||
self.assertSnarfNoResponse('foo is at http://baz.com/', 2)
|
self.assertSnarfNoResponse('foo is at http://baz.com/', 2)
|
||||||
self.assertSnarfNotRegexp('foo?', 'baz')
|
self.assertSnarfNotRegexp('foo?', 'baz')
|
||||||
m = self.getMsg('bar is at http://foo.com/')
|
m = self.getMsg('bar is at http://foo.com/')
|
||||||
@ -56,6 +56,27 @@ class InfobotTestCase(ChannelPluginTestCase):
|
|||||||
ibot.unaddressed.snarfDefinitions.setValue(learn)
|
ibot.unaddressed.snarfDefinitions.setValue(learn)
|
||||||
ibot.unaddressed.answerQuestions.setValue(answer)
|
ibot.unaddressed.answerQuestions.setValue(answer)
|
||||||
|
|
||||||
|
def testNormalize(self):
|
||||||
|
learn = ibot.unaddressed.snarfDefinitions()
|
||||||
|
answer = ibot.unaddressed.answerQuestions()
|
||||||
|
try:
|
||||||
|
ibot.unaddressed.snarfDefinitions.setValue(True)
|
||||||
|
ibot.unaddressed.answerQuestions.setValue(True)
|
||||||
|
self.assertSnarfNoResponse('foo is at http://bar.com/', 2)
|
||||||
|
self.assertSnarfRegexp('what\'s foo?', r'foo.*is.*http://bar.com/')
|
||||||
|
self.assertSnarfRegexp('wtf\'s foo?', r'foo.*is.*http://bar.com/')
|
||||||
|
self.assertSnarfRegexp('who\'s foo?', r'foo.*is.*http://bar.com/')
|
||||||
|
self.assertSnarfRegexp('where\'s foo?',r'foo.*is.*http://bar.com/')
|
||||||
|
self.assertSnarfNoResponse('i am a tool', 2)
|
||||||
|
self.assertRegexp('%s?' % self.nick, r'is.*tool')
|
||||||
|
self.assertSnarfNoResponse('my bot is a tool', 2)
|
||||||
|
self.assertRegexp('%s\'s bot?' % self.nick, r'is.*tool')
|
||||||
|
self.assertSnarfNoResponse('your name is weird', 2)
|
||||||
|
self.assertRegexp('%s\'s name?' % self.irc.nick, r'is.*weird')
|
||||||
|
finally:
|
||||||
|
ibot.unaddressed.snarfDefinitions.setValue(learn)
|
||||||
|
ibot.unaddressed.answerQuestions.setValue(answer)
|
||||||
|
|
||||||
def testAreSnarf(self):
|
def testAreSnarf(self):
|
||||||
learn = ibot.unaddressed.snarfDefinitions()
|
learn = ibot.unaddressed.snarfDefinitions()
|
||||||
answer = ibot.unaddressed.answerQuestions()
|
answer = ibot.unaddressed.answerQuestions()
|
||||||
@ -91,7 +112,7 @@ class InfobotTestCase(ChannelPluginTestCase):
|
|||||||
try:
|
try:
|
||||||
ibot.unaddressed.answerQuestions.setValue(True)
|
ibot.unaddressed.answerQuestions.setValue(True)
|
||||||
self.assertSnarfNoResponse('foo is bar')
|
self.assertSnarfNoResponse('foo is bar')
|
||||||
self.assertSnarfRegexp('foo?', 'bar')
|
self.assertSnarfRegexp('foo?', 'foo.*is.*bar')
|
||||||
ibot.unaddressed.answerQuestions.setValue(False)
|
ibot.unaddressed.answerQuestions.setValue(False)
|
||||||
self.assertSnarfNoResponse('foo?', 2)
|
self.assertSnarfNoResponse('foo?', 2)
|
||||||
finally:
|
finally:
|
||||||
@ -104,9 +125,9 @@ class InfobotTestCase(ChannelPluginTestCase):
|
|||||||
ibot.unaddressed.answerQuestions.setValue(True)
|
ibot.unaddressed.answerQuestions.setValue(True)
|
||||||
ibot.unaddressed.snarfDefinitions.setValue(True)
|
ibot.unaddressed.snarfDefinitions.setValue(True)
|
||||||
self.assertSnarfNoResponse('forums are good')
|
self.assertSnarfNoResponse('forums are good')
|
||||||
self.assertSnarfRegexp('forums?', 'good')
|
self.assertSnarfRegexp('forums?', r'forums.*are.*good')
|
||||||
self.assertNotError('no, forums are evil')
|
self.assertNotError('no, forums are evil')
|
||||||
self.assertSnarfRegexp('forums?', 'evil')
|
self.assertSnarfRegexp('forums?', r'forums.*.are.*evil')
|
||||||
finally:
|
finally:
|
||||||
ibot.unaddressed.answerQuestions.setValue(answer)
|
ibot.unaddressed.answerQuestions.setValue(answer)
|
||||||
ibot.unaddressed.snarfDefinitions.setValue(learn)
|
ibot.unaddressed.snarfDefinitions.setValue(learn)
|
||||||
@ -129,15 +150,15 @@ class InfobotTestCase(ChannelPluginTestCase):
|
|||||||
ibot.unaddressed.answerQuestions.setValue(answer)
|
ibot.unaddressed.answerQuestions.setValue(answer)
|
||||||
ibot.unaddressed.snarfDefinitions.setValue(learn)
|
ibot.unaddressed.snarfDefinitions.setValue(learn)
|
||||||
|
|
||||||
# def testNoKarmaDunno(self):
|
def testNoKarmaDunno(self):
|
||||||
# self.assertNoResponse('foo++')
|
self.assertNoResponse('foo++')
|
||||||
|
|
||||||
def testPredefinedFactoids(self):
|
def testPredefinedFactoids(self):
|
||||||
self.assertSnarfNoResponse('what?', 3)
|
self.assertSnarfNoResponse('what?', 3)
|
||||||
self.assertRegexp('roses?', 'roses are red')
|
self.assertRegexp('roses?', 'roses are red')
|
||||||
|
|
||||||
def testAddressedQuestions(self):
|
def testAddressedQuestions(self):
|
||||||
self.assertNotError('hi is <reply>Hello, $who.')
|
self.assertSnarfNoResponse('hi is <reply>Hello, $who.')
|
||||||
self.assertSnarfNoResponse('hi')
|
self.assertSnarfNoResponse('hi')
|
||||||
self.assertRegexp('hi', 'Hello')
|
self.assertRegexp('hi', 'Hello')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user