aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2022-10-20 08:03:27 +0200
committerJan200101 <sentrycraft123@gmail.com>2022-10-20 08:03:27 +0200
commit2f511877720ed44589d9de40a0919e0c3b27ae1d (patch)
tree4157418d1ded46ab953e6448dc765ba28fb0ea3b
parentc91f5a002dca8136f2724a51f3b210962752249f (diff)
downloadBerryClient-2f511877720ed44589d9de40a0919e0c3b27ae1d.tar.gz
BerryClient-2f511877720ed44589d9de40a0919e0c3b27ae1d.zip
add command aliases
-rw-r--r--BerryClient/commands.py16
1 files 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()