79 lines
4.4 KiB
Python
79 lines
4.4 KiB
Python
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
|
|
|
|
@commands.command()
|
|
async 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"])
|
|
initial_embed.add_field(name="HP", value=data["hit_points"])
|
|
initial_embed.add_field(name="AC", value=data["armor_class"])
|
|
for ability in ["strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma"]:
|
|
initial_embed.add_field(name=ability, value=data[ability], inline=True)
|
|
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(embed=initial_embed)
|
|
await ctx.send(embed=attack_embed)
|
|
if legendary_embed is not None:
|
|
await ctx.send(embed=legendary_embed)
|
|
|
|
@commands.command()
|
|
async def spell(self, ctx, *args):
|
|
name = '-'.join(args).lower()
|
|
data = requests.get(f"https://www.dnd5eapi.co/api/spells/{name}").json()
|
|
if "error" in data:
|
|
await ctx.send(f"{' '.join(args)} not found, check that the name is spelled right and that the spell "
|
|
f"is in the System Reference Document")
|
|
else:
|
|
embed = discord.Embed(title=data["name"])
|
|
embed.add_field(name="Level", value=data["level"], inline=True)
|
|
embed.add_field(name="Range", value=data["range"], inline=True)
|
|
embed.add_field(name="Components", value=', '.join(data["components"]), inline=False)
|
|
if "material" in data:
|
|
embed.add_field(name="Material Components", value=data["material"], inline=False)
|
|
embed.add_field(name="Description", value=data["desc"][0], inline=False)
|
|
embed.add_field(name="Upcasting", value=data["higher_level"][0], inline=False)
|
|
embed.add_field(name="School", value=data["school"]["name"], inline=True)
|
|
embed.add_field(name="Ritual", value=data["ritual"], inline=True)
|
|
embed.add_field(name="Classes", value=', '.join(i["name"] for i in data["classes"]), inline=False)
|
|
embed.add_field(name="Subclasses", value=', '.join(i["name"] for i in data["subclasses"]), inline=False)
|
|
await ctx.send(embed=embed)
|
|
|
|
@commands.command()
|
|
async def armour(self, ctx, *args):
|
|
name = '-'.join(args).lower().replace("-armor", "").replace("-armour", "")
|
|
data = requests.get(f"https://www.dnd5eapi.co/api/equipment/{name}").json()
|
|
if "error" in data:
|
|
await ctx.send(f"{' '.join(args)} not found, check that the name is spelled right and that the spell "
|
|
f"is in the System Reference Document")
|
|
try:
|
|
embed = discord.Embed(title=data["name"])
|
|
embed.add_field(name="Category", value=data["armor_category"], inline=False)
|
|
embed.add_field(name="Base", value=data["armor_class"]["base"], inline=True)
|
|
if data["armor_class"]["max_bonus"] is not None:
|
|
embed.add_field(name="Max Dex Bonus", value=data["armor_class"]["max_bonus"], inline=True)
|
|
embed.add_field(name="Cost", value=f"""{data["cost"]["quantity"]} {data["cost"]["unit"]}""", inline=True)
|
|
embed.add_field(name="Strength Minimum", value=data["str_minimum"], inline=True)
|
|
embed.add_field(name="Stealth Disadvantage", value=data["stealth_disadvantage"], inline=True)
|
|
embed.add_field(name="Weight", value=data["weight"], inline=True)
|
|
await ctx.send(embed=embed)
|
|
except KeyError:
|
|
await ctx.send("Error: item is not armour")
|