Sarenrae: Add action, spell, and item commands

This commit is contained in:
skins 2021-09-01 21:51:41 +01:00
parent 961c65642e
commit bb8cc3eb68

View File

@ -27,12 +27,33 @@ class Sarenrae(commands.Cog):
} }
self.conf.register_global(**default_global) self.conf.register_global(**default_global)
async def api_ping(self, category, name):
headers = {"Authorization": await self.conf.token()}
req = requests.get(f"https://api.pathfinder2.fr/v1/pf2/{category}?name={name}", headers=headers).json()
return req["results"][0]["data"]["description"]["value"]
@commands.command() @commands.command()
async def ancestry(self, ctx, *args): async def ancestry(self, ctx, *args):
name = args[0] name = ' '.join(args)
headers = {"Authorization": await self.conf.token()} html = self.api_ping("ancestry", name)
req = requests.get(f"https://api.pathfinder2.fr/v1/pf2/ancestry?name={name}", headers=headers).json() await ctx.send(file=discord.File(image(html), filename=f"{name}.jpg"))
html = req["results"][0]["data"]["description"]["value"]
@commands.command()
async def action(self, ctx, *args):
name = ' '.join(args)
html = self.api_ping("action", name)
await ctx.send(file=discord.File(image(html), filename=f"{name}.jpg"))
@commands.command()
async def spell(self, ctx, *args):
name = ' '.join(args)
html = self.api_ping("spell", name)
await ctx.send(file=discord.File(image(html), filename=f"{name}.jpg"))
@commands.command()
async def item(self, ctx, *args):
name = ' '.join(args)
html = self.api_ping("equipment", name)
await ctx.send(file=discord.File(image(html), filename=f"{name}.jpg")) await ctx.send(file=discord.File(image(html), filename=f"{name}.jpg"))
@commands.command() @commands.command()