-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (59 loc) · 1.75 KB
/
main.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
68
69
70
import os
import time
import requests
from dhooks import File, Webhook
from flask import Flask, request
app = Flask(__name__)
env = os.environ
@app.route("/", methods=["POST"])
def webhook():
content = request.json["content"]
username = request.json["username"]
avatar_url = request.json["avatar_url"]
try:
media = request.json["media"].split(",")
except:
pass
try:
video = request.json["video"].split(",")
except:
video = ""
print("=================")
print(media)
print("=================")
print(video)
print("=================")
webhook_url = (
"https://discord.com/api/webhooks/"
+ env.get("webhook_id")
+ "/"
+ env.get("webhook_token")
)
hook = Webhook(webhook_url)
release_date = 1645718400
now = time.time()
days = "> " + str(round((release_date - now) / 86400)) + " day until release"
# hook.send(content=days, username=username, avatar_url=avatar_url)
# time.sleep(1)
hook.send(content=content, username=username, avatar_url=avatar_url)
if video:
try:
r = requests.get(video[0])
open("file", "wb").write(r.content)
f = File("file", "video.mp4")
hook.send(file=f, username=username, avatar_url=avatar_url)
except:
pass
else:
try:
for url in media:
r = requests.get(url)
open("file", "wb").write(r.content)
f = File("file", "image.jpg")
hook.send(file=f, username=username, avatar_url=avatar_url)
except:
pass
return "200 ok"
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host="0.0.0.0", port=port)