from redbot.core import commands import discord import requests import htmlwebshot from PIL import Image, ImageOps photographer = htmlwebshot.WebShot() def image(name, html): photographer.create_pic(html=html, output=f"{name}.png") open_image = Image.open(f"{name}.png") image_box = ImageOps.invert(open_image.convert("RGB")).getbox() open_image.crop(image_box).save(f"{name}_cropped.png") class Sarenrae(commands.Cog): def __init__(self, bot): self.bot = bot self.token = None @commands.command() async def ancestry(self, ctx, *args): name = args[0] headers = {"Authorization": self.token} req = requests.get(f"https://api.pathfinder2.fr/v1/pf2/ancestry?name={name}", headers=headers).json() html = req["results"][0]["data"]["description"]["value"] image(html, f"ancestry/{name}") await ctx.send(file=discord.File(open(f"ancestry/{name}.png", "rb"))) @commands.command() async def sarenrae_token(self, ctx, *args): self.token = args[0] return await ctx.send(f"Set token to {self.token}")