diff --git a/tiamat/__init__.py b/tiamat/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tiamat/tiamat.py b/tiamat/tiamat.py new file mode 100644 index 0000000..3dc0d79 --- /dev/null +++ b/tiamat/tiamat.py @@ -0,0 +1,33 @@ +from redbot.core import commands +import discord +import requests + +class Tiamat(commands.Cog): + """ Get information from D&D 5e's srd """ + + def __init__(self, bot): + self.bot = bot + + def monster(self, ctx, *args): + name = '-'.join(args).lower() + data = requests.get(f"https://www.dnd5eapi.co/api/monsters/{name}").json() + if "error" in data: + await ctx.send(f"{' '.join(args)} not found, check that the name is spelled right and that the creature " + f"is in the System Reference Document") + else: + initial_embed = discord.Embed(title=data["name"]) + for ability in ["strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma"]: + initial_embed.add_field(name=ability, value=data[ability], inline=True) + initial_embed.add_field(name="AC", value=data["armor_class"]) + attack_embed = discord.Embed(title="Actions") + for action in data["actions"]: + attack_embed.add_field(name=action["name"], value=action["desc"]) + legendary_embed = None + if "legendary_actions" in data: + legendary_embed = discord.Embed(title="Legendary Actions") + for action in data["legendary_actions"]: + legendary_embed.add_field(name=action["name"], value=action["desc"]) + await ctx.send(initial_embed) + await ctx.send(attack_embed) + if legendary_embed is not None: + await ctx.send(legendary_embed)