From 2f511877720ed44589d9de40a0919e0c3b27ae1d Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Thu, 20 Oct 2022 08:03:27 +0200 Subject: add command aliases --- BerryClient/commands.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/BerryClient/commands.py b/BerryClient/commands.py index 532c0a2..20771ef 100644 --- a/BerryClient/commands.py +++ b/BerryClient/commands.py @@ -7,7 +7,7 @@ log = logging.getLogger(__name__) PREFIX = "#" COMMANDS = {} -def command(name=None): +def command(name=None, aliases=None): def decorator(func): func_name = name or func.__name__ @@ -15,7 +15,7 @@ def command(name=None): try: retval = func(core, *args) if retval: - core.postToChat(f"[{func_name}] {retval}") + log.info(retval) except Exception as e: log.exception(e) @@ -24,11 +24,19 @@ def command(name=None): if func.__doc__: description = func.__doc__.strip().split("\n")[0] - COMMANDS[func_name] = { + cmd = { "func": wrapper, - "description": description + "description": description, + "alias": False, } + COMMANDS[func_name] = cmd + if aliases: + for alias in aliases: + alias_cmd = cmd.copy() + alias_cmd["alias"] = True + COMMANDS[alias] = alias_cmd + return decorator @on_chat_post() -- cgit v1.2.3