diff --git a/api/commands.py b/api/commands.py index 9fbdf3a..5b15e79 100644 --- a/api/commands.py +++ b/api/commands.py @@ -35,7 +35,9 @@ def get_required_args(func): def command(type): def command_dec(func): def add_command(): - command_dict[type][func.__name__] = {"func": func, "params": get_required_args(func)} + command_dict[type][func.__name__] = {"func": func, + "params": get_required_args(func), + "help": parse_help(func)} return func return add_command() @@ -43,6 +45,12 @@ def command(type): return command_dec +def parse_help(func): + match = re.search(".*:help:.*", func.__doc__) + + return match.group(0).partition(":help: ")[-1] + + def get_player(discord_uuid=None, mc_uuid=None): try: if discord_uuid is not None: diff --git a/api/views.py b/api/views.py index df38596..acdf3eb 100644 --- a/api/views.py +++ b/api/views.py @@ -35,13 +35,23 @@ def run_command(request, command, req_type): return JsonResponse(response, safe=False) +def get_commands(): + command_list = [] + + for request in commands.command_dict: + for c in commands.command_dict[request]: + command_list.append({"command": c, "help": commands.command_dict[request][c]["help"]}) + + return command_list + + class CommandAPI(View): def get(self, request, command): get = request.GET if check_token(get, commands_perm=True): if command.lower() == "commands": - return JsonResponse(commands.command_dict) + return JsonResponse(get_commands(), safe=False) else: return run_command(get, command, "GET") else: