Sarenrae initial commit

This commit is contained in:
skins 2021-09-01 20:15:09 +01:00
parent 0a7c30c9c3
commit 82060de182
3 changed files with 52 additions and 1 deletions

16
sarenrae/__init__.py Normal file
View File

@ -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)

35
sarenrae/sarenrae.py Normal file
View File

@ -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}")

View File

@ -1,5 +1,5 @@
{
"name": "Dice",
"name": "Tiamat",
"author": [
"skins (skins#6969)"
],