Init commit
This commit is contained in:
128
GwendolynFuncs.py
Normal file
128
GwendolynFuncs.py
Normal file
@ -0,0 +1,128 @@
|
||||
from lxml import 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
|
||||
|
||||
from dice import roll
|
||||
|
||||
def roll_dice(author, rollStr: str = "1d20"):
|
||||
print("Rolling "+str(rollStr))
|
||||
if rollStr == '0/0': # easter eggs
|
||||
return("What do you expect me to do, destroy the universe?")
|
||||
|
||||
adv = 0
|
||||
if re.search('(^|\s+)(adv|dis)(\s+|$)', rollStr) is not None:
|
||||
adv = 1 if re.search('(^|\s+)adv(\s+|$)', rollStr) is not None else -1
|
||||
rollStr = re.sub('(adv|dis)(\s+|$)', '', rollStr)
|
||||
res = roll(rollStr, adv=adv)
|
||||
out = res.result
|
||||
outStr = author + ' :game_die:\n' + out
|
||||
if len(outStr) > 1999:
|
||||
outputs = author + ' :game_die:\n[Output truncated due to length]\n**Result:** ' + str(res.plain)
|
||||
else:
|
||||
outputs = outStr
|
||||
print("Successfully ran !roll")
|
||||
print("")
|
||||
return(outputs)
|
||||
no_caps_list = ["of","the"]
|
||||
def cap(s):
|
||||
word_number = 0
|
||||
lst = s.split()
|
||||
res = ''
|
||||
for word in lst:
|
||||
word_number += 1
|
||||
if word not in no_caps_list or word_number == 1:
|
||||
word = word.capitalize()
|
||||
res += word+" "
|
||||
res = res[:-1]
|
||||
return res
|
||||
|
||||
def time_in_range(start, end, x):
|
||||
"""Return true if x is in the range [start, end]"""
|
||||
if start <= end:
|
||||
return start <= x <= end
|
||||
else:
|
||||
return start <= x or x <= end
|
||||
|
||||
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))
|
||||
elif time_in_range(now.replace(hour=10, minute=0, second=0, microsecond=0),now.replace(hour=13, minute=0, second=0, microsecond=0), now):
|
||||
return("Good day, "+str(author))
|
||||
elif time_in_range(now.replace(hour=13, minute=0, second=0, microsecond=0),now.replace(hour=18, minute=0, second=0, microsecond=0), now):
|
||||
return("Good afternoon, "+str(author))
|
||||
elif time_in_range(now.replace(hour=18, minute=0, second=0, microsecond=0),now.replace(hour=22, minute=0, second=0, microsecond=0), now):
|
||||
return("Good evening, "+str(author))
|
||||
elif time_in_range(now.replace(hour=22, minute=0, second=0, microsecond=0),now.replace(hour=23, minute=59, second=59, microsecond=0), now):
|
||||
return("Good night, "+str(author))
|
||||
else:
|
||||
return("Why hello, "+str(author))
|
||||
|
||||
def imageFunc():
|
||||
mh = 730
|
||||
mw = 900
|
||||
cams = ("one","two","three","four")
|
||||
cam = random.choice(cams)
|
||||
if cam == "one":
|
||||
a = str(random.randint(0 ,9))
|
||||
b = str(random.randint(0,9))
|
||||
c = str(random.randint(0,9))
|
||||
d = str(random.randint(0,9))
|
||||
search = ("img_"+a+b+c+d)
|
||||
elif cam == "two":
|
||||
a = str(random.randint(2012,2016))
|
||||
b = str(random.randint(1,12)).zfill(2)
|
||||
c = str(random.randint(1,29)).zfill(2)
|
||||
search = ("IMG_"+a+b+c)
|
||||
elif cam == "three":
|
||||
a = str(random.randint(1,500)).zfill(4)
|
||||
search = ("IMAG_"+a)
|
||||
elif cam == "four":
|
||||
a = str(random.randint(0,9))
|
||||
b = str(random.randint(0,9))
|
||||
c = str(random.randint(0,9))
|
||||
d = str(random.randint(0,9))
|
||||
search = ("DSC_"+a+b+c+d)
|
||||
page = urllib.request.urlopen("https://www.bing.com/images/search?q="+search+"&safesearch=off")
|
||||
read = page.read()
|
||||
tree = etree.HTML(read)
|
||||
images = tree.xpath('//a[@class = "thumb"]/@href')
|
||||
number = random.randint(1,len(images))-1
|
||||
image = images[number]
|
||||
print("Successfully returned an image")
|
||||
print("")
|
||||
return(image)
|
||||
|
||||
def movieFunc():
|
||||
try:
|
||||
print("Creating IMDb object")
|
||||
ia = imdb.IMDb()
|
||||
|
||||
print("Picking a movie")
|
||||
movs = open("movies.txt", "r")
|
||||
movlist = movs.read().split("\n")
|
||||
mov = random.choice(movlist)
|
||||
movs.close()
|
||||
|
||||
print("Searching for "+mov)
|
||||
s_result = ia.search_movie(mov)
|
||||
|
||||
print("Getting the data")
|
||||
movie = s_result[0]
|
||||
ia.update(movie)
|
||||
cast = movie['cast']
|
||||
pcast = ""
|
||||
for x in range(3):
|
||||
if cast[x]:
|
||||
pcast += cast[x]['name']+", "
|
||||
print("Successfully ran !movie")
|
||||
print("")
|
||||
return(movie['title'], movie['plot'][0].split("::")[0], movie['cover url'].replace("150","600").replace("101","404"), pcast[:-2])
|
||||
except:
|
||||
print("Something bad happened...")
|
||||
return("error","","","")
|
Reference in New Issue
Block a user