Created
September 17, 2023 15:45
-
-
Save st1vms/53b9dc23c37c7a4d186511e11b5f7530 to your computer and use it in GitHub Desktop.
Auto send/delete emoji-reactions from text, for Discord messages.
This file contains hidden or 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 | |
from urllib import parse | |
from time import sleep | |
from emoji_table import EMOJI_TABLE | |
__AUTHTOKEN = "Authentication header value provided by discord, retrievable using browser dev-tools" | |
__COOKIE = "Cookie header value provided by discord, retrievable using browser dev-tools" | |
__USER_AGENT = ( | |
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/117.0" | |
) | |
__BASE_HEADERS = { | |
"Host": "discord.com", | |
"User-Agent": __USER_AGENT, | |
"Accept": "*/*", | |
"Accept-Language": "q=0.8,en-US;q=0.5,en;q=0.3", | |
"Authorization": __AUTHTOKEN, | |
"Origin": "https://discord.com", | |
"DNT": "1", | |
"Alt-Used": "discord.com", | |
"Connection": "keep-alive", | |
"Cookie": __COOKIE, | |
"Sec-Fetch-Dest": "empty", | |
"Sec-Fetch-Mode": "cors", | |
"Sec-Fetch-Site": "same-origin", | |
"Content-Length": "0", | |
"TE": "trailers", | |
} | |
def send_emoji(emoji: str, guild_id: str, channel_id: str, message_id: str) -> bool: | |
headers = __BASE_HEADERS.copy() | |
headers["Referer"] = f"https://discord.com/channels/{guild_id}/{channel_id}" | |
url_encoded_emoji = parse.quote(emoji) | |
URL = "https://discord.com/api/v9/channels/" | |
URL += f"{channel_id}/messages/{message_id}/reactions/{url_encoded_emoji}" | |
URL += "/%40me?location=Message&type=0" | |
res = requests.put(URL, headers=headers) | |
return res.status_code == 204 | |
def remove_emoji(emoji: str, guild_id: str, channel_id: str, message_id: str) -> bool: | |
headers = __BASE_HEADERS.copy() | |
headers["Referer"] = f"https://discord.com/channels/{guild_id}/{channel_id}" | |
url_encoded_emoji = parse.quote(emoji) | |
DELETE_URL = "https://discord.com/api/v9/channels/" | |
DELETE_URL += f"{channel_id}/messages/{message_id}/reactions/{url_encoded_emoji}" | |
DELETE_URL += "/0/%40me?location=Message&burst=false" | |
res = requests.delete(DELETE_URL, headers=headers) | |
return res.status_code == 204 | |
def text_to_emoji_list(text: str) -> list[str]: | |
d = {k: len(v) for k, v in EMOJI_TABLE.items()} | |
res = [] | |
for c in text: | |
c = c.lower() | |
if not c in EMOJI_TABLE: | |
continue | |
if d[c] > 0: | |
res.append(EMOJI_TABLE[c][d[c] % len(EMOJI_TABLE[c])]) | |
d[c] -= 1 | |
return res | |
def __main(): | |
guild_id = input("\nInsert Guild ID\n>>").strip() | |
channel_id = input("\nInsert Channel ID\n>>").strip() | |
while True: | |
message_id = input("\nInsert Message ID\n>>").strip() | |
del_mode = False | |
if "y" == input("\nDelete emojis? (N/y)\n>>").strip().lower(): | |
del_mode = True | |
text = input("\nInsert text\n>>").strip() | |
if not text: | |
print("\nInvalid choice...") | |
continue | |
emojis = text_to_emoji_list(text) | |
for emoji in emojis: | |
if del_mode: | |
print("Removing emoji...", end="\r") | |
remove_emoji(emoji, guild_id, channel_id, message_id) | |
else: | |
print("Sending emoji...", end="\r") | |
send_emoji(emoji, guild_id, channel_id, message_id) | |
sleep(0.5) | |
if __name__ == "__main__": | |
try: | |
__main() | |
except KeyboardInterrupt: | |
pass | |
print("\nClosing...") |
This file contains hidden or 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
EMOJI_TABLE = { | |
"a":("🇦","🅰️"), | |
"b":("🇧","🅱️"), | |
"c":("🇨","©️",), | |
"d":("🇩",), | |
"e":("🇪",), | |
"f":("🇫",), | |
"g":("🇬",), | |
"h":("🇭",), | |
"i":("🇮","ℹ️"), | |
"j":("🇯",), | |
"k":("🇰",), | |
"l":("🇱",), | |
"m":("🇲","Ⓜ️"), | |
"n":("🇳",), | |
"o":("🇴","⭕", "🅾️",), | |
"p":("🇵","🅿️"), | |
"q":("🇶",), | |
"r":("🇷","®️",), | |
"s":("🇸",), | |
"t":("🇹",), | |
"u":("🇺",), | |
"v":("🇻",), | |
"w":("🇼",), | |
"x":("🇽","❌","❎","✖️"), | |
"y":("🇾",), | |
"z":("🇿",), | |
"0":("0️⃣",), | |
"1":("1️⃣",), | |
"2":("2️⃣",), | |
"3":("3️⃣",), | |
"4":("4️⃣",), | |
"5":("5️⃣",), | |
"6":("6️⃣",), | |
"7":("7️⃣",), | |
"8":("8️⃣",), | |
"9":(" 9️⃣",), | |
"!":("❕", "❗",), | |
"?":("❔", "❓",), | |
"*":("*️⃣",), | |
"+":("➕",), | |
"-":("➖",), | |
"/":("➗",), | |
"=":("🟰",), | |
"#":("#️⃣",), | |
"$":("💲",), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment