Sarenrae: permanent storage of tokens
This commit is contained in:
parent
735f1b057d
commit
a67c5eb4d6
@ -1,16 +1,16 @@
|
|||||||
from redbot.core import commands
|
from redbot.core import commands, Config, checks
|
||||||
import discord
|
import discord
|
||||||
import requests
|
import requests
|
||||||
import htmlwebshot
|
import imgkit
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image, ImageOps
|
||||||
import os
|
import os
|
||||||
|
|
||||||
photographer = htmlwebshot.WebShot()
|
UID = 0x181eff7aacab91fa4051d1d995d44050
|
||||||
|
|
||||||
|
|
||||||
def image(name, html):
|
def image(name, html):
|
||||||
photographer.create_pic(html=html, output=f"{name}.png")
|
open_image = imgkit.from_string(html, False)
|
||||||
open_image = Image.open(f"{name}.png")
|
open_image = Image.open(open_image)
|
||||||
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,12 +18,16 @@ 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.token = None
|
self.conf = Config.get_conf(self, identifier=UID, force_registration=True)
|
||||||
|
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.token}
|
headers = {"Authorization": self.conf.pf2_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}"
|
||||||
@ -32,8 +36,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.token = args[0]
|
self.conf.pf2_token.set(args[0])
|
||||||
return await ctx.send(f"Set token to {self.token}")
|
return await ctx.send(f"Set token to {self.conf.pf2_token}")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user