forked from NotSoSuper/NotSoBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage_queue_api.py
67 lines (60 loc) · 2.01 KB
/
message_queue_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from flask import Flask, render_template, request, session, Response
import jinja2
import json
import os
import time
app = Flask(__name__)
loader = jinja2.ChoiceLoader([
app.jinja_loader,
jinja2.FileSystemLoader('/root/discord/templates'),
])
app.jinja_loader = loader
queue = {}
@app.route("/queue", methods=["POST"])
def q():
if all(x in request.form for x in ('id', 'channel_id', 'message', 'key', 'embed')) and len(request.form) == 5:
try:
if request.form['key'] != '':
return render_template("index.html", RESPONSE='heck off')
key = str(request.form['id'])
channel_id = str(request.form['channel_id'])
utc = int(time.time())
msg = str(request.form['message'])
embed = str(request.form['embed'])
queue.update({key:[channel_id, msg, utc, embed]})
return render_template("index.html", RESPONSE='added')
except Exception as e:
print(e)
return render_template("index.html", RESPONSE='no, 1')
else:
return render_template("index.html", RESPONSE='no, 0')
@app.route("/queued", methods=["POST"])
def queued():
if 'key' in request.form and len(request.form) == 1:
try:
if request.form['key'] != '':
return render_template("index.html", RESPONSE='heck off')
js = json.dumps(queue)
return Response(js, status=200, mimetype='application/json')
except Exception as e:
print(e)
return render_template("index.html", RESPONSE='no, 1')
else:
return render_template("index.html", RESPONSE='no, 0')
@app.route("/queue_delete", methods=["POST"])
def delete():
if 'key' in request.form and 'id' in request.form and len(request.form) <= 2:
try:
if request.form['key'] != '':
return render_template("index.html", RESPONSE='heck off')
queue_id = str(request.form['id'])
del queue[queue_id]
return render_template("index.html", RESPONSE='ok')
except Exception as e:
print(e)
return render_template("index.html", RESPONSE='no, 1')
else:
return render_template("index.html", RESPONSE='no, 0')
if __name__ == "__main__":
app.debug = True
app.run(host='ip', port=0)