Converted misc functionality to slash commands

This commit is contained in:
NikolajDanger
2021-04-06 11:02:12 +02:00
parent b3b81b2b50
commit 682a20f62d
5 changed files with 96 additions and 82 deletions

View File

@ -2,16 +2,9 @@ import discord, codecs, string, json
from discord.ext import commands
from discord_slash import cog_ext
from utils import Options
from utils import getParams
with open("resources/slashParameters.json", "r") as f:
params = json.load(f)
options = Options()
if options.testing:
for p in params:
params[p]["guild_ids"] = options.guildIds
params = getParams()
class MiscCog(commands.Cog):
def __init__(self, bot):
@ -30,33 +23,12 @@ class MiscCog(commands.Cog):
# Restarts the bot
@cog_ext.cog_slash(**params["stop"])
async def stop(self, ctx):
if "#"+str(ctx.author.id) in self.bot.options.admins:
await ctx.send("Pulling git repo and restarting...")
await self.bot.change_presence(status = discord.Status.offline)
self.bot.databaseFuncs.stopServer()
self.bot.log("Logging out.")
await self.bot.logout()
else:
self.bot.log(f"{ctx.author.display_name} tried to stop me! (error code 201)",str(ctx.channel_id))
await ctx.send(f"I don't think I will, {ctx.author.display_name} (error code 201)")
await self.bot.stop(ctx)
# Gets help for specific command
@cog_ext.cog_slash(**params["help"])
async def helpCommand(self, ctx, command = ""):
if command == "":
with codecs.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 codecs.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)
await self.bot.other.helpFunc(ctx, command)
# Lets you thank the bot
@cog_ext.cog_slash(**params["thank"])
@ -66,67 +38,51 @@ class MiscCog(commands.Cog):
# Sends a friendly message
@cog_ext.cog_slash(**params["hello"])
async def hello(self, ctx):
await ctx.send(self.bot.other.helloFunc(ctx.author.display_name))
await self.bot.other.helloFunc(ctx)
# Rolls dice
@cog_ext.cog_slash(**params["roll"])
async def roll(self, ctx, dice = "1d20"):
await ctx.send(self.bot.other.rollDice(ctx.author.display_name, dice))
await self.bot.other.rollDice(ctx, dice)
# Sends a random image
@cog_ext.cog_slash(**params["image"])
async def image(self, ctx):
await ctx.defer()
await ctx.send(self.bot.other.imageFunc())
await self.bot.other.imageFunc(ctx)
# Finds a random movie
@cog_ext.cog_slash(**params["movie"])
async def movie(self,ctx):
async def movie(self, ctx):
await self.bot.other.movieFunc(ctx)
# Generates a random name
@cog_ext.cog_slash(**params["name"])
async def name(self, ctx):
await ctx.send(self.generators.nameGen())
await self.generators.nameGen(ctx)
# Generates a random tavern name
@cog_ext.cog_slash(**params["tavern"])
async def tavern(self, ctx):
await ctx.send(self.generators.tavernGen())
await self.generators.tavernGen(ctx)
# Finds a page on the Senkulpa wiki
@cog_ext.cog_slash(**params["wiki"])
async def wiki(self, ctx, wikiPage):
await ctx.defer()
command = string.capwords(wikiPage)
title, content, thumbnail = self.bot.otherfindWikiPage(command)
if title != "":
self.bot.log("Sending the embedded message",str(ctx.channel_id))
content += "\n[Læs mere](https://senkulpa.fandom.com/da/wiki/"+title.replace(" ","_")+")"
embed = discord.Embed(title = title, description = content, colour=0xDEADBF)
if thumbnail != "":
embed.set_thumbnail(url=thumbnail)
await ctx.send(embed = embed)
else:
await ctx.send(content)
await self.bot.other.findWikiPage(ctx, wikiPage)
#Searches for movie and adds it to Bedre Netflix
@cog_ext.cog_slash(**params["addMovie"])
async def addMovie(self, ctx, movie):
await ctx.defer()
await self.bedreNetflix.requestMovie(ctx, movie)
#Searches for show and adds it to Bedre Netflix
@cog_ext.cog_slash(**params["addShow"])
async def addShow(self, ctx, show):
await ctx.defer()
await self.bedreNetflix.requestShow(ctx, show)
#Returns currently downloading torrents
@cog_ext.cog_slash(**params["downloading"])
async def downloading(self, ctx, parameters = "-d"):
await ctx.defer()
await self.bedreNetflix.downloading(ctx, parameters)
#Looks up on Wolfram Alpha