132 lines
6.7 KiB
Python
132 lines
6.7 KiB
Python
import math
|
|
import discord
|
|
import json
|
|
import logging
|
|
|
|
from funcs import gwendolynFuncs as gf
|
|
|
|
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
|
|
|
|
def modifier(statistic):
|
|
mods = math.floor((statistic-10)/2)
|
|
if mods >= 0:
|
|
mods = "+"+str(mods)
|
|
return(str(mods))
|
|
|
|
saves = ["strength_save","dexterity_save","constitution_save","intelligence_save","wisdom_save","charisma_save"]
|
|
abilities = ["acrobatics","animal_handling","arcana","athletics","deception","history","insight","intimidation","investigation","medicine","nature","perception","performance","persuasion","religion","sleight_of_hand","stealth","survival"]
|
|
|
|
def monsterFunc(content):
|
|
command = gf.cap(content.lower().replace("!monster ",""))
|
|
print("Looking up "+command)
|
|
logging.info("Looking up "+command)
|
|
if len(content.lower().split()) < 2:
|
|
print("Monster doesn't exist in database\n")
|
|
logging.info("Monster doesn't exist in database\n")
|
|
return("I don't know that monster...","","","","","")
|
|
else:
|
|
data = json.load(open('resources/monsters.json', encoding = "utf8"))
|
|
for monster in data:
|
|
if str(command) == monster["name"]:
|
|
print("Found it!")
|
|
logging.info("Found it!")
|
|
if monster["subtype"] != "":
|
|
typs = (monster["type"]+" ("+monster["subtype"]+")")
|
|
else:
|
|
typs = monster["type"]
|
|
con_mod = math.floor((monster["constitution"]-10)/2)
|
|
hit_dice = monster["hit_dice"]
|
|
|
|
stats = ("**Str:** "+str(monster["strength"])+" ("+modifier(monster["strength"])+")\t**Dex:** "+str(monster["dexterity"])+" ("+modifier(monster["dexterity"])+")\t**Con:** "+str(monster["constitution"])+" ("+modifier(monster["constitution"])+")\n**Int: **"+str(monster["intelligence"])+" ("+modifier(monster["intelligence"])+")\t**Wis: **"+str(monster["wisdom"])+" ("+modifier(monster["wisdom"])+")\t**Cha: **"+str(monster["charisma"])+" ("+modifier(monster["charisma"])+")")
|
|
|
|
saving_throws = ""
|
|
for save in saves:
|
|
if save in monster:
|
|
if monster[save] >= 0:
|
|
saving_throws += " "+gf.cap(save[:3])+" +"+str(monster[save])+","
|
|
else:
|
|
saving_throws += " "+gf.cap(save[:3])+" "+str(monster[save])+","
|
|
if saving_throws != "":
|
|
saving_throws = "\n**Saving Throws**"+saving_throws[:-1]
|
|
|
|
skills = ""
|
|
for skill in abilities:
|
|
if skill in monster:
|
|
if monster[skill] >= 0:
|
|
skills += " "+gf.cap(skill.replace("_"," "))+" +"+str(monster[skill])+","
|
|
else:
|
|
skills += " "+gf.cap(skill.replace("_"," "))+" "+str(monster[skill])+","
|
|
if skills != "":
|
|
skills = "\n**Skills**"+skills[:-1]
|
|
|
|
vulnerabilities = monster["damage_vulnerabilities"]
|
|
if vulnerabilities != "":
|
|
vulnerabilities = "\n**Damage Vulnerabilities** "+vulnerabilities
|
|
|
|
resistances = monster["damage_resistances"]
|
|
if resistances != "":
|
|
resistances = "\n**Damage Resistances** "+resistances
|
|
|
|
immunities = monster["damage_immunities"]
|
|
if immunities != "":
|
|
immunities = "\n**Damage Immunities** "+immunities
|
|
|
|
c_immunities = monster["condition_immunities"]
|
|
if c_immunities != "":
|
|
c_immunities = "\n**Condition Immunities** "+c_immunities
|
|
|
|
spec_ab = ""
|
|
if "special_abilities" in monster:
|
|
for ability in monster["special_abilities"]:
|
|
spec_ab += "\n\n***"+ability["name"]+".*** "+ability["desc"]
|
|
|
|
act = ""
|
|
if "actions" in monster:
|
|
for action in monster["actions"]:
|
|
act += "\n\n***"+action["name"]+".*** "+action["desc"]
|
|
|
|
react = ""
|
|
if "reactions" in monster:
|
|
for reaction in monster["reactions"]:
|
|
react += "\n\n***"+reaction["name"]+".*** "+reaction["desc"]
|
|
|
|
leg_act = ""
|
|
if "legendary_actions" in monster:
|
|
for action in monster["legendary_actions"]:
|
|
leg_act += "\n\n***"+action["name"]+".*** "+action["desc"]
|
|
|
|
if con_mod < 0:
|
|
hit_dice += (" - "+str(con_mod * int(monster["hit_dice"].replace("d"," ").split()[0])*(-1)))
|
|
if con_mod > 0:
|
|
hit_dice += (" + "+str(con_mod * int(monster["hit_dice"].replace("d"," ").split()[0])))
|
|
new_part = "\n--------------------"
|
|
monster_type = monster["size"]+" "+typs+", "+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"])
|
|
text2 = (spec_ab)
|
|
text3 = (act)
|
|
text4 = (react)
|
|
text5 = (leg_act)
|
|
print("Returning monster information\n")
|
|
logging.info("Returning monster information\n")
|
|
return(str(command),text1,text2,text3,text4,text5)
|
|
print("")
|
|
return("I don't know that monster...","","","","","")
|
|
|
|
def spellFunc(content):
|
|
command = gf.cap(content.lower().replace("!spell ",""))
|
|
print("Looking up "+command)
|
|
logging.info("Looking up "+command)
|
|
data = json.load(open('resources/spells.json', encoding = "utf8"))
|
|
if str(command) in data:
|
|
print("Returning spell information")
|
|
logging.info("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"]))
|
|
else:
|
|
print("I don't know that spell")
|
|
logging.info("I don't know that spell")
|
|
spell_output = "I don't think that's a spell"
|
|
print("Successfully ran !spell")
|
|
logging.info("Successfully ran !spell")
|
|
return(spell_output)
|