✨ Converted misc functionality to slash commands
This commit is contained in:
@ -10,6 +10,8 @@ from .bedreNetflix import BedreNetflix
|
||||
from .nerdShit import NerdShit
|
||||
from .generators import Generators
|
||||
|
||||
from utils import cap
|
||||
|
||||
class MyStringifier(d20.MarkdownStringifier):
|
||||
def _str_expression(self, node):
|
||||
if node.comment == None:
|
||||
@ -57,29 +59,31 @@ class Other():
|
||||
await ctx.send(embed = embed)
|
||||
|
||||
# Responds with a greeting of a time-appropriate maner
|
||||
def helloFunc(self, author):
|
||||
async def helloFunc(self, ctx):
|
||||
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
|
||||
|
||||
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):
|
||||
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))
|
||||
sendMessage = "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):
|
||||
return("Good afternoon, "+str(author))
|
||||
sendMessage = "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))
|
||||
sendMessage = "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))
|
||||
sendMessage = "Good night, "+str(author)
|
||||
else:
|
||||
return("Hello, "+str(author))
|
||||
sendMessage = "Hello, "+str(author)
|
||||
|
||||
await ctx.send(sendMessage)
|
||||
|
||||
# Finds a random picture online
|
||||
def imageFunc(self):
|
||||
async def imageFunc(self, ctx):
|
||||
# Picks a type of camera, which decides the naming scheme
|
||||
cams = ("one","two","three","four")
|
||||
cam = random.choice(cams)
|
||||
@ -113,22 +117,31 @@ class Other():
|
||||
tree = lxml.etree.HTML(read)
|
||||
images = tree.xpath('//a[@class = "thumb"]/@href')
|
||||
|
||||
# Picks an image
|
||||
number = random.randint(1,len(images))-1
|
||||
image = images[number]
|
||||
if len(images) == 0:
|
||||
await ctx.send("Found no images")
|
||||
else:
|
||||
# Picks an image
|
||||
number = random.randint(1,len(images))-1
|
||||
image = images[number]
|
||||
|
||||
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")
|
||||
return(image)
|
||||
# Returns the image
|
||||
self.bot.log("Successfully returned an image")
|
||||
|
||||
await ctx.send(image)
|
||||
|
||||
# Finds a page from the Senkulpa Wikia
|
||||
def findWikiPage(self, search : str):
|
||||
async def findWikiPage(self, ctx, search : str):
|
||||
await ctx.defer()
|
||||
search = cap(search)
|
||||
foundPage = False
|
||||
|
||||
self.bot.log("Trying to find wiki page for "+search)
|
||||
wikia.set_lang("da")
|
||||
searchResults = wikia.search("senkulpa",search)
|
||||
if len(searchResults) > 0:
|
||||
foundPage = True
|
||||
searchResult = searchResults[0].replace(",","%2C")
|
||||
self.bot.log("Found page \""+searchResult+"\"")
|
||||
page = wikia.page("senkulpa",searchResult)
|
||||
@ -137,15 +150,39 @@ class Other():
|
||||
images = page.images
|
||||
if len(images) > 0:
|
||||
image = images[len(images)-1]+"/revision/latest?path-prefix=da"
|
||||
return page.title, content, image
|
||||
else:
|
||||
return page.title, content, ""
|
||||
image = ""
|
||||
else:
|
||||
self.bot.log("Couldn't find the page (error code 1002)")
|
||||
return "", "Couldn't find page (error code 1002)", ""
|
||||
self.bot.log("Couldn't find the page")
|
||||
await ctx.send("Couldn't find page (error code 1002)")
|
||||
|
||||
def rollDice(self, user, rollString):
|
||||
if foundPage:
|
||||
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)
|
||||
|
||||
async def rollDice(self, ctx, rollString):
|
||||
user = ctx.author.display_name
|
||||
while len(rollString) > 1 and rollString[0] == " ":
|
||||
rollString = rollString[1:]
|
||||
return user+" :game_die:\n"+str(d20.roll(rollString, allow_comments=True,stringifier=MyStringifier()))
|
||||
|
||||
roll = d20.roll(rollString, allow_comments=True, stringifier=MyStringifier())
|
||||
await ctx.send(f"{user} :game_die:\n{roll}")
|
||||
|
||||
async def helpFunc(self, ctx, command):
|
||||
if command == "":
|
||||
with open("resources/help/help.txt",encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
em = discord.Embed(title = "Help", description = text,colour = 0x59f442)
|
||||
await ctx.send(embed = em)
|
||||
else:
|
||||
self.bot.log(f"Looking for help-{command}.txt",str(ctx.channel_id))
|
||||
with open(f"resources/help/help-{command}.txt",encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
em = discord.Embed(title = command.capitalize(), description = text,colour = 0x59f442)
|
||||
await ctx.send(embed = em)
|
||||
|
||||
|
Reference in New Issue
Block a user