From 82060de182adfcc1d49153e2e52e5ff9c45d0244 Mon Sep 17 00:00:00 2001 From: skins Date: Wed, 1 Sep 2021 20:15:09 +0100 Subject: [PATCH] Sarenrae initial commit --- sarenrae/__init__.py | 16 ++++++++++++++++ sarenrae/sarenrae.py | 35 +++++++++++++++++++++++++++++++++++ tiamat/info.json | 2 +- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 sarenrae/__init__.py create mode 100644 sarenrae/sarenrae.py diff --git a/sarenrae/__init__.py b/sarenrae/__init__.py new file mode 100644 index 0000000..4cc7bee --- /dev/null +++ b/sarenrae/__init__.py @@ -0,0 +1,16 @@ +"""Package for Dice cog.""" +import json +from pathlib import Path + +from redbot.core.bot import Red + +from .sarenrae import Sarenrae + +with open(Path(__file__).parent / "info.json") as fp: + __red_end_user_data_statement__ = json.load(fp)["end_user_data_statement"] + + +def setup(bot: Red) -> None: + """Load Dice cog.""" + cog = Sarenrae(bot) + bot.add_cog(cog) diff --git a/sarenrae/sarenrae.py b/sarenrae/sarenrae.py new file mode 100644 index 0000000..e450012 --- /dev/null +++ b/sarenrae/sarenrae.py @@ -0,0 +1,35 @@ +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}") + diff --git a/tiamat/info.json b/tiamat/info.json index 8bce27d..94a4b31 100644 --- a/tiamat/info.json +++ b/tiamat/info.json @@ -1,5 +1,5 @@ { - "name": "Dice", + "name": "Tiamat", "author": [ "skins (skins#6969)" ],