Created
June 28, 2021 20:15
-
-
Save pagpeter/a117ffc1bdae1f296ee9379815c00112 to your computer and use it in GitHub Desktop.
A small script to exploit discord embeds to get data about a name from NameMC.
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 discord | |
import asyncio | |
from threading import Thread | |
from discord_webhook import DiscordWebhook | |
from time import sleep | |
from flask import Flask, jsonify | |
from datetime import datetime | |
WEBHOOK = "<webhook>" | |
TOKEN = "<bot-token>" | |
data = [] | |
def requestThread(): | |
global data | |
sleep(3) | |
app = Flask(__name__) | |
@app.route('/<name>') | |
def getData(name): | |
try: | |
sendWebhook(name) | |
sleep(1.2) | |
droptime = -1 | |
if bool(data[1]): | |
droptime = datetime.strptime(data[1],"%Y-%m-%dT%H:%M:%Sz").timestamp() | |
return jsonify({"name": data[2], "dropping": bool(data[1]), "droptime": data[1], "unix": droptime, "searches": data[0]}) | |
except Exception: | |
return jsonify({"error": Exception}) | |
app.run() | |
def parseData(data: str): | |
searches = data.split("Searches: ")[1].split(" ")[0] | |
drop = None | |
if data.find("Time of Availability") != -1: | |
drop = data.split("Availability: ")[1].split(",")[0] | |
return searches, drop | |
def sendWebhook(name: str): | |
DiscordWebhook(url=WEBHOOK, content=f"https://namemc.com/name/{name}").execute() | |
class MyClient(discord.Client): | |
async def on_ready(self): | |
print('Logged on as', self.user) | |
async def on_message(self, message): | |
global data | |
# don't respond to ourselves | |
if message.author == self.user: | |
return | |
if message.content.startswith("https://namemc.com/name/"): | |
await asyncio.sleep(1) | |
if len(message.embeds) != 1: | |
print("Error! No embed found") | |
return | |
searches, drop = parseData(message.embeds[0].description) | |
name = message.content.replace("https://namemc.com/name/", "") | |
data = [searches, drop, name] | |
# await message.channel.send("Searches: {}\nDroptime: {}\nName: {}".format(searches, drop, name)) | |
Thread(target=requestThread).start() | |
client = MyClient() | |
client.run(TOKEN) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment