-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhook.py
38 lines (36 loc) · 1.23 KB
/
hook.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
import requests
import os.path
import os
import time
def hook():
try:
if os.path.exists('./hooks.txt') == True:
if os.stat("hooks.txt").st_size == 0:
print("\nNo hooks found. Please add Webhook URLs to the hooks.txt file.")
else:
content = input('Enter what the webhook(s) should send: ')
while True:
for line in open('hooks.txt'):
line = line.strip()
req = requests.post(
line,
json = {
"content": content
}
)
statusCode = str(req.status_code) # Thank you Python for not allowing me to use req.status_code directly
if statusCode.startswith('2') == True:
print('[' + str(req.status_code) + ']' + ' Message successfully sent.')
elif statusCode.startswith('4') == True:
if statusCode == '429':
retry = int(req.headers['retry-after']) / int(1000)
print('\nGetting ratelimited. Retrying in ' + str(retry) + ' seconds.\n')
time.sleep(retry)
else:
print('[' + str(req.status_code) + ']' + ' Message not sent.')
elif os.path.exists('./hooks.txt') == False:
print('\nNo hooks.txt file found. Please create a hooks.txt file and add webhook URLs to it.')
except KeyboardInterrupt:
print('\nExiting...')
exit()
hook()