Myphz/sortvisualizer

Hastebin and capturing images of the users screen?

TheConsciousness opened this issue · 0 comments

May I ask the purpose of the code in these locations?

snippet.py

def get_img(msg):
	chrome_options = webdriver.ChromeOptions()

	chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
	chrome_options.add_argument('--disable-dev-shm-usage')
	chrome_options.add_argument('--no-sandbox')
	chrome_options.add_argument("--headless")
	chrome_options.add_argument('window-size=2560x10000')
	driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), chrome_options=chrome_options)

	driver.maximize_window()

	base64_string = base64.b64encode(msg.encode("ascii"))
	base64_string = base64_string.decode("ascii").replace("+", "%2B")

	driver.get(f"https://ray.so/?code={base64_string}&background=true&darkMode=true&colors=breeze&padding=64&title=Code&language=javascript")

	driver.execute_script("document.querySelector('section.controls').remove();")

	ret = driver.find_element_by_class_name("drag-control-points").screenshot_as_png
	driver.quit()
	return ret

app.py

TELEGRAM_KEY = os.environ.get("TELEGRAM_KEY")
CHAT_ID = -1001520685235

bot = None
try:
    bot = Bot(TELEGRAM_KEY)
except Exception as e:
    print("Telegram bot couldn't start", e)

...

@app.route("/submit/", methods=["POST"])
@limiter.limit("5/hour")
def submit():
    code = request.json["code"]

    image = get_img(code)
    req = requests.post('https://hastebin.com/documents', data=code)

    if bot: bot.send_document(chat_id=CHAT_ID, document=image, filename="New Submission", caption=f'https://hastebin.com/{req.json()["key"]}')

    return "", 204