This commit is contained in:
NikolajDanger
2020-04-01 00:59:02 +02:00
parent 9088aaf932
commit eb8fb0c2c2
11 changed files with 254 additions and 185 deletions

View File

@@ -1,16 +1,20 @@
import lxml.etree #used by imageFunc
import re #used by roll_dice
import datetime #used by helloFunc
import json #used by spellFunc
import random #used by imageFunc
import urllib #used by imageFunc
import imdb #used by movieFunc
import lxml.etree # Used by imageFunc
import re # Used by roll_dice
import datetime # Used by helloFunc
import json # Used by spellFunc
import random # Used by imageFunc
import urllib # Used by imageFunc
import imdb # Used by movieFunc
import time # Used for logging
import logging # Used for... you know... logging
from .roll import dice
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
# I stole this. It rolls dice. I am not qualified to comment it
def roll_dice(author : str, rollStr : str = "1d20"):
print("Rolling "+str(rollStr))
logThis("Rolling "+str(rollStr))
if rollStr == '0/0': # easter eggs
return("What do you expect me to do, destroy the universe?")
@@ -25,8 +29,7 @@ def roll_dice(author : str, rollStr : str = "1d20"):
outputs = author + ' :game_die:\n[Output truncated due to length]\n**Result:** ' + str(res.plain)
else:
outputs = outStr
print("Successfully ran !roll")
print("")
logThis("Successfully ran !roll")
return(outputs)
# Capitalizes all words except some of them
@@ -52,7 +55,6 @@ def time_in_range(start, end, x):
# Responds with a greeting of a time-aprpriate maner
def helloFunc(author):
print("")
now = datetime.datetime.now()
if time_in_range(now.replace(hour=5, minute=0, second=0, microsecond=0),now.replace(hour=10, minute=0, second=0, microsecond=0), now):
return("Good morning, "+str(author))
@@ -72,6 +74,7 @@ def imageFunc():
# Picks a type of camera, which decides the naming scheme
cams = ("one","two","three","four")
cam = random.choice(cams)
logThis("Chose cam type "+cam)
if cam == "one":
a = str(random.randint(0 ,9))
b = str(random.randint(0,9))
@@ -92,7 +95,9 @@ def imageFunc():
c = str(random.randint(0,9))
d = str(random.randint(0,9))
search = ("DSC_"+a+b+c+d)
logThis("Searching for "+search)
# Searches for the image and reads the resulting web page
page = urllib.request.urlopen("https://www.bing.com/images/search?q="+search+"&safesearch=off")
read = page.read()
@@ -103,8 +108,13 @@ def imageFunc():
number = random.randint(1,len(images))-1
image = images[number]
logThis("Picked image number "+str(number))
# Returns the image
print("Successfully returned an image\n")
logThis("Successfully returned an image")
return(image)
def logThis(message : str):
localtime = time.asctime(time.localtime(time.time()))
print(localtime+" - "+message)
logging.info(localtime+" - "+message)