diff --git a/sarenrae/sarenrae.py b/sarenrae/sarenrae.py index f7a3ac6..776979f 100644 --- a/sarenrae/sarenrae.py +++ b/sarenrae/sarenrae.py @@ -27,12 +27,33 @@ class Sarenrae(commands.Cog): } 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() async def ancestry(self, ctx, *args): - name = args[0] - headers = {"Authorization": await self.conf.token()} - req = requests.get(f"https://api.pathfinder2.fr/v1/pf2/ancestry?name={name}", headers=headers).json() - html = req["results"][0]["data"]["description"]["value"] + name = ' '.join(args) + html = self.api_ping("ancestry", name) + await ctx.send(file=discord.File(image(html), filename=f"{name}.jpg")) + + @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")) @commands.command()