Last active
June 30, 2021 23:32
-
-
Save IlluminatiFish/50e0ff7210f6e7408b59d32ddc459021 to your computer and use it in GitHub Desktop.
A little class to terminate those pesky token loggers that exist unfortunately in the discord community
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, pprint, json, base64, magic | |
class Nuker: | |
def __init__(self, webhook_url): | |
chunks = webhook_url.split("/") | |
self.webhook_id = chunks[5] | |
self.webhook_token = chunks[6] | |
self.headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2729.17 Safari/537.36."} | |
def is_webhook_alive(self): | |
response = requests.get(f"https://discord.com/api/webhooks/{self.webhook_id}/{self.webhook_token}", headers=self.headers) | |
return response.status_code < 300 | |
def scrape_webhook(self): | |
response = requests.get(f"https://discord.com/api/webhooks/{self.webhook_id}/{self.webhook_token}", | |
headers=self.headers) | |
if response.status_code == 200: | |
pprint.pprint(response.json()) | |
else: | |
print(f"[SCRAPER] Scraping info on the webhook failed with {response.status_code}") | |
def modify_webhook(self, raw_data: dict): | |
if not raw_data: | |
print( | |
"[MODIFIER] You must give a dictionary of items you would like to change, refer to the discord documentation if you do not know what this means.") | |
return | |
modified_data = json.dumps(raw_data) | |
self.headers["Content-Type"] = "application/json" | |
response = requests.patch(f"https://discord.com/api/webhooks/{self.webhook_id}/{self.webhook_token}", | |
headers=self.headers, data=modified_data) | |
pprint.pprint(response.json()) | |
if response.status_code == 200: | |
print("[*] Modifications have been applied, enjoy spooking the cunts") | |
else: | |
print(f"[MODIFIER] Unknown error occurred with status code {response.status_code}") | |
def delete_webhook(self): | |
response = requests.delete(f"https://discord.com/api/webhooks/{self.webhook_id}/{self.webhook_token}", | |
headers=self.headers) | |
if response.status_code != 204: | |
print(f"[DELETER] Unknown error occurred with status code {response.status_code}") | |
return | |
print(f"[*] Deleted webhook with token {self.webhook_token} and id {self.webhook_id}") | |
def send_webhook_message(self, message: str = None, ping_type: str = None, footer_image: str = None): | |
if not message: | |
print("[MESSENGER] Please supply a message you would like to send") | |
return | |
content = message | |
if ping_type: | |
if ping_type != "everyone" and ping_type != "here": | |
print(f"[MESSENGER] Unfortunately we cannot ping {ping_type} we only support everyone and here pings") | |
return | |
content += ('||\u200b||' * 200) + "@" + ping_type | |
if footer_image: | |
if not ping_type: | |
content += ('||\u200b||' * 200) + footer_image | |
content += footer_image | |
json_data = json.dumps({"content": content}) | |
self.headers["Content-Type"] = "application/json" | |
response = requests.post(f"https://discord.com/api/webhooks/{self.webhook_id}/{self.webhook_token}", | |
headers=self.headers, data=json_data) | |
if response.status_code != 204: | |
print(f"[MESSENGER] Unknown error occurred with status code {response.status_code}") | |
return | |
print( | |
f"[*] Sent your message with your footer image to webhook with token {self.webhook_token} and id {self.webhook_id}") | |
def create_base64_image_uri(self, image_url): | |
response = requests.get(image_url, headers=self.headers) | |
content_type = response.headers.get("Content-Type", None) | |
# Reference: https://stackoverflow.com/a/43049834 | |
content_mimetype = content_type.split(";")[0] | |
magician = magic.Magic(mime=True) | |
true_mimetype = magician.from_buffer(response.content) | |
# If the content types are not the same, trust the mimetype from the python-magic library instead of the server | |
if str(true_mimetype) != str(content_mimetype): | |
content_type = true_mimetype | |
if not content_type.startswith("image"): | |
return | |
encoded_image = base64.b64encode(response.content) | |
avatar_uri = f"data:{content_type};base64,{encoded_image.decode()}" | |
return avatar_uri | |
################################################################################################################################# | |
# NOTE: All the functions only work on a webhook urls that includes the webhook id (the number) ex. 859232011122507754 in them # | |
# # | |
# Usage: # | |
# Set the Nuker class to a variable and pass the target webhook url as a paramter to it # | |
# i.e. nuker = Nuker(<webhook url>) # | |
# # | |
# Then you can freely use the methods below to your heart's content: # | |
# # | |
# scrape_webhook() - Scrapes data about the webhook # | |
# modify_webhook({"name": "modified name", "avatar": "avatar_uri"}) - Modifies the name and avatar of the webhook # | |
# delete_webhook() - Deletes the webhook # | |
# is_webhook_alive() - Checks whether the webhook is even alive # | |
# create_base64_image_uri(url) - Creates a base64 URI for the image from the URL provided # | |
################################################################################################################################# | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
first