mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-25 19:44:13 +01:00
blootbot-compatibility (and cool feature desire) - moobot factoids that are
like "see <factoid key>" now actually return the value of that factoid key
This commit is contained in:
parent
2beb507554
commit
2d21655cb2
@ -49,6 +49,8 @@ import random
|
|||||||
from itertools import imap
|
from itertools import imap
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
|
import registry
|
||||||
|
|
||||||
import conf
|
import conf
|
||||||
import ircdb
|
import ircdb
|
||||||
import utils
|
import utils
|
||||||
@ -116,6 +118,11 @@ class OptionList(object):
|
|||||||
def pickOptions(s):
|
def pickOptions(s):
|
||||||
return OptionList().tokenize(s)
|
return OptionList().tokenize(s)
|
||||||
|
|
||||||
|
conf.registerPlugin('MoobotFactoids')
|
||||||
|
conf.registerChannelValue(conf.supybot.plugins.MoobotFactoids,
|
||||||
|
'showFactoidIfOnlyOneMatch', registry.Boolean(True, """Determines whether
|
||||||
|
or not the factoid value will be shown when a listkeys search returns only
|
||||||
|
one factoid key."""))
|
||||||
|
|
||||||
class MoobotDBHandler(plugins.DBHandler):
|
class MoobotDBHandler(plugins.DBHandler):
|
||||||
def makeDb(self, filename):
|
def makeDb(self, filename):
|
||||||
@ -159,11 +166,17 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
# definition of what the key is (i.e., "foo is bar")
|
# definition of what the key is (i.e., "foo is bar")
|
||||||
newfact = pickOptions(fact)
|
newfact = pickOptions(fact)
|
||||||
if newfact.startswith("<reply>"):
|
if newfact.startswith("<reply>"):
|
||||||
newfact = newfact[7:].strip()
|
newfact = newfact[7:]
|
||||||
type = "reply"
|
type = "reply"
|
||||||
elif newfact.startswith("<action>"):
|
elif newfact.startswith("<action>"):
|
||||||
newfact = newfact[8:].strip()
|
newfact = newfact[8:]
|
||||||
type = "action"
|
type = "action"
|
||||||
|
elif newfact.startswith("see "):
|
||||||
|
newfact = newfact[4:]
|
||||||
|
type = "refer"
|
||||||
|
# shortcut the substitutions here
|
||||||
|
return (type, newfact)
|
||||||
|
newfact = newfact.strip()
|
||||||
newfact = plugins.standardSubstitute(irc, msg, newfact)
|
newfact = plugins.standardSubstitute(irc, msg, newfact)
|
||||||
return (type, newfact)
|
return (type, newfact)
|
||||||
|
|
||||||
@ -219,6 +232,11 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
irc.reply(text, prefixName=False)
|
irc.reply(text, prefixName=False)
|
||||||
elif type == "define":
|
elif type == "define":
|
||||||
irc.reply("%s is %s" % (key, text), prefixName=False)
|
irc.reply("%s is %s" % (key, text), prefixName=False)
|
||||||
|
elif type == "refer":
|
||||||
|
# text here is the new key to refer to
|
||||||
|
msg.args = [s.replace(key, text) for s in msg.args]
|
||||||
|
newtokens = [s.replace(key, text) for s in tokens]
|
||||||
|
self.invalidCommand(irc, wmsg, newtokens)
|
||||||
else:
|
else:
|
||||||
irc.error("Spurious type from _parseFactoid.")
|
irc.error("Spurious type from _parseFactoid.")
|
||||||
return True
|
return True
|
||||||
@ -593,15 +611,15 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
glob)
|
glob)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.reply("No keys matching %r found." % search)
|
irc.reply("No keys matching %r found." % search)
|
||||||
return
|
elif cursor.rowcount == 1 and \
|
||||||
elif cursor.rowcount == 1:
|
self.registryValue('showFactoidIfOnlyOneMatch', msg.args[0]):
|
||||||
key = cursor.fetchone()[0]
|
key = cursor.fetchone()[0]
|
||||||
self.invalidCommand(irc, msg, [key])
|
self.invalidCommand(irc, msg, [key])
|
||||||
return
|
else:
|
||||||
keys = [repr(tup[0]) for tup in cursor.fetchall()]
|
keys = [repr(tup[0]) for tup in cursor.fetchall()]
|
||||||
s = "Key search for %r (%s found): %s" % \
|
s = "Key search for %r (%s found): %s" % \
|
||||||
(search, len(keys), utils.commaAndify(keys))
|
(search, len(keys), utils.commaAndify(keys))
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
|
|
||||||
def listvalues(self, irc, msg, args):
|
def listvalues(self, irc, msg, args):
|
||||||
"""<text>
|
"""<text>
|
||||||
|
Loading…
Reference in New Issue
Block a user