✨
This commit is contained in:
@@ -1,94 +1,94 @@
|
||||
import random
|
||||
|
||||
class Generators():
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
# Returns a list of all letter pairs in the text
|
||||
def make_pairs(self, corpus):
|
||||
for i in range(len(corpus)-1):
|
||||
yield (corpus[i], corpus[i+1])
|
||||
# Returns a list of all letter pairs in the text
|
||||
def make_pairs(self, corpus):
|
||||
for i in range(len(corpus)-1):
|
||||
yield (corpus[i], corpus[i+1])
|
||||
|
||||
# Returns a list of all letter triplets in the text
|
||||
def make_triplets(self, corpus):
|
||||
for i in range(len(corpus)-2):
|
||||
yield (corpus[i], corpus[i+1], corpus[i+2])
|
||||
# Returns a list of all letter triplets in the text
|
||||
def make_triplets(self, corpus):
|
||||
for i in range(len(corpus)-2):
|
||||
yield (corpus[i], corpus[i+1], corpus[i+2])
|
||||
|
||||
# Generates a random name
|
||||
async def name_gen(self, ctx):
|
||||
# Makes a list of all names from "names.txt"
|
||||
with open("gwendolyn/resources/names.txt", "r", encoding='utf8') as file_pointer:
|
||||
names = file_pointer.read()
|
||||
corpus = list(names)
|
||||
# Generates a random name
|
||||
async def name_gen(self, ctx):
|
||||
# Makes a list of all names from "names.txt"
|
||||
with open("gwendolyn/resources/names.txt", "r", encoding='utf8') as file_pointer:
|
||||
names = file_pointer.read()
|
||||
corpus = list(names)
|
||||
|
||||
# Makes a list of pairs
|
||||
pairs = self.make_pairs(corpus)
|
||||
triplets = self.make_triplets(corpus)
|
||||
# Makes a list of pairs
|
||||
pairs = self.make_pairs(corpus)
|
||||
triplets = self.make_triplets(corpus)
|
||||
|
||||
letter_dict = {}
|
||||
letter_dict = {}
|
||||
|
||||
# Makes a dictionary of all letters that come after all other letters
|
||||
for letter_1, letter_2 in pairs:
|
||||
if letter_1 in letter_dict:
|
||||
letter_dict[letter_1].append(letter_2)
|
||||
else:
|
||||
letter_dict[letter_1] = [letter_2]
|
||||
# Makes a dictionary of all letters that come after all other letters
|
||||
for letter_1, letter_2 in pairs:
|
||||
if letter_1 in letter_dict:
|
||||
letter_dict[letter_1].append(letter_2)
|
||||
else:
|
||||
letter_dict[letter_1] = [letter_2]
|
||||
|
||||
for letter_1, letter_2, letter_3 in triplets:
|
||||
if letter_1+letter_2 in letter_dict:
|
||||
letter_dict[letter_1+letter_2].append(letter_3)
|
||||
else:
|
||||
letter_dict[letter_1+letter_2] = [letter_3]
|
||||
for letter_1, letter_2, letter_3 in triplets:
|
||||
if letter_1+letter_2 in letter_dict:
|
||||
letter_dict[letter_1+letter_2].append(letter_3)
|
||||
else:
|
||||
letter_dict[letter_1+letter_2] = [letter_3]
|
||||
|
||||
# Choses a random first letter
|
||||
first_letter = random.choice(corpus)
|
||||
# Choses a random first letter
|
||||
first_letter = random.choice(corpus)
|
||||
|
||||
# Makes sure the first letter is not something a name can't start with.
|
||||
while first_letter.islower() or first_letter == " " or first_letter == "-" or first_letter == "\n":
|
||||
first_letter = random.choice(corpus)
|
||||
# Makes sure the first letter is not something a name can't start with.
|
||||
while first_letter.islower() or first_letter == " " or first_letter == "-" or first_letter == "\n":
|
||||
first_letter = random.choice(corpus)
|
||||
|
||||
# Starts the name
|
||||
chain = [first_letter]
|
||||
# Starts the name
|
||||
chain = [first_letter]
|
||||
|
||||
# Picks second letter
|
||||
second_letter = random.choice(letter_dict[chain[-1]])
|
||||
# Picks second letter
|
||||
second_letter = random.choice(letter_dict[chain[-1]])
|
||||
|
||||
while second_letter == "\n":
|
||||
second_letter = random.choice(letter_dict[chain[-1]])
|
||||
while second_letter == "\n":
|
||||
second_letter = random.choice(letter_dict[chain[-1]])
|
||||
|
||||
chain.append(second_letter)
|
||||
chain.append(second_letter)
|
||||
|
||||
done = False
|
||||
done = False
|
||||
|
||||
# Creates the name one letter at a time
|
||||
while not done:
|
||||
if random.randint(1,10) > 1:
|
||||
try:
|
||||
new_letter = random.choice(letter_dict[chain[-2]+chain[-1]])
|
||||
except KeyError():
|
||||
new_letter = random.choice(letter_dict[chain[-1]])
|
||||
else:
|
||||
new_letter = random.choice(letter_dict[chain[-1]])
|
||||
chain.append(new_letter)
|
||||
# Ends name if the name ends
|
||||
if new_letter == "\n":
|
||||
done = True
|
||||
gen_name = "".join(chain)
|
||||
self.bot.log("Generated "+gen_name[:-1])
|
||||
# Creates the name one letter at a time
|
||||
while not done:
|
||||
if random.randint(1,10) > 1:
|
||||
try:
|
||||
new_letter = random.choice(letter_dict[chain[-2]+chain[-1]])
|
||||
except KeyError():
|
||||
new_letter = random.choice(letter_dict[chain[-1]])
|
||||
else:
|
||||
new_letter = random.choice(letter_dict[chain[-1]])
|
||||
chain.append(new_letter)
|
||||
# Ends name if the name ends
|
||||
if new_letter == "\n":
|
||||
done = True
|
||||
gen_name = "".join(chain)
|
||||
self.bot.log("Generated "+gen_name[:-1])
|
||||
|
||||
# Returns the name
|
||||
await ctx.send(gen_name)
|
||||
# Returns the name
|
||||
await ctx.send(gen_name)
|
||||
|
||||
# Generates a random tavern name
|
||||
async def tavern_gen(self, ctx):
|
||||
# _lists first parts, second parts and third parts of tavern names
|
||||
first_part = ["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"]
|
||||
second_part = ["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"]
|
||||
third_part = [" Tavern"," Inn","","","","","","","","",""]
|
||||
# Generates a random tavern name
|
||||
async def tavern_gen(self, ctx):
|
||||
# _lists first parts, second parts and third parts of tavern names
|
||||
first_part = ["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"]
|
||||
second_part = ["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"]
|
||||
third_part = [" Tavern"," Inn","","","","","","","","",""]
|
||||
|
||||
# Picks one of each
|
||||
gen_tav = random.choice(first_part)+" "+random.choice(second_part)+random.choice(third_part)
|
||||
self.bot.log("Generated "+gen_tav)
|
||||
# Picks one of each
|
||||
gen_tav = random.choice(first_part)+" "+random.choice(second_part)+random.choice(third_part)
|
||||
self.bot.log("Generated "+gen_tav)
|
||||
|
||||
# Return the name
|
||||
await ctx.send(gen_tav)
|
||||
# Return the name
|
||||
await ctx.send(gen_tav)
|
||||
|
||||
@@ -6,80 +6,80 @@ import wolframalpha
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
class NerdShit():
|
||||
def __init__(self, bot):
|
||||
"""Runs misc commands."""
|
||||
self.bot = bot
|
||||
def __init__(self, bot):
|
||||
"""Runs misc commands."""
|
||||
self.bot = bot
|
||||
|
||||
async def wolf_search(self,ctx,content):
|
||||
await self.bot.defer(ctx)
|
||||
font = ImageFont.truetype('gwendolyn/resources/fonts/times-new-roman.ttf', 20)
|
||||
self.bot.log("Requesting data")
|
||||
bot = wolframalpha.Client(self.bot.credentials["wolfram_alpha_key"])
|
||||
res = bot.query(content)
|
||||
async def wolf_search(self,ctx,content):
|
||||
await self.bot.defer(ctx)
|
||||
font = ImageFont.truetype('gwendolyn/resources/fonts/times-new-roman.ttf', 20)
|
||||
self.bot.log("Requesting data")
|
||||
bot = wolframalpha.Client(self.bot.credentials["wolfram_alpha_key"])
|
||||
res = bot.query(content)
|
||||
|
||||
self.bot.log("Processing data")
|
||||
titles = []
|
||||
pods = []
|
||||
if int(res.numpods) > 0:
|
||||
for pod in res.pods:
|
||||
titles += [pod.title]
|
||||
for i, sub in enumerate(pod.subpods):
|
||||
pods += [sub]
|
||||
if i > 0:
|
||||
titles += [""]
|
||||
self.bot.log("Processing data")
|
||||
titles = []
|
||||
pods = []
|
||||
if int(res.numpods) > 0:
|
||||
for pod in res.pods:
|
||||
titles += [pod.title]
|
||||
for i, sub in enumerate(pod.subpods):
|
||||
pods += [sub]
|
||||
if i > 0:
|
||||
titles += [""]
|
||||
|
||||
pod_chunks = [pods[x:x+2] for x in range(0, len(pods), 2)]
|
||||
title_chunks = [titles[x:x+2] for x in range(0, len(titles), 2)]
|
||||
await ctx.send(f"Response for \"{content}\"")
|
||||
pod_chunks = [pods[x:x+2] for x in range(0, len(pods), 2)]
|
||||
title_chunks = [titles[x:x+2] for x in range(0, len(titles), 2)]
|
||||
await ctx.send(f"Response for \"{content}\"")
|
||||
|
||||
for i, chunk in enumerate(pod_chunks):
|
||||
width = 0
|
||||
for title in title_chunks[i]:
|
||||
width = max(width,font.getsize(title)[0])
|
||||
height = 5
|
||||
heights = []
|
||||
for count, pod in enumerate(chunk):
|
||||
heights += [height]
|
||||
width = max(width,int(pod.img['@width']))
|
||||
if title_chunks[i][count] == "":
|
||||
place_for_text = 0
|
||||
else:
|
||||
place_for_text = 30
|
||||
height += int(pod.img["@height"]) + 10 + place_for_text
|
||||
for i, chunk in enumerate(pod_chunks):
|
||||
width = 0
|
||||
for title in title_chunks[i]:
|
||||
width = max(width,font.getsize(title)[0])
|
||||
height = 5
|
||||
heights = []
|
||||
for count, pod in enumerate(chunk):
|
||||
heights += [height]
|
||||
width = max(width,int(pod.img['@width']))
|
||||
if title_chunks[i][count] == "":
|
||||
place_for_text = 0
|
||||
else:
|
||||
place_for_text = 30
|
||||
height += int(pod.img["@height"]) + 10 + place_for_text
|
||||
|
||||
width += 10
|
||||
height += 5
|
||||
wolf_image = Image.new("RGB",(width,height),color=(255,255,255))
|
||||
width += 10
|
||||
height += 5
|
||||
wolf_image = Image.new("RGB",(width,height),color=(255,255,255))
|
||||
|
||||
for count, pod in enumerate(chunk):
|
||||
response = requests.get(pod.img["@src"])
|
||||
file = open("gwendolyn/resources/wolfTemp.png", "wb")
|
||||
file.write(response.content)
|
||||
file.close()
|
||||
old_image = Image.open("gwendolyn/resources/wolfTemp.png")
|
||||
old_size = old_image.size
|
||||
if title_chunks[i][count] == "":
|
||||
place_for_text = 0
|
||||
else:
|
||||
place_for_text = 30
|
||||
new_size = (width,int(old_size[1]+10+place_for_text))
|
||||
new_image = Image.new("RGB",new_size,color=(255,255,255))
|
||||
new_image.paste(old_image, (int((int(old_size[0]+10)-old_size[0])/2),int(((new_size[1]-place_for_text)-old_size[1])/2)+place_for_text))
|
||||
if title_chunks[i][count] != "":
|
||||
drawer = ImageDraw.Draw(new_image,"RGB")
|
||||
drawer.text((5,7),title_chunks[i][count],font=font,fill=(150,150,150))
|
||||
for count, pod in enumerate(chunk):
|
||||
response = requests.get(pod.img["@src"])
|
||||
file = open("gwendolyn/resources/wolfTemp.png", "wb")
|
||||
file.write(response.content)
|
||||
file.close()
|
||||
old_image = Image.open("gwendolyn/resources/wolfTemp.png")
|
||||
old_size = old_image.size
|
||||
if title_chunks[i][count] == "":
|
||||
place_for_text = 0
|
||||
else:
|
||||
place_for_text = 30
|
||||
new_size = (width,int(old_size[1]+10+place_for_text))
|
||||
new_image = Image.new("RGB",new_size,color=(255,255,255))
|
||||
new_image.paste(old_image, (int((int(old_size[0]+10)-old_size[0])/2),int(((new_size[1]-place_for_text)-old_size[1])/2)+place_for_text))
|
||||
if title_chunks[i][count] != "":
|
||||
drawer = ImageDraw.Draw(new_image,"RGB")
|
||||
drawer.text((5,7),title_chunks[i][count],font=font,fill=(150,150,150))
|
||||
|
||||
wolf_image.paste(new_image,(0,heights[count]))
|
||||
new_image.close()
|
||||
old_image.close()
|
||||
count += 1
|
||||
wolf_image.paste(new_image,(0,heights[count]))
|
||||
new_image.close()
|
||||
old_image.close()
|
||||
count += 1
|
||||
|
||||
wolf_image.save("gwendolyn/resources/wolf.png")
|
||||
wolf_image.close()
|
||||
await ctx.channel.send(file = discord.File("gwendolyn/resources/wolf.png"))
|
||||
wolf_image.save("gwendolyn/resources/wolf.png")
|
||||
wolf_image.close()
|
||||
await ctx.channel.send(file = discord.File("gwendolyn/resources/wolf.png"))
|
||||
|
||||
os.remove("gwendolyn/resources/wolf.png")
|
||||
os.remove("gwendolyn/resources/wolfTemp.png")
|
||||
else:
|
||||
self.bot.log("No returned data")
|
||||
await ctx.send("Could not find anything relating to your search")
|
||||
os.remove("gwendolyn/resources/wolf.png")
|
||||
os.remove("gwendolyn/resources/wolfTemp.png")
|
||||
else:
|
||||
self.bot.log("No returned data")
|
||||
await ctx.send("Could not find anything relating to your search")
|
||||
|
||||
@@ -17,176 +17,176 @@ fandom.set_lang("da")
|
||||
fandom.set_wiki("senkulpa")
|
||||
|
||||
class MyStringifier(d20.MarkdownStringifier):
|
||||
def _str_expression(self, node):
|
||||
if node.comment is None:
|
||||
result_text = "Result"
|
||||
else:
|
||||
result_text = node.comment.capitalize()
|
||||
def _str_expression(self, node):
|
||||
if node.comment is None:
|
||||
result_text = "Result"
|
||||
else:
|
||||
result_text = node.comment.capitalize()
|
||||
|
||||
return f"**{result_text}**: {self._stringify(node.roll)}\n**Total**: {int(node.total)}"
|
||||
return f"**{result_text}**: {self._stringify(node.roll)}\n**Total**: {int(node.total)}"
|
||||
|
||||
class Other():
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.plex = Plex(self.bot)
|
||||
self.nerd_shit = NerdShit(self.bot)
|
||||
self.generators = Generators(self.bot)
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.plex = Plex(self.bot)
|
||||
self.nerd_shit = NerdShit(self.bot)
|
||||
self.generators = Generators(self.bot)
|
||||
|
||||
# Picks a random movie and returns information about it
|
||||
async def movie_func(self, ctx):
|
||||
await self.bot.defer(ctx)
|
||||
# Picks a random movie and returns information about it
|
||||
async def movie_func(self, ctx):
|
||||
await self.bot.defer(ctx)
|
||||
|
||||
self.bot.log("Creating IMDb object")
|
||||
imdb_client = imdb.IMDb()
|
||||
self.bot.log("Creating IMDb object")
|
||||
imdb_client = imdb.IMDb()
|
||||
|
||||
self.bot.log("Picking a movie")
|
||||
with open("gwendolyn/resources/movies.txt", "r") as file_pointer:
|
||||
movie_list = file_pointer.read().split("\n")
|
||||
movie_name = random.choice(movie_list)
|
||||
self.bot.log("Picking a movie")
|
||||
with open("gwendolyn/resources/movies.txt", "r") as file_pointer:
|
||||
movie_list = file_pointer.read().split("\n")
|
||||
movie_name = random.choice(movie_list)
|
||||
|
||||
self.bot.log(f"Searching for {movie_name}")
|
||||
search_result = imdb_client.search_movie(movie_name)
|
||||
self.bot.log(f"Searching for {movie_name}")
|
||||
search_result = imdb_client.search_movie(movie_name)
|
||||
|
||||
self.bot.log("Getting the data")
|
||||
movie = search_result[0]
|
||||
imdb_client.update(movie)
|
||||
self.bot.log("Getting the data")
|
||||
movie = search_result[0]
|
||||
imdb_client.update(movie)
|
||||
|
||||
self.bot.log("Successfully ran /movie")
|
||||
self.bot.log("Successfully ran /movie")
|
||||
|
||||
title = movie["title"]
|
||||
plot = movie['plot'][0].split("::")[0]
|
||||
cover = movie['cover url'].replace("150","600").replace("101","404")
|
||||
cast = ", ".join([i["name"] for i in movie['cast'][:5]])
|
||||
embed = discord.Embed(title=title, description=plot, color=0x24ec19)
|
||||
embed.set_thumbnail(url=cover)
|
||||
embed.add_field(name="Cast", value=cast,inline = True)
|
||||
await ctx.send(embed = embed)
|
||||
title = movie["title"]
|
||||
plot = movie['plot'][0].split("::")[0]
|
||||
cover = movie['cover url'].replace("150","600").replace("101","404")
|
||||
cast = ", ".join([i["name"] for i in movie['cast'][:5]])
|
||||
embed = discord.Embed(title=title, description=plot, color=0x24ec19)
|
||||
embed.set_thumbnail(url=cover)
|
||||
embed.add_field(name="Cast", value=cast,inline = True)
|
||||
await ctx.send(embed = embed)
|
||||
|
||||
# Responds with a greeting of a time-appropriate maner
|
||||
async def hello_func(self, ctx):
|
||||
def time_in_range(start, end, i):
|
||||
# Return true if i is in the range [start, end]
|
||||
if start <= end:
|
||||
return start <= i <= end
|
||||
else:
|
||||
return start <= i or i <= end
|
||||
# Responds with a greeting of a time-appropriate maner
|
||||
async def hello_func(self, ctx):
|
||||
def time_in_range(start, end, i):
|
||||
# Return true if i is in the range [start, end]
|
||||
if start <= end:
|
||||
return start <= i <= end
|
||||
else:
|
||||
return start <= i or i <= end
|
||||
|
||||
author = ctx.author.display_name
|
||||
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):
|
||||
send_message = "Good morning, "+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):
|
||||
send_message = "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):
|
||||
send_message = "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):
|
||||
send_message = "Good night, "+str(author)
|
||||
else:
|
||||
send_message = "Hello, "+str(author)
|
||||
author = ctx.author.display_name
|
||||
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):
|
||||
send_message = "Good morning, "+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):
|
||||
send_message = "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):
|
||||
send_message = "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):
|
||||
send_message = "Good night, "+str(author)
|
||||
else:
|
||||
send_message = "Hello, "+str(author)
|
||||
|
||||
await ctx.send(send_message)
|
||||
await ctx.send(send_message)
|
||||
|
||||
# Finds a random picture online
|
||||
async def image_func(self, ctx):
|
||||
# Picks a type of camera, which decides the naming scheme
|
||||
cams = ("one","two","three","four")
|
||||
cam = random.choice(cams)
|
||||
self.bot.log("Chose cam type "+cam)
|
||||
if cam == "one":
|
||||
# Finds a random picture online
|
||||
async def image_func(self, ctx):
|
||||
# Picks a type of camera, which decides the naming scheme
|
||||
cams = ("one","two","three","four")
|
||||
cam = random.choice(cams)
|
||||
self.bot.log("Chose cam type "+cam)
|
||||
if cam == "one":
|
||||
|
||||
search = "img_" + ''.join(
|
||||
[str(random.randint(0,9)) for _ in range(4)]
|
||||
)
|
||||
elif cam == "two":
|
||||
year = str(random.randint(2012,2016))
|
||||
month = str(random.randint(1,12)).zfill(2)
|
||||
day = str(random.randint(1,29)).zfill(2)
|
||||
search = f"IMG_{year}{month}{day}"
|
||||
elif cam == "three":
|
||||
search = f"IMAG_{str(random.randint(1,500)).zfill(4)}"
|
||||
elif cam == "four":
|
||||
search = "DSC_" + ''.join(
|
||||
[str(random.randint(0,9)) for _ in range(4)]
|
||||
)
|
||||
search = "img_" + ''.join(
|
||||
[str(random.randint(0,9)) for _ in range(4)]
|
||||
)
|
||||
elif cam == "two":
|
||||
year = str(random.randint(2012,2016))
|
||||
month = str(random.randint(1,12)).zfill(2)
|
||||
day = str(random.randint(1,29)).zfill(2)
|
||||
search = f"IMG_{year}{month}{day}"
|
||||
elif cam == "three":
|
||||
search = f"IMAG_{str(random.randint(1,500)).zfill(4)}"
|
||||
elif cam == "four":
|
||||
search = "DSC_" + ''.join(
|
||||
[str(random.randint(0,9)) for _ in range(4)]
|
||||
)
|
||||
|
||||
self.bot.log("Searching for "+search)
|
||||
self.bot.log("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()
|
||||
tree = lxml.etree.HTML(read)
|
||||
images = tree.xpath('//a[@class = "iusc"]/@m')
|
||||
# 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()
|
||||
tree = lxml.etree.HTML(read)
|
||||
images = tree.xpath('//a[@class = "iusc"]/@m')
|
||||
|
||||
if len(images) == 0:
|
||||
await ctx.send("Found no images")
|
||||
else:
|
||||
# Picks an image
|
||||
number = random.randint(1,len(images))-1
|
||||
image = ast.literal_eval(str(images[number]))
|
||||
image_url = image["murl"]
|
||||
if len(images) == 0:
|
||||
await ctx.send("Found no images")
|
||||
else:
|
||||
# Picks an image
|
||||
number = random.randint(1,len(images))-1
|
||||
image = ast.literal_eval(str(images[number]))
|
||||
image_url = image["murl"]
|
||||
|
||||
self.bot.log("Picked image number "+str(number))
|
||||
self.bot.log("Picked image number "+str(number))
|
||||
|
||||
# Returns the image
|
||||
self.bot.log("Successfully returned an image")
|
||||
# Returns the image
|
||||
self.bot.log("Successfully returned an image")
|
||||
|
||||
await ctx.send(image_url)
|
||||
await ctx.send(image_url)
|
||||
|
||||
# Finds a page from the Senkulpa Wikia
|
||||
async def find_wiki_page(self, ctx, search : str):
|
||||
await self.bot.defer(ctx)
|
||||
found_page = False
|
||||
# Finds a page from the Senkulpa Wikia
|
||||
async def find_wiki_page(self, ctx, search : str):
|
||||
await self.bot.defer(ctx)
|
||||
found_page = False
|
||||
|
||||
if search != "":
|
||||
self.bot.log("Trying to find wiki page for "+search)
|
||||
search_results = fandom.search(search)
|
||||
if len(search_results) > 0:
|
||||
found_page = True
|
||||
search_result = search_results[0]
|
||||
else:
|
||||
self.bot.log("Couldn't find the page")
|
||||
await ctx.send("Couldn't find page")
|
||||
else:
|
||||
found_page = True
|
||||
self.bot.log("Searching for a random page")
|
||||
search_result = fandom.random()
|
||||
if search != "":
|
||||
self.bot.log("Trying to find wiki page for "+search)
|
||||
search_results = fandom.search(search)
|
||||
if len(search_results) > 0:
|
||||
found_page = True
|
||||
search_result = search_results[0]
|
||||
else:
|
||||
self.bot.log("Couldn't find the page")
|
||||
await ctx.send("Couldn't find page")
|
||||
else:
|
||||
found_page = True
|
||||
self.bot.log("Searching for a random page")
|
||||
search_result = fandom.random()
|
||||
|
||||
if found_page:
|
||||
self.bot.log(f"Found page \"{search_result[0]}\"")
|
||||
page = fandom.page(pageid = search_result[1])
|
||||
content = page.summary
|
||||
if found_page:
|
||||
self.bot.log(f"Found page \"{search_result[0]}\"")
|
||||
page = fandom.page(pageid = search_result[1])
|
||||
content = page.summary
|
||||
|
||||
images = page.images
|
||||
if len(images) > 0:
|
||||
image = images[0]
|
||||
else:
|
||||
image = ""
|
||||
self.bot.log("Sending the embedded message",str(ctx.channel_id))
|
||||
content += f"\n[Læs mere]({page.url})"
|
||||
embed = discord.Embed(title = page.title, description = content, colour=0xDEADBF)
|
||||
if image != "":
|
||||
embed.set_thumbnail(url=image)
|
||||
images = page.images
|
||||
if len(images) > 0:
|
||||
image = images[0]
|
||||
else:
|
||||
image = ""
|
||||
self.bot.log("Sending the embedded message",str(ctx.channel_id))
|
||||
content += f"\n[Læs mere]({page.url})"
|
||||
embed = discord.Embed(title = page.title, description = content, colour=0xDEADBF)
|
||||
if image != "":
|
||||
embed.set_thumbnail(url=image)
|
||||
|
||||
await ctx.send(embed = embed)
|
||||
await ctx.send(embed = embed)
|
||||
|
||||
async def roll_dice(self, ctx, roll_string):
|
||||
user = ctx.author.display_name
|
||||
while len(roll_string) > 1 and roll_string[0] == " ":
|
||||
roll_string = roll_string[1:]
|
||||
async def roll_dice(self, ctx, roll_string):
|
||||
user = ctx.author.display_name
|
||||
while len(roll_string) > 1 and roll_string[0] == " ":
|
||||
roll_string = roll_string[1:]
|
||||
|
||||
roll = d20.roll(roll_string, allow_comments=True, stringifier=MyStringifier())
|
||||
await ctx.send(f"{user} :game_die:\n{roll}")
|
||||
roll = d20.roll(roll_string, allow_comments=True, stringifier=MyStringifier())
|
||||
await ctx.send(f"{user} :game_die:\n{roll}")
|
||||
|
||||
async def help_func(self, ctx, command):
|
||||
if command == "":
|
||||
with open("gwendolyn/resources/help/help.txt",encoding="utf-8") as file_pointer:
|
||||
text = file_pointer.read()
|
||||
embed = discord.Embed(title = "Help", description = text,colour = 0x59f442)
|
||||
await ctx.send(embed = embed)
|
||||
else:
|
||||
self.bot.log(f"Looking for help-{command}.txt",str(ctx.channel_id))
|
||||
with open(f"gwendolyn/resources/help/help-{command}.txt",encoding="utf-8") as file_pointer:
|
||||
text = file_pointer.read()
|
||||
embed = discord.Embed(title = command.capitalize(), description = text,colour = 0x59f442)
|
||||
await ctx.send(embed = embed)
|
||||
async def help_func(self, ctx, command):
|
||||
if command == "":
|
||||
with open("gwendolyn/resources/help/help.txt",encoding="utf-8") as file_pointer:
|
||||
text = file_pointer.read()
|
||||
embed = discord.Embed(title = "Help", description = text,colour = 0x59f442)
|
||||
await ctx.send(embed = embed)
|
||||
else:
|
||||
self.bot.log(f"Looking for help-{command}.txt",str(ctx.channel_id))
|
||||
with open(f"gwendolyn/resources/help/help-{command}.txt",encoding="utf-8") as file_pointer:
|
||||
text = file_pointer.read()
|
||||
embed = discord.Embed(title = command.capitalize(), description = text,colour = 0x59f442)
|
||||
await ctx.send(embed = embed)
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user