-
Notifications
You must be signed in to change notification settings - Fork 0
/
Webhooker.py
69 lines (54 loc) · 2.13 KB
/
Webhooker.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
from urllib.parse import urlparse
import requests
allowed_domains = ["discord.com", "*.discord.com"]
while True:
webhook_url = input("Paste Discord webhook URL here: ").strip()
# Add default scheme if missing
if not webhook_url.startswith(("http://", "https://")):
webhook_url = "https://" + webhook_url
# Parse the URL
parsed_url = urlparse(webhook_url)
domain = parsed_url.netloc.replace("www.", "").replace("https://", "")
# Check if the domain is in the allowed_domains list
if any(domain.endswith(allowed) for allowed in allowed_domains):
break
else:
print("Invalid URL. Only Discord URLs are allowed.")
username = input("What should the webhook name be? ").strip()
default_avatar_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Python-logo-notext.svg/935px-Python-logo-notext.svg.png"
avatar_url = input("Paste link to pfp image (or press Enter for default): ").strip()
if not avatar_url:
avatar_url = default_avatar_url
content = input("What should message content be? ").strip()
while True:
if avatar_url.endswith((".jpg", ".jpeg", ".png", ".gif")):
break
else:
print("Invalid URL", avatar_url)
while True:
confirmation = input(
"Is this correct?\n username: {}\n Profile image URL: {}\n message: {}\n yes or no? ".format(
username, avatar_url, content)).strip().lower()
if confirmation.startswith("y"):
print("Okay, pinging webhook...")
# request code here
data = {
"username": username,
"avatar_url": avatar_url,
"content": content,
}
response = requests.post(webhook_url, json=data)
if response.status_code == 204:
print("Webhook sent successfully!")
else:
print("Failed to send the webhook.")
print("Response status code:", response.status_code)
print("Response text:", response.text)
break
elif confirmation.startswith("n"):
print("Okay, cancelling...")
exit()
else:
print("Invalid input. Please enter 'yes' or 'no?'")
continue
exit()