Skip to content

Commit

Permalink
Merge pull request #13 from markusressel/feature/sort_command_list
Browse files Browse the repository at this point in the history
sort command list by name and argument count (increasing)
  • Loading branch information
markusressel authored Aug 14, 2019
2 parents 02eb377 + 53a8a39 commit fce95a6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion telegram_click/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
3 changes: 3 additions & 0 deletions telegram_click/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit fce95a6

Please sign in to comment.