✨ Converted all lookup functionality to slash commands
This commit is contained in:
@ -1,9 +1,7 @@
|
|||||||
import discord, json
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord_slash import cog_ext
|
from discord_slash import cog_ext
|
||||||
from discord_slash import SlashCommandOptionType as scot
|
|
||||||
|
|
||||||
from utils import getParams, cap
|
from utils import getParams
|
||||||
|
|
||||||
params = getParams()
|
params = getParams()
|
||||||
|
|
||||||
@ -15,58 +13,12 @@ class LookupCog(commands.Cog):
|
|||||||
# Looks up a spell
|
# Looks up a spell
|
||||||
@cog_ext.cog_slash(**params["spell"])
|
@cog_ext.cog_slash(**params["spell"])
|
||||||
async def spell(self, ctx, query):
|
async def spell(self, ctx, query):
|
||||||
spell = self.bot.lookupFuncs.spellFunc(cap(query))
|
await self.bot.lookupFuncs.spellFunc(ctx, query)
|
||||||
if len(spell) > 2000:
|
|
||||||
await ctx.send(spell[:2000])
|
|
||||||
await ctx.send(spell[2000:])
|
|
||||||
else:
|
|
||||||
await ctx.send(spell)
|
|
||||||
|
|
||||||
# Looks up a monster
|
# Looks up a monster
|
||||||
@cog_ext.cog_slash(**params["monster"])
|
@cog_ext.cog_slash(**params["monster"])
|
||||||
async def monster(self, ctx, query):
|
async def monster(self, ctx, query):
|
||||||
title, text1, text2, text3, text4, text5 = self.bot.lookupFuncs.monsterFunc(cap(query))
|
await self.bot.lookupFuncs.monsterFunc(ctx, query)
|
||||||
em1 = discord.Embed(title = title, description = text1, colour=0xDEADBF)
|
|
||||||
|
|
||||||
# Sends the received information. Separates into separate messages if
|
|
||||||
# there is too much text
|
|
||||||
await ctx.send(embed = em1)
|
|
||||||
if text2 != "":
|
|
||||||
if len(text2) < 2048:
|
|
||||||
em2 = discord.Embed(title = "Special Abilities", description = text2, colour=0xDEADBF)
|
|
||||||
await ctx.send(embed = em2)
|
|
||||||
else:
|
|
||||||
em2 = discord.Embed(title = "Special Abilities", description = text2[:2048], colour=0xDEADBF)
|
|
||||||
await ctx.send(embed = em2)
|
|
||||||
em2_2 = discord.Embed(title = "", description = text2[2048:], colour=0xDEADBF)
|
|
||||||
await ctx.send(embed = em2_2)
|
|
||||||
if text3 != "":
|
|
||||||
if len(text3) < 2048:
|
|
||||||
em3 = discord.Embed(title = "Actions", description = text3, colour=0xDEADBF)
|
|
||||||
await ctx.send(embed = em3)
|
|
||||||
else:
|
|
||||||
em3 = discord.Embed(title = "Actions", description = text3[:2048], colour=0xDEADBF)
|
|
||||||
await ctx.send(embed = em3)
|
|
||||||
em3_2 = discord.Embed(title = "", description = text3[2048:], colour=0xDEADBF)
|
|
||||||
await ctx.send(embed = em3_2)
|
|
||||||
if text4 != "":
|
|
||||||
if len(text4) < 2048:
|
|
||||||
em4 = discord.Embed(title = "Reactions", description = text4, colour=0xDEADBF)
|
|
||||||
await ctx.send(embed = em4)
|
|
||||||
else:
|
|
||||||
em4 = discord.Embed(title = "Reactions", description = text4[:2048], colour=0xDEADBF)
|
|
||||||
await ctx.send(embed = em4)
|
|
||||||
em4_2 = discord.Embed(title = "", description = text4[2048:], colour=0xDEADBF)
|
|
||||||
await ctx.send(embed = em4_2)
|
|
||||||
if text5 != "":
|
|
||||||
if len(text5) < 2048:
|
|
||||||
em5 = discord.Embed(title = "Legendary Actions", description = text5, colour=0xDEADBF)
|
|
||||||
await ctx.send(embed = em5)
|
|
||||||
else:
|
|
||||||
em5 = discord.Embed(title = "Legendary Actions", description = text5[:2048], colour=0xDEADBF)
|
|
||||||
await ctx.send(embed = em5)
|
|
||||||
em5_2 = discord.Embed(title = "", description = text5[2048:], colour=0xDEADBF)
|
|
||||||
await ctx.send(embed = em5_2)
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(LookupCog(bot))
|
bot.add_cog(LookupCog(bot))
|
@ -1,5 +1,6 @@
|
|||||||
import math
|
import math
|
||||||
import json
|
import json
|
||||||
|
import discord
|
||||||
|
|
||||||
from utils import cap
|
from utils import cap
|
||||||
|
|
||||||
@ -18,27 +19,28 @@ class LookupFuncs():
|
|||||||
return(str(mods))
|
return(str(mods))
|
||||||
|
|
||||||
# Looks up a monster
|
# Looks up a monster
|
||||||
def monsterFunc(self, command):
|
async def monsterFunc(self, ctx, query):
|
||||||
self.bot.log("Looking up "+command)
|
query = cap(query)
|
||||||
|
self.bot.log("Looking up "+query)
|
||||||
|
|
||||||
# 1-letter monsters don't exist
|
# 1-letter monsters don't exist
|
||||||
if len(command) < 2:
|
if len(query) < 2:
|
||||||
self.bot.log("Monster name too short (error code 601)")
|
self.bot.log("Monster name too short")
|
||||||
return("I don't know that monster... (error code 601)","","","","","")
|
await ctx.send("I don't know that monster...")
|
||||||
else:
|
else:
|
||||||
# Opens "monsters.json"
|
# Opens "monsters.json"
|
||||||
data = json.load(open('resources/lookup/monsters.json', encoding = "utf8"))
|
data = json.load(open('resources/lookup/monsters.json', encoding = "utf8"))
|
||||||
for monster in data:
|
for monster in data:
|
||||||
if "name" in monster and str(command) == monster["name"]:
|
if "name" in monster and str(query) == monster["name"]:
|
||||||
self.bot.log("Found it!")
|
self.bot.log("Found it!")
|
||||||
|
|
||||||
# Looks at the information about the monster and returns that information
|
# Looks at the information about the monster and returns that information
|
||||||
# in separate variables, allowing Gwendolyn to know where to separate
|
# in separate variables, allowing Gwendolyn to know where to separate
|
||||||
# the messages
|
# the messages
|
||||||
if monster["subtype"] != "":
|
if monster["subtype"] != "":
|
||||||
typs = (monster["type"]+" ("+monster["subtype"]+")")
|
types = (monster["type"]+" ("+monster["subtype"]+")")
|
||||||
else:
|
else:
|
||||||
typs = monster["type"]
|
types = monster["type"]
|
||||||
con_mod = math.floor((monster["constitution"]-10)/2)
|
con_mod = math.floor((monster["constitution"]-10)/2)
|
||||||
hit_dice = monster["hit_dice"]
|
hit_dice = monster["hit_dice"]
|
||||||
|
|
||||||
@ -80,10 +82,10 @@ class LookupFuncs():
|
|||||||
if c_immunities != "":
|
if c_immunities != "":
|
||||||
c_immunities = "\n**Condition Immunities** "+c_immunities
|
c_immunities = "\n**Condition Immunities** "+c_immunities
|
||||||
|
|
||||||
spec_ab = ""
|
specialAbilities = ""
|
||||||
if "special_abilities" in monster:
|
if "special_abilities" in monster:
|
||||||
for ability in monster["special_abilities"]:
|
for ability in monster["special_abilities"]:
|
||||||
spec_ab += "\n\n***"+ability["name"]+".*** "+ability["desc"]
|
specialAbilities += "\n\n***"+ability["name"]+".*** "+ability["desc"]
|
||||||
|
|
||||||
act = ""
|
act = ""
|
||||||
if "actions" in monster:
|
if "actions" in monster:
|
||||||
@ -95,10 +97,10 @@ class LookupFuncs():
|
|||||||
for reaction in monster["reactions"]:
|
for reaction in monster["reactions"]:
|
||||||
react += "\n\n***"+reaction["name"]+".*** "+reaction["desc"]
|
react += "\n\n***"+reaction["name"]+".*** "+reaction["desc"]
|
||||||
|
|
||||||
leg_act = ""
|
legendaryActions = ""
|
||||||
if "legendary_actions" in monster:
|
if "legendary_actions" in monster:
|
||||||
for action in monster["legendary_actions"]:
|
for action in monster["legendary_actions"]:
|
||||||
leg_act += "\n\n***"+action["name"]+".*** "+action["desc"]
|
legendaryActions += "\n\n***"+action["name"]+".*** "+action["desc"]
|
||||||
|
|
||||||
if con_mod < 0:
|
if con_mod < 0:
|
||||||
hit_dice += (" - "+str(con_mod * int(monster["hit_dice"].replace("d"," ").split()[0])*(-1)))
|
hit_dice += (" - "+str(con_mod * int(monster["hit_dice"].replace("d"," ").split()[0])*(-1)))
|
||||||
@ -107,33 +109,56 @@ class LookupFuncs():
|
|||||||
|
|
||||||
new_part = "\n--------------------"
|
new_part = "\n--------------------"
|
||||||
|
|
||||||
monster_type = monster["size"]+" "+typs+", "+monster["alignment"]+"*"
|
monster_type = monster["size"]+" "+types+", "+monster["alignment"]+"*"
|
||||||
|
|
||||||
basic_info = "\n**Armor Class** "+str(monster["armor_class"])+"\n**Hit Points** "+str(monster["hit_points"])+" ("+hit_dice+")\n**Speed **"+monster["speed"]+new_part+"\n"
|
basic_info = "\n**Armor Class** "+str(monster["armor_class"])+"\n**Hit Points** "+str(monster["hit_points"])+" ("+hit_dice+")\n**Speed **"+monster["speed"]+new_part+"\n"
|
||||||
|
|
||||||
text1 = (monster_type+new_part+basic_info+stats+new_part+saving_throws+skills+vulnerabilities+resistances+immunities+c_immunities+"\n**Senses** "+monster["senses"]+"\n**Languages** "+monster["languages"]+"\n**Challenge** "+monster["challenge_rating"])
|
info = (monster_type+new_part+basic_info+stats+new_part+saving_throws+skills+vulnerabilities+resistances+immunities+c_immunities+"\n**Senses** "+monster["senses"]+"\n**Languages** "+monster["languages"]+"\n**Challenge** "+monster["challenge_rating"])
|
||||||
|
|
||||||
text2 = (spec_ab)
|
monsterInfo = [(info, query),
|
||||||
text3 = (act)
|
(specialAbilities, "Special Abilities"),
|
||||||
text4 = (react)
|
(act, "Actions"),
|
||||||
text5 = (leg_act)
|
(react, "Reactions"),
|
||||||
|
(legendaryActions, "Legendary Actions")]
|
||||||
|
|
||||||
self.bot.log("Returning monster information")
|
self.bot.log("Returning monster information")
|
||||||
return(str(command),text1,text2,text3,text4,text5)
|
|
||||||
self.bot.log("Monster not in database (error code 602)")
|
# Sends the received information. Separates into separate messages if
|
||||||
return("I don't know that monster... (error code 602)","","","","","")
|
# there is too much text
|
||||||
|
await ctx.send(f"Result for \"{query}\"")
|
||||||
|
for text, title in monsterInfo:
|
||||||
|
if text != "":
|
||||||
|
if len(text) < 2000:
|
||||||
|
em = discord.Embed(title = title, description = text, colour=0xDEADBF)
|
||||||
|
await ctx.channel.send(embed = em)
|
||||||
|
else:
|
||||||
|
index = text[:2000].rfind(".")+1
|
||||||
|
em1 = discord.Embed(title = title, description = text[:index], colour=0xDEADBF)
|
||||||
|
await ctx.channel.send(embed = em1)
|
||||||
|
em2 = discord.Embed(title = "", description = text[index+1:], colour=0xDEADBF)
|
||||||
|
await ctx.channel.send(embed = em2)
|
||||||
|
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
self.bot.log("Monster not in database")
|
||||||
|
await ctx.send("I don't know that monster...")
|
||||||
|
|
||||||
# Looks up a spell
|
# Looks up a spell
|
||||||
def spellFunc(self, command):
|
async def spellFunc(self, ctx, query):
|
||||||
self.bot.log("Looking up "+command)
|
query = cap(query)
|
||||||
|
self.bot.log("Looking up "+query)
|
||||||
|
|
||||||
# Opens "spells.json"
|
# Opens "spells.json"
|
||||||
data = json.load(open('resources/lookup/spells.json', encoding = "utf8"))
|
data = json.load(open('resources/lookup/spells.json', encoding = "utf8"))
|
||||||
if str(command) in data:
|
if query in data:
|
||||||
self.bot.log("Returning spell information")
|
self.bot.log("Returning spell information")
|
||||||
spell_output = ("***"+str(command)+"***\n*"+str(data[str(command)]["level"])+" level "+str(data[str(command)]["school"])+"\nCasting Time: "+str(data[str(command)]["casting_time"])+"\nRange: "+str(data[str(command)]["range"])+"\nComponents: "+str(data[str(command)]["components"])+"\nDuration: "+str(data[str(command)]["duration"])+"*\n \n"+str(data[str(command)]["description"]))
|
sendMessage = (f"***{query}***\n*{data[query]['level']} level {data[query]['school']}\nCasting Time: {data[query]['casting_time']}\nRange:{data[query]['range']}\nComponents:{data[query]['components']}\nDuration:{data[query]['duration']}*\n \n{data[query]['description']}")
|
||||||
else:
|
else:
|
||||||
self.bot.log("I don't know that spell (error code 501)")
|
self.bot.log("I don't know that spell (error code 501)")
|
||||||
spell_output = "I don't think that's a spell (error code 501)"
|
sendMessage = "I don't think that's a spell (error code 501)"
|
||||||
self.bot.log("Successfully ran /spell")
|
|
||||||
return(spell_output)
|
if len(sendMessage) > 2000:
|
||||||
|
await ctx.send(sendMessage[:2000])
|
||||||
|
await ctx.send(sendMessage[2000:])
|
||||||
|
else:
|
||||||
|
await ctx.send(sendMessage)
|
||||||
|
Reference in New Issue
Block a user