Added help strings to lookups.

This commit is contained in:
Jeremy Fincher 2003-12-02 18:37:39 +00:00
parent 64499fd18f
commit 1b8d655738
3 changed files with 14 additions and 2 deletions

View File

@ -49,7 +49,6 @@ import utils
import privmsgs import privmsgs
import callbacks import callbacks
def configure(onStart, afterConnect, advanced): def configure(onStart, afterConnect, advanced):
# This will be called by setup.py to configure this module. onStart and # This will be called by setup.py to configure this module. onStart and
# afterConnect are both lists. Append to onStart the commands you would # afterConnect are both lists. Append to onStart the commands you would
@ -157,8 +156,19 @@ class Lookup(callbacks.Privmsg):
def f(self, irc, msg, args): def f(self, irc, msg, args):
args.insert(0, name) args.insert(0, name)
self._lookup(irc, msg, args) self._lookup(irc, msg, args)
db = getDb()
cursor = db.cursor()
cursor.execute("""SELECT COUNT(*) FROM %s""" % name)
rows = cursor.fetchone()[0]
docstring = """[<key>]
If <key> is given, looks up <key> in the %s database. Otherwise,
returns a random key: value pair from the database. There are
%s in the database.
""" % (name, utils.nItems(rows, name))
f = types.FunctionType(f.func_code, f.func_globals, f = types.FunctionType(f.func_code, f.func_globals,
f.func_name, closure=f.func_closure) f.func_name, closure=f.func_closure)
f.__doc__ = docstring
setattr(self.__class__, name, f) setattr(self.__class__, name, f)
def _lookup(self, irc, msg, args): def _lookup(self, irc, msg, args):

View File

@ -64,6 +64,7 @@ if sqlite:
self.assertResponse('test your mom', 'my mom') self.assertResponse('test your mom', 'my mom')
self.assertError('test something not in there') self.assertError('test something not in there')
self.assertResponse('test foo:bar', 'baz') self.assertResponse('test foo:bar', 'baz')
self.assertHelp('help test')
self.assertNotError('lookup remove test') self.assertNotError('lookup remove test')
try: try:
original = conf.replyWhenNotCommand original = conf.replyWhenNotCommand

View File

@ -193,7 +193,8 @@ class PluginTestCase(unittest.TestCase):
m = self._feedMsg(query) m = self._feedMsg(query)
if m is None: if m is None:
raise TimeoutError, query raise TimeoutError, query
self.failUnless(lastGetHelp in m.args[1]) self.failUnless(lastGetHelp in m.args[1],
'%s is not the help (%s)' % (m.args[1], lastGetHelp))
def assertNoResponse(self, query, timeout=None): def assertNoResponse(self, query, timeout=None):
m = self._feedMsg(query, timeout) m = self._feedMsg(query, timeout)