mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Updateed to have a bit more personality and infinity percent more configuration variables.
This commit is contained in:
parent
2f2b7bd6c1
commit
738546b4cf
@ -40,6 +40,7 @@ import plugins
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import random
|
||||||
import cPickle as pickle
|
import cPickle as pickle
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
@ -47,9 +48,25 @@ import utils
|
|||||||
import ircmsgs
|
import ircmsgs
|
||||||
import ircutils
|
import ircutils
|
||||||
import privmsgs
|
import privmsgs
|
||||||
|
import registry
|
||||||
import callbacks
|
import callbacks
|
||||||
|
|
||||||
conf.registerPlugin('Infobot')
|
conf.registerPlugin('Infobot')
|
||||||
|
conf.registerGlobalValue(conf.supybot.plugins.Infobot, 'personality',
|
||||||
|
registry.Boolean(True, """Determines whether the bot will respond will
|
||||||
|
personable (Infobot-like) responses rather than its standard messages."""))
|
||||||
|
conf.registerGlobalValue(conf.supybot.plugins.Infobot, 'boringDunno',
|
||||||
|
registry.String('Dunno.', """Determines what boring dunno should be given
|
||||||
|
if supybot.plugins.Infobot.personality is False."""))
|
||||||
|
conf.registerGlobalValue(conf.supybot.plugins.Infobot,
|
||||||
|
'snarfUnaddressedDefinitions', registry.Boolean(True, """Determines whether
|
||||||
|
the bot will snarf definitions given in the channel that weren't directly
|
||||||
|
addressed to it. Of course, no confirmation will be given if the bot isn't
|
||||||
|
directly addressed."""))
|
||||||
|
conf.registerGlobalValue(conf.supybot.plugins.Infobot,
|
||||||
|
'answerUnaddressedQuestions', registry.Boolean(True, """Determines whether
|
||||||
|
the bot will answer questions that weren't directly addressed to it. Of
|
||||||
|
course, if it doesn't have an answer, it will remain silent."""))
|
||||||
|
|
||||||
def configure(advanced):
|
def configure(advanced):
|
||||||
# This will be called by setup.py to configure this module. Advanced is
|
# This will be called by setup.py to configure this module. Advanced is
|
||||||
@ -72,6 +89,19 @@ class InfobotDB(object):
|
|||||||
(self._is, self._are) = pickle.load(fd)
|
(self._is, self._are) = pickle.load(fd)
|
||||||
self._changes = 0
|
self._changes = 0
|
||||||
self._responses = 0
|
self._responses = 0
|
||||||
|
self._ends = ['!',
|
||||||
|
'.',
|
||||||
|
', $who.',]
|
||||||
|
self._dunnos = ['Dunno',
|
||||||
|
'No idea',
|
||||||
|
'I don\'t know',
|
||||||
|
'I have no idea',
|
||||||
|
'I don\'t have a clue',]
|
||||||
|
self._confirms = ['10-4',
|
||||||
|
'Okay',
|
||||||
|
'Got it',
|
||||||
|
'Gotcha',
|
||||||
|
'I hear ya']
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
fd = file(filename, 'w')
|
fd = file(filename, 'w')
|
||||||
@ -117,6 +147,12 @@ class InfobotDB(object):
|
|||||||
self._changes += 1
|
self._changes += 1
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
|
def getDunno(self):
|
||||||
|
return random.choice(self._dunnos) + random.choice(self._ends)
|
||||||
|
|
||||||
|
def getConfirm(self):
|
||||||
|
return random.choice(self._confirms) + random.choice(self._ends)
|
||||||
|
|
||||||
def getChangeCount(self):
|
def getChangeCount(self):
|
||||||
return self._changes
|
return self._changes
|
||||||
|
|
||||||
@ -126,13 +162,17 @@ class InfobotDB(object):
|
|||||||
class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
||||||
regexps = ['doForget', 'doFactoid', 'doUnknown']
|
regexps = ['doForget', 'doFactoid', 'doUnknown']
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
||||||
|
try:
|
||||||
self.db = InfobotDB()
|
self.db = InfobotDB()
|
||||||
|
except Exception:
|
||||||
|
self.log.exception('Error loading %s:', filename)
|
||||||
|
raise # So it doesn't get loaded without its database.
|
||||||
self.irc = None
|
self.irc = None
|
||||||
self.msg = None
|
self.msg = None
|
||||||
self.force = False
|
self.force = False
|
||||||
self.replied = False
|
self.replied = False
|
||||||
self.addressed = False
|
self.addressed = False
|
||||||
callbacks.PrivmsgCommandAndRegexp.__init__(self)
|
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
self.db.close()
|
self.db.close()
|
||||||
@ -151,12 +191,17 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
irc.reply(plugins.standardSubstitute(irc, msg, s), prefixName=False)
|
irc.reply(plugins.standardSubstitute(irc, msg, s), prefixName=False)
|
||||||
|
|
||||||
def confirm(self, irc=None, msg=None):
|
def confirm(self, irc=None, msg=None):
|
||||||
# XXX
|
if self.registryValue('personality'):
|
||||||
self.reply('Roger that!', irc=irc, msg=msg)
|
self.reply(self.db.getConfirm(), irc=irc, msg=msg)
|
||||||
|
else:
|
||||||
|
assert self.irc is not None
|
||||||
|
self.irc.replySuccess()
|
||||||
|
|
||||||
def dunno(self, irc=None, msg=None):
|
def dunno(self, irc=None, msg=None):
|
||||||
# XXX
|
if self.registryValue('personality'):
|
||||||
self.reply('I dunno, dude.', irc=irc, msg=msg)
|
self.reply(self.db.getDunno(), irc=irc, msg=msg)
|
||||||
|
else:
|
||||||
|
self.reply(self.registryValue('boringDunno'), irc=irc, msg=msg)
|
||||||
|
|
||||||
def factoid(self, key, irc=None, msg=None):
|
def factoid(self, key, irc=None, msg=None):
|
||||||
if irc is None:
|
if irc is None:
|
||||||
@ -249,6 +294,7 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
r"^(.+?)\?[?!. ]*$"
|
r"^(.+?)\?[?!. ]*$"
|
||||||
key = match.group(1)
|
key = match.group(1)
|
||||||
key = plugins.standardSubstitute(irc, msg, key)
|
key = plugins.standardSubstitute(irc, msg, key)
|
||||||
|
if self.addressed or self.registryValue('answerUnaddressedQuestions'):
|
||||||
self.factoid(key) # Does the dunno'ing for us itself.
|
self.factoid(key) # Does the dunno'ing for us itself.
|
||||||
# TODO: Add invalidCommand.
|
# TODO: Add invalidCommand.
|
||||||
|
|
||||||
@ -257,15 +303,20 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
(key, isAre, maybeForce, value) = match.groups()
|
(key, isAre, maybeForce, value) = match.groups()
|
||||||
if key.lower() in ('where', 'what', 'who'):
|
if key.lower() in ('where', 'what', 'who'):
|
||||||
# It's a question.
|
# It's a question.
|
||||||
|
if self.addressed or \
|
||||||
|
self.registryValue('answerUnaddressedQuestions'):
|
||||||
self.factoid(value)
|
self.factoid(value)
|
||||||
return
|
return
|
||||||
|
if not self.addressed and \
|
||||||
|
not self.registryValue('snarfUnaddressedDefinitions'):
|
||||||
|
return
|
||||||
isAre = isAre.lower()
|
isAre = isAre.lower()
|
||||||
self.force = self.force or bool(maybeForce)
|
self.force = self.force or bool(maybeForce)
|
||||||
key = plugins.standardSubstitute(irc, msg, key)
|
key = plugins.standardSubstitute(irc, msg, key)
|
||||||
value = plugins.standardSubstitute(irc, msg, value)
|
value = plugins.standardSubstitute(irc, msg, value)
|
||||||
if isAre in ('was', 'is', 'am'):
|
if isAre in ('was', 'is', 'am'):
|
||||||
if self.db.hasIs(key):
|
if self.db.hasIs(key):
|
||||||
if not self.force:
|
if self.addressed and not self.force:
|
||||||
value = self.db.getIs(key)
|
value = self.db.getIs(key)
|
||||||
self.reply('But %s is %s.' % (key, value))
|
self.reply('But %s is %s.' % (key, value))
|
||||||
return
|
return
|
||||||
@ -274,7 +325,7 @@ class Infobot(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
self.db.setIs(key, value)
|
self.db.setIs(key, value)
|
||||||
else:
|
else:
|
||||||
if self.db.hasAre(key):
|
if self.db.hasAre(key):
|
||||||
if not self.force:
|
if self.addressed and not self.force:
|
||||||
value = self.db.getAre(key)
|
value = self.db.getAre(key)
|
||||||
self.reply('But %s are %s.' % (key, value))
|
self.reply('But %s are %s.' % (key, value))
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user