-
Notifications
You must be signed in to change notification settings - Fork 15
/
utils.py
73 lines (61 loc) · 2.15 KB
/
utils.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
71
72
73
import yaml
import requests
import exceptions
def verifyRecaptcha(token, request, config):
print(f"Verifying recaptcha {token[:15]}")
recaptcha_url = "https://www.google.com/recaptcha/api/siteverify"
payload = {
"secret": config["recaptcha"]["private"],
"response": token,
"remoteip": request.remote_addr,
}
response = requests.post(recaptcha_url, data=payload)
result = response.json()
return result
def generateInvite(config):
print("Generating new invite!")
resp = requests.post(
f"https://discordapp.com/api/channels/{config['discord']['welcome_room']}/invites",
headers={"Authorization": f"Bot {config['discord']['private']}"},
json={"max_uses": 1, "unique": True, "max_age": 300},
)
i = resp.json()
if resp.status_code != 200:
raise exceptions.InviteGenerationError(i)
if i.get("code"):
print("Generated new invite!")
return i["code"]
raise exceptions.InviteGenerationError(i)
def verifyConfig(config):
ok = True
if "dark_theme" not in config:
print("!! Theme not defined")
if "recaptcha" in config:
if config["recaptcha"]["public"] == None:
print("!! Recaptcha public key is not defined, exiting")
ok = False
if config["recaptcha"]["private"] == None:
print("!! Recaptcha private key is not defined, exiting")
ok = False
else:
print("!! Recaptcha config doesnt exist, exiting")
ok = False
if "discord" in config:
if config["discord"]["welcome_room"] == None:
print("!! Discord welcome room not defined, exiting")
ok = False
if config["discord"]["private"] == None:
print("!! Discord private key is not defined, exiting")
ok = False
else:
print("!! Discord config doesnt exist, exiting")
ok = False
if "server" in config:
if config["server"]["port"] == None:
print("!! Server port not defined, exiting")
ok = False
else:
print("!! Sever config not defined, exiting")
ok = False
if not ok:
quit(1)