Some logging and comments

This commit is contained in:
Nikolaj Danger
2020-03-24 17:02:27 +01:00
parent 5c85ea8d5b
commit 5f78967eb2
6 changed files with 40 additions and 12 deletions

View File

@ -70,6 +70,9 @@ async def on_message(message):
logging.info("\n"+localtime+"\n"+message.author.name+" ran !monster")
title, text1, text2, text3, text4, text5 = funcs.monsterFunc(message.content)
em1 = discord.Embed(title = title, description = text1, colour=0xDEADBF)
# Sends the received information. Seperates into seperate messages if
# there is too much text
await message.channel.send(embed = em1)
if text2 != "":
if len(text2) < 2048:

View File

@ -30,6 +30,10 @@ def monsterFunc(content):
if str(command) == monster["name"]:
print("Found it!")
logging.info("Found it!")
# Looks at the information about the monster and returns that information
# in seperate variables, allowing Gwendolyn to know where to seperate
# the messages
if monster["subtype"] != "":
typs = (monster["type"]+" ("+monster["subtype"]+")")
else:
@ -99,18 +103,25 @@ def monsterFunc(content):
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")
print("Returning monster information")
logging.info("Returning monster information")
return(str(command),text1,text2,text3,text4,text5)
print("")
print("Couldn't find monster")
logging.info("Couldn't find monster")
return("I don't know that monster...","","","","","")
def spellFunc(content):

View File

@ -1,7 +1,8 @@
import numpy as np
import random
import logging
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
def make_pairs(corpus):
for i in range(len(corpus)-1):
@ -37,6 +38,7 @@ def nameGen():
done = True
genName = "".join(chain)
print("Generated "+genName)
logging.info("Generated "+genName)
return(genName)
def tavernGen():
@ -44,5 +46,6 @@ def tavernGen():
sp = ["Eel","Dolphin","Dwarf","Pegasus","Pony","Rose","Stag","Wolf","Lamb","Demon","Goat","Spirit","Horde","Jester","Mountain","Eagle","Satyr","Dog","Spider","Star","Dad","Rat","Jeremy","Mouse","Unicorn","Pearl","Ant","Crab","Penguin","Octopus","Lawyer","Ghost","Toad","Handjob","Immigrant","SJW","Dragon","Bard","Sphinx","Soldier","Salmon","Owlbear","Kite","Frost Giant","'̶̧̗̣̰̞̜̤̦̖͗̈́̏͊͒͜+̴͎̰͓̱̻̝̬̼͕̥͍̪͕̮͙͂͝*̶̲̓̊̏'̷̥̺͈̞͒̆̏͋̀̐̇͆̓͊͠'̷͖̱̟̟͉̝̪̮͕̃͑́̍͆̓̌͒̄͛̇͘̚ͅ!̷̡̻̈́#̸̳̰̿̿̏͐̏̓̌̚̚͠¨̷̟͙̱͎̟̱̅̀͋̇͗͂͋͋̕͘´̴̡̡͎͔̦̜̟̼̠̰̤͋́̀̓́̄́̏͂̀͜.̸̛̭͍̮̜͑̋̀̋̈́̇̆̆̌_̸̡̥̜̞̝̮̑͑̓̓̇͜͜^̴̡̢͕̠̖̤̺̭̮̙͕̼̳̺̼͋̿̏̎̑͑̊̀̅͐̚͝͝","Arsonist"]
tp = [" Tavern"," Inn","","","","","","","","",""]
genTav = random.choice(fp)+" "+random.choice(sp)+random.choice(tp)
print("Generated "+genTav+"\n")
print("Generated "+genTav)
print("Generated "+genTav)
return(genTav)

View File

@ -1,21 +1,28 @@
import imdb
import random
import logging
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
def movieFunc():
try:
print("Creating IMDb object")
logging.info("Creating IMDb object")
ia = imdb.IMDb()
print("Picking a movie")
logging.info("Picking a movie")
movs = open("resources/movies.txt", "r")
movlist = movs.read().split("\n")
mov = random.choice(movlist)
movs.close()
print("Searching for "+mov)
logging.info("Searching for "+mov)
s_result = ia.search_movie(mov)
print("Getting the data")
logging.info("Getting the data")
movie = s_result[0]
ia.update(movie)
cast = movie['cast']
@ -24,8 +31,9 @@ def movieFunc():
if cast[x]:
pcast += cast[x]['name']+", "
print("Successfully ran !movie")
print("")
logging.info("Successfully ran !movie")
return(movie['title'], movie['plot'][0].split("::")[0], movie['cover url'].replace("150","600").replace("101","404"), pcast[:-2])
except:
print("Something bad happened...")
logging.info("Something bad happened...")
return("error","","","")

View File

@ -10,7 +10,7 @@ import numexpr
from . import errors
log = logging.getLogger(__name__)
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
VALID_OPERATORS = 'k|rr|ro|mi|ma|ra|e|p'
VALID_OPERATORS_ARRAY = VALID_OPERATORS.split('|')
@ -41,10 +41,10 @@ def get_roll_comment(rollStr):
no_comment = ''
dice_set = re.split('([-+*/().=])', rollStr)
dice_set = [d for d in dice_set if not d in (None, '')]
log.debug("Found dice set: " + str(dice_set))
logging.debug("Found dice set: " + str(dice_set))
for index, dice in enumerate(dice_set):
match = DICE_PATTERN.match(dice)
log.debug("Found dice group: " + str(match.groups()))
logging.debug("Found dice group: " + str(match.groups()))
no_comment += dice.replace(match.group(5), '')
if match.group(5):
comment = match.group(5) + ''.join(dice_set[index + 1:])
@ -85,10 +85,10 @@ class Roll(object):
# parse each, returning a SingleDiceResult
dice_set = re.split('([-+*/().=])', rollStr)
dice_set = [d for d in dice_set if not d in (None, '')]
log.debug("Found dice set: " + str(dice_set))
logging.debug("Found dice set: " + str(dice_set))
for index, dice in enumerate(dice_set):
match = DICE_PATTERN.match(dice)
log.debug("Found dice group: " + str(match.groups()))
logging.debug("Found dice group: " + str(match.groups()))
# check if it's dice
if match.group(1):
roll = self.roll_one(dice.replace(match.group(5), ''), adv)
@ -157,7 +157,7 @@ class Roll(object):
skeleton=skeletonReply, raw_dice=self)
except Exception as ex:
if not isinstance(ex, (SyntaxError, KeyError, errors.AvraeException)):
log.error('Error in roll() caused by roll {}:'.format(rollStr))
logging.error('Error in roll() caused by roll {}:'.format(rollStr))
traceback.print_exc()
return DiceResult(verbose_result="Invalid input: {}".format(ex))

View File

@ -1,5 +1,8 @@
import json
import string
import logging
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
def getName(user : str):
with open("resources/swcharacters.json", "r") as f: