From 53a8a39840c87b173fd023e70729d24af7942b6d Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Wed, 14 Aug 2019 05:05:45 +0200 Subject: [PATCH] sort command list by name and argument count (increasing) --- telegram_click/__init__.py | 3 ++- telegram_click/decorator.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/telegram_click/__init__.py b/telegram_click/__init__.py index 346751d..5d7c90a 100644 --- a/telegram_click/__init__.py +++ b/telegram_click/__init__.py @@ -47,7 +47,8 @@ def generate_command_list(update, context) -> str: """ commands_with_permission = list( filter(lambda x: x["permissions"] is None or x["permissions"].evaluate(update, context), COMMAND_LIST)) - help_messages = list(map(lambda x: x["message"], commands_with_permission)) + sorted_commands = sorted(commands_with_permission, key=lambda x: (x["name"].lower(), len(x["arguments"]))) + help_messages = list(map(lambda x: x["message"], sorted_commands)) if len(COMMAND_LIST) <= 0: return "This bot does not have any commands." diff --git a/telegram_click/decorator.py b/telegram_click/decorator.py index 90df95b..fc98924 100644 --- a/telegram_click/decorator.py +++ b/telegram_click/decorator.py @@ -172,6 +172,9 @@ def command(name: str, description: str = None, from telegram_click import COMMAND_LIST COMMAND_LIST.append( { + "name": name, + "description": description, + "arguments": arguments, "message": help_message, "permissions": permissions }