66 lines
2.7 KiB
Python
66 lines
2.7 KiB
Python
|
"""Help system for this tenquestionmarks-based bot.
|
||
|
Usage:
|
||
|
- !tqmhelp -> display an overview of all modules
|
||
|
- !tqmhelp module -> display help for a specific module
|
||
|
- !tqmhelp module command -> display help for a specific command
|
||
|
"""
|
||
|
|
||
|
import types
|
||
|
import inspect
|
||
|
|
||
|
def tqmhelp(nick,channel,tenquestionmarks,module,command=None):
|
||
|
output = []
|
||
|
bnick = tenquestionmarks.config()["nick"]
|
||
|
if module == "":
|
||
|
output.append("%s help index\n" % (bnick))
|
||
|
output.append("--------------------------------\n")
|
||
|
output.append("In this bot, commands are grouped into modules.\n")
|
||
|
output.append("For help with a specific module, type !tqmhelp followed by \n")
|
||
|
output.append("the name of the module.\n")
|
||
|
output.append("This bot contains the following modules:\n")
|
||
|
output.append("--------------------------------\n")
|
||
|
for submod in tenquestionmarks.modules():
|
||
|
output.append("<b>%s</b>\n" % (submod))
|
||
|
submodobj = tenquestionmarks.modules()[submod]
|
||
|
if not submodobj.__doc__ == None:
|
||
|
output.append(submodobj.__doc__)
|
||
|
output.append("\n--------------------------------\n")
|
||
|
elif not command == None:
|
||
|
try:
|
||
|
modobj = tenquestionmarks.modules()[module]
|
||
|
except KeyError:
|
||
|
return tenquestionmarks.html("<b>Help error</b>: No module named %s" % (module))
|
||
|
if not hasattr(modobj,command):
|
||
|
return tenquestionmarks.html("<b>Help error</b>: No command %s in module %s" % (command,module))
|
||
|
output.append("%s help for command %s.%s\n" % (bnick, module, command))
|
||
|
output.append("--------------------------------\n")
|
||
|
commandobj = getattr(modobj,command)
|
||
|
output.append("<b>Command %s.%s</b>\n" % (module, command))
|
||
|
argspec = inspect.getargspec(commandobj)
|
||
|
del argspec.args[0]
|
||
|
del argspec.args[0]
|
||
|
del argspec.args[0]
|
||
|
output.append("<b>Usage:</b> !%s.%s %s\n" % (module, command, " ".join(argspec.args)))
|
||
|
if not commandobj.__doc__ == None:
|
||
|
output.append(commandobj.__doc__)
|
||
|
else:
|
||
|
try:
|
||
|
modobj = tenquestionmarks.modules()[module]
|
||
|
except KeyError:
|
||
|
return tenquestionmarks.html("<b>Help error</b>: No module named %s" % (module))
|
||
|
output.append("%s help for module %s\n" % (bnick, module))
|
||
|
output.append("--------------------------------\n")
|
||
|
for var in vars(modobj):
|
||
|
varvalue = vars(modobj)[var]
|
||
|
if not (var.startswith("on_") or var.startswith("_")) and isinstance(varvalue,types.FunctionType):
|
||
|
output.append("<b>Command %s.%s</b>\n" % (module, var))
|
||
|
argspec = inspect.getargspec(varvalue)
|
||
|
del argspec.args[0]
|
||
|
del argspec.args[0]
|
||
|
del argspec.args[0]
|
||
|
output.append("<b>Usage:</b> !%s.%s %s\n" % (module, var, " ".join(argspec.args)))
|
||
|
if not varvalue.__doc__ == None:
|
||
|
output.append(varvalue.__doc__)
|
||
|
output.append("\n--------------------------------\n")
|
||
|
return tenquestionmarks.html("".join(output))
|