Sarenrae: Fix error with image creation

This commit is contained in:
skins 2021-09-01 20:46:41 +01:00
parent 54cdc26137
commit 735f1b057d

View File

@ -3,6 +3,7 @@ import discord
import requests
import htmlwebshot
from PIL import Image, ImageOps
import os
photographer = htmlwebshot.WebShot()
@ -10,7 +11,7 @@ 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()
image_box = ImageOps.invert(open_image.convert("RGB")).getbbox()
open_image.crop(image_box).save(f"{name}_cropped.png")
@ -25,11 +26,14 @@ class Sarenrae(commands.Cog):
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(f"ancestry/{name}", html)
filename = f"ancestry-{name}"
image(filename, html)
await ctx.send(file=discord.File(open(f"ancestry/{name}.png", "rb")))
os.remove(f"{filename}.png")
os.remove(f"{filename}_cropped.png")
@commands.command()
async def sarenrae_token(self, ctx, *args):
self.token = args[0]
return await ctx.send(f"Set token to {self.token}")