Sarenrae initial commit
This commit is contained in:
parent
0a7c30c9c3
commit
82060de182
16
sarenrae/__init__.py
Normal file
16
sarenrae/__init__.py
Normal 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
35
sarenrae/sarenrae.py
Normal 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}")
|
||||||
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "Dice",
|
"name": "Tiamat",
|
||||||
"author": [
|
"author": [
|
||||||
"skins (skins#6969)"
|
"skins (skins#6969)"
|
||||||
],
|
],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user