✨ Converted all lookup functionality to slash commands
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import math
|
||||
import json
|
||||
import discord
|
||||
|
||||
from utils import cap
|
||||
|
||||
@ -18,27 +19,28 @@ class LookupFuncs():
|
||||
return(str(mods))
|
||||
|
||||
# Looks up a monster
|
||||
def monsterFunc(self, command):
|
||||
self.bot.log("Looking up "+command)
|
||||
async def monsterFunc(self, ctx, query):
|
||||
query = cap(query)
|
||||
self.bot.log("Looking up "+query)
|
||||
|
||||
# 1-letter monsters don't exist
|
||||
if len(command) < 2:
|
||||
self.bot.log("Monster name too short (error code 601)")
|
||||
return("I don't know that monster... (error code 601)","","","","","")
|
||||
if len(query) < 2:
|
||||
self.bot.log("Monster name too short")
|
||||
await ctx.send("I don't know that monster...")
|
||||
else:
|
||||
# Opens "monsters.json"
|
||||
data = json.load(open('resources/lookup/monsters.json', encoding = "utf8"))
|
||||
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!")
|
||||
|
||||
# Looks at the information about the monster and returns that information
|
||||
# in separate variables, allowing Gwendolyn to know where to separate
|
||||
# the messages
|
||||
if monster["subtype"] != "":
|
||||
typs = (monster["type"]+" ("+monster["subtype"]+")")
|
||||
types = (monster["type"]+" ("+monster["subtype"]+")")
|
||||
else:
|
||||
typs = monster["type"]
|
||||
types = monster["type"]
|
||||
con_mod = math.floor((monster["constitution"]-10)/2)
|
||||
hit_dice = monster["hit_dice"]
|
||||
|
||||
@ -80,10 +82,10 @@ class LookupFuncs():
|
||||
if c_immunities != "":
|
||||
c_immunities = "\n**Condition Immunities** "+c_immunities
|
||||
|
||||
spec_ab = ""
|
||||
specialAbilities = ""
|
||||
if "special_abilities" in monster:
|
||||
for ability in monster["special_abilities"]:
|
||||
spec_ab += "\n\n***"+ability["name"]+".*** "+ability["desc"]
|
||||
specialAbilities += "\n\n***"+ability["name"]+".*** "+ability["desc"]
|
||||
|
||||
act = ""
|
||||
if "actions" in monster:
|
||||
@ -95,10 +97,10 @@ class LookupFuncs():
|
||||
for reaction in monster["reactions"]:
|
||||
react += "\n\n***"+reaction["name"]+".*** "+reaction["desc"]
|
||||
|
||||
leg_act = ""
|
||||
legendaryActions = ""
|
||||
if "legendary_actions" in monster:
|
||||
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:
|
||||
hit_dice += (" - "+str(con_mod * int(monster["hit_dice"].replace("d"," ").split()[0])*(-1)))
|
||||
@ -107,33 +109,56 @@ class LookupFuncs():
|
||||
|
||||
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"
|
||||
|
||||
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)
|
||||
text3 = (act)
|
||||
text4 = (react)
|
||||
text5 = (leg_act)
|
||||
monsterInfo = [(info, query),
|
||||
(specialAbilities, "Special Abilities"),
|
||||
(act, "Actions"),
|
||||
(react, "Reactions"),
|
||||
(legendaryActions, "Legendary Actions")]
|
||||
|
||||
self.bot.log("Returning monster information")
|
||||
return(str(command),text1,text2,text3,text4,text5)
|
||||
self.bot.log("Monster not in database (error code 602)")
|
||||
return("I don't know that monster... (error code 602)","","","","","")
|
||||
|
||||
# Sends the received information. Separates into separate messages if
|
||||
# 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
|
||||
def spellFunc(self, command):
|
||||
self.bot.log("Looking up "+command)
|
||||
async def spellFunc(self, ctx, query):
|
||||
query = cap(query)
|
||||
self.bot.log("Looking up "+query)
|
||||
|
||||
# Opens "spells.json"
|
||||
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")
|
||||
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:
|
||||
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)"
|
||||
self.bot.log("Successfully ran /spell")
|
||||
return(spell_output)
|
||||
sendMessage = "I don't think that's a spell (error code 501)"
|
||||
|
||||
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