42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
import flask
|
|
|
|
api = flask.Flask(__name__)
|
|
#enable/disable this to get web pages of crashes returned
|
|
api.config["DEBUG"] = True
|
|
|
|
def init():
|
|
#todo load entire command library and cache it here
|
|
pass
|
|
|
|
def is_command(command:str)->bool:
|
|
if command == "!echo":
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def handle_command(command, rest):
|
|
if command == "!echo":
|
|
message = "Got payload [%s]" % rest
|
|
return flask.make_response("{message:\"%s\"}" % message, 200, {"Content-Type": "application/json"})
|
|
|
|
@api.route('/api/v1/command', methods=['GET'])
|
|
def is_command():
|
|
if 'name' in request.args:
|
|
if is_command(request.args['name']):
|
|
return flask.make_response('', 200)
|
|
else:
|
|
return flask.make_response('', 404)
|
|
|
|
def exec_command():
|
|
if 'command_name' not in request.args:
|
|
return flask.make_response('{text:"Argument \'command_name\' not in request"}', 400)
|
|
if 'rest' not in request.args:
|
|
return flask.make_response('{text:"Argument \'rest\' not in request"}', 400)
|
|
|
|
return handle_command(request.args['command_name'], request.args['rest'])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
init()
|
|
api.run(host='0.0.0.0')
|