From 902a57c911599acdfefaa53684b72b4720207ea8 Mon Sep 17 00:00:00 2001 From: iou1name Date: Fri, 25 May 2018 13:46:43 -0400 Subject: [PATCH] .help lists aliases --- bot.py | 16 +++++++++------- modules/help.py | 12 +++++++----- tools/__init__.py | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/bot.py b/bot.py index 6b77d31..a13d9ea 100755 --- a/bot.py +++ b/bot.py @@ -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 diff --git a/modules/help.py b/modules/help.py index 0204278..d5deb62 100755 --- a/modules/help.py +++ b/modules/help.py @@ -16,16 +16,18 @@ 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]: - bot.msg("Ex. Out: " + ex[1]) + if ex[1]: + bot.msg("Ex. Out: " + ex[1]) else: if trigger.owner: @@ -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) diff --git a/tools/__init__.py b/tools/__init__.py index 30ab50d..32a8619 100755 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -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):