.help lists aliases

This commit is contained in:
iou1name 2018-05-25 13:46:43 -04:00
parent 09a4f03f4c
commit 902a57c911
3 changed files with 18 additions and 13 deletions

16
bot.py
View File

@ -128,13 +128,15 @@ class Fulvia(irc.IRCClient):
for func in callables:
if hasattr(func, 'commands'):
self._callables[func.__name__] = func
for command in func.commands:
self.commands[command] = tools.Command(command)
self.commands[command]._func_name = func.__name__
self.commands[command].priv = func.priv
self.commands[command].doc = func._docs
if command in func.aliases:
self.commands[command].alias = True
for cmd in func.commands:
self.commands[cmd] = tools.Command(cmd)
self.commands[cmd]._func_name = func.__name__
self.commands[cmd].priv = func.priv
self.commands[cmd].doc = func._docs
if cmd in func.aliases:
self.commands[cmd].canonical = False
aliases = [a for a in func.commands if a != cmd]
self.commands[cmd].aliases = aliases
if func.hook:
self._callables[func.__name__] = func

View File

@ -16,12 +16,14 @@ def help(bot, trigger):
name = name.lower()
if name not in bot.commands:
return
doc = bot.commands[name].doc
docstring, examples = doc
cmd = bot.commands[name]
docstring, examples = cmd.doc
if examples:
ex = random.choice(examples)
bot.msg(docstring)
if cmd.aliases:
bot.msg("Aliases: " + ", ".join(cmd.aliases))
if ex[0]:
bot.msg("Ex. In: " + ex[0])
if ex[1]:
@ -35,7 +37,7 @@ def help(bot, trigger):
else:
cmds = [cmd for _, cmd in bot.commands.items() if cmd.priv < 5]
cmds = [cmd.name for cmd in cmds if not cmd.alias]
cmds = [cmd.name for cmd in cmds if cmd.canonical]
cmds = sorted(cmds)
msg = "Available commands: " + ", ".join(cmds)
bot.msg(msg)

View File

@ -142,7 +142,8 @@ class Command():
self._func_name = ""
self.priv = 0
self.doc = None
self.alias = False
self.canonical = True
self.aliases = []
def configureHostMask(mask):