plugins/Factoids: Dynamically generate the help string using the value of supybot.plugins.Factoids.learnSeparator

This commit is contained in:
James Vega 2006-08-28 13:14:21 +00:00
parent cd2b58a7d5
commit 3908e989c5

View File

@ -99,14 +99,16 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
db.commit() db.commit()
return db return db
def learn(self, irc, msg, args, channel, key, factoid): def getCommandHelp(self, command):
"""[<channel>] <key> as <value> method = self.getCommandMethod(command)
if method.im_func.func_name == 'learn':
s = self.registryValue('learnSeparator', dynamic.msg.args[0])
return callbacks.getHelp(method,
doc=method._fake__doc__ % (s, s),
name=callbacks.formatCommand(command))
return super(Factoids, self).getCommandHelp(self, command)
Associates <key> with <value>. <channel> is only necessary if the def learn(self, irc, msg, args, channel, key, factoid):
message isn't sent on the channel itself. The word 'as' is necessary
to separate the key from the value. It can be changed to another
word via the learnSeparator registry value.
"""
db = self.getDb(channel) db = self.getDb(channel)
cursor = db.cursor() cursor = db.cursor()
cursor.execute("SELECT id, locked FROM keys WHERE key LIKE %s", key) cursor.execute("SELECT id, locked FROM keys WHERE key LIKE %s", key)
@ -129,6 +131,15 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
else: else:
irc.error('That factoid is locked.') irc.error('That factoid is locked.')
learn = wrap(learn, ['factoid']) learn = wrap(learn, ['factoid'])
learn._fake__doc__ = """[<channel>] <key> %s <value>
Associates <key> with <value>. <channel> is only
necessary if the message isn't sent on the channel
itself. The word '%s' is necessary to separate the
key from the value. It can be changed to another word
via the learnSeparator registry value.
"""
def _lookupFactoid(self, channel, key): def _lookupFactoid(self, channel, key):
db = self.getDb(channel) db = self.getDb(channel)