refactor help
This commit is contained in:
parent
6a067166fe
commit
bf6e5784f2
12
loader.py
12
loader.py
|
@ -30,7 +30,7 @@ def unload_module(bot, name):
|
||||||
bot.unregister_callable(obj)
|
bot.unregister_callable(obj)
|
||||||
|
|
||||||
del old_module
|
del old_module
|
||||||
delattr(sys.modules['modules'], name)
|
delattr(sys.modules['modules'], name.rpartition('.')[2])
|
||||||
del sys.modules[name]
|
del sys.modules[name]
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,14 +77,6 @@ def process_callable(func, config):
|
||||||
Sets various helper atributes about a given function.
|
Sets various helper atributes about a given function.
|
||||||
"""
|
"""
|
||||||
prefix = config.core.prefix
|
prefix = config.core.prefix
|
||||||
doc = func.__doc__
|
|
||||||
if doc:
|
|
||||||
doc = doc.strip()
|
|
||||||
doc = doc.replace("\t", "")
|
|
||||||
doc = doc.replace("\n\n", "\x00")
|
|
||||||
doc = doc.replace("\n", " ")
|
|
||||||
doc = doc.replace("\x00", "\n")
|
|
||||||
func._docs = {}
|
|
||||||
|
|
||||||
func.example = getattr(func, "example", [(None, None)])
|
func.example = getattr(func, "example", [(None, None)])
|
||||||
func.thread = getattr(func, "thread", True)
|
func.thread = getattr(func, "thread", True)
|
||||||
|
@ -108,5 +100,3 @@ def process_callable(func, config):
|
||||||
if ex_input[0] != prefix:
|
if ex_input[0] != prefix:
|
||||||
ex_input = prefix + ex_input
|
ex_input = prefix + ex_input
|
||||||
func.example[n] = (ex_input, example[1])
|
func.example[n] = (ex_input, example[1])
|
||||||
if doc:
|
|
||||||
func._docs = (doc, func.example)
|
|
||||||
|
|
|
@ -7,27 +7,41 @@ import random
|
||||||
|
|
||||||
from module import commands, example
|
from module import commands, example
|
||||||
|
|
||||||
|
def clean_docstring(doc):
|
||||||
|
"""Cleans the docstring up a bit."""
|
||||||
|
if not doc:
|
||||||
|
return ''
|
||||||
|
doc = doc.strip()
|
||||||
|
doc = doc.replace("\t", "")
|
||||||
|
doc = doc.replace("\n\n", "\x00")
|
||||||
|
doc = doc.replace("\n", " ")
|
||||||
|
doc = doc.replace("\x00", "\n")
|
||||||
|
return doc
|
||||||
|
|
||||||
@commands('help', 'commands')
|
@commands('help', 'commands')
|
||||||
@example('.help tell')
|
@example('.help tell')
|
||||||
def help(bot, trigger):
|
def help(bot, trigger):
|
||||||
"""Shows a command's documentation, and possibly an example."""
|
"""Shows a command's documentation, and possibly an example."""
|
||||||
if trigger.group(2):
|
if trigger.group(2):
|
||||||
name = trigger.group(2)
|
command = trigger.group(2)
|
||||||
name = name.lower()
|
command = command.lower()
|
||||||
if name not in bot.commands:
|
if command not in bot.commands:
|
||||||
return bot.msg("Command not found.")
|
return bot.msg("Command not found.")
|
||||||
cmd = bot.commands[name]
|
|
||||||
docstring, examples = cmd.doc
|
|
||||||
if examples:
|
|
||||||
ex = random.choice(examples)
|
|
||||||
|
|
||||||
bot.msg(docstring)
|
func = bot.commands[command]
|
||||||
if cmd.aliases:
|
doc = clean_docstring(func.__doc__)
|
||||||
bot.msg("Aliases: " + ", ".join(cmd.aliases))
|
bot.msg(doc)
|
||||||
if ex[0]:
|
|
||||||
|
aliases = [c for c, f in bot.commands.items() if f == func]
|
||||||
|
aliases.remove(command)
|
||||||
|
if aliases:
|
||||||
|
bot.msg("Aliases: " + ", ".join(aliases))
|
||||||
|
|
||||||
|
if hasattr(func, 'example'):
|
||||||
|
ex = random.choice(func.example)
|
||||||
bot.msg("Ex. In: " + ex[0])
|
bot.msg("Ex. In: " + ex[0])
|
||||||
if ex[1]:
|
if ex[1]:
|
||||||
bot.msg("Ex. Out: " + ex[1])
|
bot.msg("Ex. Out: " + ex[1])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if trigger.owner:
|
if trigger.owner:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user