/api/command/commands endpoint returns a list of commands and help messages
parent
915c4a9157
commit
26f8090878
|
@ -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:
|
||||
|
|
12
api/views.py
12
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:
|
||||
|
|
Loading…
Reference in New Issue