MsRewards-Reborn/V7/logger.py

28 lines
1010 B
Python

from playwright.sync_api import Page
from discord import Colour, Embed, File, RequestsWebhookAdapter, Webhook
class Logger:
def __init__(self, link):
self.wh = Webhook.from_url(link, adapter=RequestsWebhookAdapter())
def error(self, page: Page, error: str):
with open("page.html", "w") as f:
try:
f.write(page.content())
except Exception as e:
f.write(f"the driver has closed or crashed. Can't access page content\n{e}")
embed = Embed(
title="An Error has occurred",
description=str(error),
colour=Colour.red(),
)
try:
page.screenshot(path="screenshot.png")
except Exception as e:
with open("screenshot.png", "w") as f:
f.write(f"Can't take screenshot\n{e}")
file = File("screenshot.png")
embed.set_image(url="attachment://screenshot.png")
self.wh.send(embed=embed, username="error", file=file)