Compare commits

..

No commits in common. "dd769ae19c233d4c25aea328784be6c4ddd50ee1" and "735f1b057d347d5ebb43c70a203c772681bc04dd" have entirely different histories.

2 changed files with 11 additions and 15 deletions

View File

@ -9,7 +9,7 @@
"requirements": [ "requirements": [
"requests", "requests",
"pillow", "pillow",
"imgkit" "htmlwebshot"
], ],
"tags": [ "tags": [
"gaming", "gaming",

View File

@ -1,16 +1,16 @@
from redbot.core import commands, Config, checks from redbot.core import commands
import discord import discord
import requests import requests
import imgkit import htmlwebshot
from PIL import Image, ImageOps from PIL import Image, ImageOps
import os import os
UID = 0x181eff7aacab91fa4051d1d995d44050 photographer = htmlwebshot.WebShot()
def image(name, html): def image(name, html):
open_image = imgkit.from_string(html, False) photographer.create_pic(html=html, output=f"{name}.png")
open_image = Image.open(open_image) open_image = Image.open(f"{name}.png")
image_box = ImageOps.invert(open_image.convert("RGB")).getbbox() image_box = ImageOps.invert(open_image.convert("RGB")).getbbox()
open_image.crop(image_box).save(f"{name}_cropped.png") open_image.crop(image_box).save(f"{name}_cropped.png")
@ -18,16 +18,12 @@ def image(name, html):
class Sarenrae(commands.Cog): class Sarenrae(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
self.conf = Config.get_conf(self, identifier=UID, force_registration=True) self.token = None
default_global = {
"pf2_token": "",
}
self.conf.register_global(**default_global)
@commands.command() @commands.command()
async def ancestry(self, ctx, *args): async def ancestry(self, ctx, *args):
name = args[0] name = args[0]
headers = {"Authorization": self.conf.pf2_token} headers = {"Authorization": self.token}
req = requests.get(f"https://api.pathfinder2.fr/v1/pf2/ancestry?name={name}", headers=headers).json() req = requests.get(f"https://api.pathfinder2.fr/v1/pf2/ancestry?name={name}", headers=headers).json()
html = req["results"][0]["data"]["description"]["value"] html = req["results"][0]["data"]["description"]["value"]
filename = f"ancestry-{name}" filename = f"ancestry-{name}"
@ -36,8 +32,8 @@ class Sarenrae(commands.Cog):
os.remove(f"{filename}.png") os.remove(f"{filename}.png")
os.remove(f"{filename}_cropped.png") os.remove(f"{filename}_cropped.png")
@commands.command() @commands.command()
@checks.is_owner()
async def sarenrae_token(self, ctx, *args): async def sarenrae_token(self, ctx, *args):
self.conf.pf2_token.set(args[0]) self.token = args[0]
return await ctx.send(f"Set token to {self.conf.pf2_token}") return await ctx.send(f"Set token to {self.token}")