/api/command/commands endpoint returns a list of commands and help messages

doc_update
Joey Hines 2019-01-27 12:43:30 -06:00
parent 915c4a9157
commit 26f8090878
2 changed files with 20 additions and 2 deletions

View File

@ -35,7 +35,9 @@ def get_required_args(func):
def command(type): def command(type):
def command_dec(func): def command_dec(func):
def add_command(): 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 func
return add_command() return add_command()
@ -43,6 +45,12 @@ def command(type):
return command_dec 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): def get_player(discord_uuid=None, mc_uuid=None):
try: try:
if discord_uuid is not None: if discord_uuid is not None:

View File

@ -35,13 +35,23 @@ def run_command(request, command, req_type):
return JsonResponse(response, safe=False) 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): class CommandAPI(View):
def get(self, request, command): def get(self, request, command):
get = request.GET get = request.GET
if check_token(get, commands_perm=True): if check_token(get, commands_perm=True):
if command.lower() == "commands": if command.lower() == "commands":
return JsonResponse(commands.command_dict) return JsonResponse(get_commands(), safe=False)
else: else:
return run_command(get, command, "GET") return run_command(get, command, "GET")
else: else: