This commit is contained in:
NikolajDanger
2020-03-31 01:37:31 +02:00
parent b389988a92
commit d9f1e23481
5 changed files with 48 additions and 14 deletions

View File

@ -202,4 +202,3 @@ async def on_message(message):
# Runs the whole shabang # Runs the whole shabang
client.run(token) client.run(token)

View File

@ -8,6 +8,7 @@ import imdb #used by movieFunc
from .roll import dice from .roll import dice
# I stole this. It rolls dice. I am not qualified to comment it
def roll_dice(author : str, rollStr : str = "1d20"): def roll_dice(author : str, rollStr : str = "1d20"):
print("Rolling "+str(rollStr)) print("Rolling "+str(rollStr))
if rollStr == '0/0': # easter eggs if rollStr == '0/0': # easter eggs
@ -28,8 +29,8 @@ def roll_dice(author : str, rollStr : str = "1d20"):
print("") print("")
return(outputs) return(outputs)
# Capitalizes all words except some of them
no_caps_list = ["of","the"] no_caps_list = ["of","the"]
def cap(s): def cap(s):
word_number = 0 word_number = 0
lst = s.split() lst = s.split()
@ -49,6 +50,7 @@ def time_in_range(start, end, x):
else: else:
return start <= x or x <= end return start <= x or x <= end
# Responds with a greeting of a time-aprpriate maner
def helloFunc(author): def helloFunc(author):
print("") print("")
now = datetime.datetime.now() now = datetime.datetime.now()
@ -65,7 +67,9 @@ def helloFunc(author):
else: else:
return("Why hello, "+str(author)) return("Why hello, "+str(author))
# Finds a random picture online
def imageFunc(): def imageFunc():
# Picks a type of camera, which decides the naming scheme
cams = ("one","two","three","four") cams = ("one","two","three","four")
cam = random.choice(cams) cam = random.choice(cams)
if cam == "one": if cam == "one":
@ -88,12 +92,17 @@ def imageFunc():
c = str(random.randint(0,9)) c = str(random.randint(0,9))
d = str(random.randint(0,9)) d = str(random.randint(0,9))
search = ("DSC_"+a+b+c+d) search = ("DSC_"+a+b+c+d)
# Searches for the image and reads the resulting web page
page = urllib.request.urlopen("https://www.bing.com/images/search?q="+search+"&safesearch=off") page = urllib.request.urlopen("https://www.bing.com/images/search?q="+search+"&safesearch=off")
read = page.read() read = page.read()
tree = lxml.etree.HTML(read) tree = lxml.etree.HTML(read)
images = tree.xpath('//a[@class = "thumb"]/@href') images = tree.xpath('//a[@class = "thumb"]/@href')
# Picks an image
number = random.randint(1,len(images))-1 number = random.randint(1,len(images))-1
image = images[number] image = images[number]
print("Successfully returned an image")
print("") # Returns the image
print("Successfully returned an image\n")
return(image) return(image)

View File

@ -7,6 +7,7 @@ from funcs import gwendolynFuncs as gf
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO) logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
# Calculates D&D stat modifier
def modifier(statistic): def modifier(statistic):
mods = math.floor((statistic-10)/2) mods = math.floor((statistic-10)/2)
if mods >= 0: if mods >= 0:
@ -16,15 +17,19 @@ def modifier(statistic):
saves = ["strength_save","dexterity_save","constitution_save","intelligence_save","wisdom_save","charisma_save"] 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"] abilities = ["acrobatics","animal_handling","arcana","athletics","deception","history","insight","intimidation","investigation","medicine","nature","perception","performance","persuasion","religion","sleight_of_hand","stealth","survival"]
# Looks up a monster
def monsterFunc(content): def monsterFunc(content):
command = gf.cap(content.lower().replace("!monster ","")) command = gf.cap(content.lower().replace("!monster ",""))
print("Looking up "+command) print("Looking up "+command)
logging.info("Looking up "+command) logging.info("Looking up "+command)
# 1-letter monsters don't exist
if len(content.lower().split()) < 2: if len(content.lower().split()) < 2:
print("Monster doesn't exist in database\n") print("Monster doesn't exist in database\n")
logging.info("Monster doesn't exist in database\n") logging.info("Monster doesn't exist in database\n")
return("I don't know that monster...","","","","","") return("I don't know that monster...","","","","","")
else: else:
# Opens "mensters.json"
data = json.load(open('resources/monsters.json', encoding = "utf8")) data = json.load(open('resources/monsters.json', encoding = "utf8"))
for monster in data: for monster in data:
if str(command) == monster["name"]: if str(command) == monster["name"]:
@ -124,10 +129,13 @@ def monsterFunc(content):
logging.info("Couldn't find monster") logging.info("Couldn't find monster")
return("I don't know that monster...","","","","","") return("I don't know that monster...","","","","","")
# Looks up a spell
def spellFunc(content): def spellFunc(content):
command = gf.cap(content.lower().replace("!spell ","")) command = gf.cap(content.lower().replace("!spell ",""))
print("Looking up "+command) print("Looking up "+command)
logging.info("Looking up "+command) logging.info("Looking up "+command)
# Opens "spells.json"
data = json.load(open('resources/spells.json', encoding = "utf8")) data = json.load(open('resources/spells.json', encoding = "utf8"))
if str(command) in data: if str(command) in data:
print("Returning spell information") print("Returning spell information")

View File

@ -4,48 +4,65 @@ import logging
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO) logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
# Returns a list of all letter pairs in the text
def make_pairs(corpus): def make_pairs(corpus):
for i in range(len(corpus)-1): for i in range(len(corpus)-1):
yield (corpus[i], corpus[i+1]) yield (corpus[i], corpus[i+1])
# Generates a random name
def nameGen(): def nameGen():
# Makes a list of all names from "names.txt"
names = open('resources/names.txt', encoding='utf8').read() names = open('resources/names.txt', encoding='utf8').read()
corpus = list(names) corpus = list(names)
# Makes a list of pairs
pairs = make_pairs(corpus) pairs = make_pairs(corpus)
word_dict = {} letter_dict = {}
for word_1, word_2 in pairs: # Makes a dictionary of all letters that come after all other letters
if word_1 in word_dict.keys(): for letter_1, letter_2 in pairs:
word_dict[word_1].append(word_2) if letter_1 in letter_dict.keys():
letter_dict[letter_1].append(letter_2)
else: else:
word_dict[word_1] = [word_2] letter_dict[letter_1] = [letter_2]
first_word = random.choice(corpus) # Choses a random first letter
first_letter = random.choice(corpus)
while first_word.islower() or first_word == " " or first_word == "-" or first_word == "\n": # Makes sure the first letter is not something a name can't start with.
first_word = random.choice(corpus) while first_letter.islower() or first_letter == " " or first_letter == "-" or first_letter == "\n":
first_letter = random.choice(corpus)
chain = [first_word] # Starts the name
chain = [first_letter]
done = False done = False
# Creates the name one letter at a time
while done == False: while done == False:
new_letter = random.choice(word_dict[chain[-1]]) new_letter = random.choice(letter_dict[chain[-1]])
chain.append(new_letter) chain.append(new_letter)
# Ends name if the name ends
if new_letter == "\n": if new_letter == "\n":
done = True done = True
genName = "".join(chain) genName = "".join(chain)
print("Generated "+genName) print("Generated "+genName)
logging.info("Generated "+genName) logging.info("Generated "+genName)
# Returns the name
return(genName) return(genName)
# Generates a random tavern name
def tavernGen(): def tavernGen():
# Lists first parts, second parts and third parts of tavern names
fp = ["The Silver","The Golden","The Staggering","The Laughing","The Prancing","The Gilded","The Running","The Howling","The Slaughtered","The Leering","The Drunken","The Leaping","The Roaring","The Frowning","The Lonely","The Wandering","The Mysterious","The Barking","The Black","The Gleaming","The Tap-Dancing","The Sad","The Sexy","The Artificial","The Groovy","The Merciful","The Confused","The Pouting","The Horny","The Okay","The Friendly","The Hungry","The Handicapped","The Fire-breathing","The One-Eyed","The Psychotic","The Mad","The Evil","The Idiotic","The Trusty","The Busty"] fp = ["The Silver","The Golden","The Staggering","The Laughing","The Prancing","The Gilded","The Running","The Howling","The Slaughtered","The Leering","The Drunken","The Leaping","The Roaring","The Frowning","The Lonely","The Wandering","The Mysterious","The Barking","The Black","The Gleaming","The Tap-Dancing","The Sad","The Sexy","The Artificial","The Groovy","The Merciful","The Confused","The Pouting","The Horny","The Okay","The Friendly","The Hungry","The Handicapped","The Fire-breathing","The One-Eyed","The Psychotic","The Mad","The Evil","The Idiotic","The Trusty","The Busty"]
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"] 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","","","","","","","","",""] tp = [" Tavern"," Inn","","","","","","","","",""]
# Picks one of each
genTav = random.choice(fp)+" "+random.choice(sp)+random.choice(tp) genTav = random.choice(fp)+" "+random.choice(sp)+random.choice(tp)
print("Generated "+genTav) print("Generated "+genTav)
logging.info("Generated "+genTav) logging.info("Generated "+genTav)
# Return the name
return(genTav) return(genTav)

View File

@ -4,6 +4,7 @@ import logging
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO) logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
# Picks a random movie and returns information about it
def movieFunc(): def movieFunc():
try: try:
print("Creating IMDb object") print("Creating IMDb object")