from discord import Embed, Colour, File from modules.Classes.Config import Config from modules.Tools.logger import error from modules.Tools.tools import format_error class DiscordLogger: def __init__(self, config: Config): self.config = config def send(self, message: str): driver = self.config.WebDriver.driver if type(message) is not str: message = format_error(message) error(message) with open("page.html", "w") as f: try: f.write(driver.page_source) except Exception as e: error(e) f.write("the driver has closed or crashed. Can't access page content") img = self.config.display.waitgrab() img.save("screenshot.png") embed = Embed( title="An Error has occurred", description=str(message), colour=Colour.red(), ) file = File("screenshot.png") embed.set_image(url="attachment://screenshot.png") embed.set_footer(text=self.config.UserCredentials.get_mail() + " - " + self.config.WebDriver.current_driver()) self.config.discord.wh.send(embed=embed, username="error", file=file, avatar_url=self.config.discord.avatar_url) self.config.discord.wh.send(username="error", file=File("page.html"), avatar_url=self.config.discord.avatar_url)