Files
Gwendolyn/cogs/MiscCog.py
2021-03-31 00:38:51 +02:00

137 lines
4.8 KiB
Python

import discord, codecs, string, json
from discord.ext import commands
from discord_slash import cog_ext
from utils import Options
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
class MiscCog(commands.Cog):
def __init__(self, bot):
"""Runs misc commands."""
self.bot = bot
self.bot.remove_command("help")
self.generators = bot.other.generators
self.bedreNetflix = bot.other.bedreNetflix
self.nerdShit = bot.other.nerdShit
# Sends the bot's latency
@cog_ext.cog_slash(**params["ping"])
async def ping(self, ctx):
await ctx.send(f"Pong!\nLatency is {round(self.bot.latency * 1000)}ms")
# 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...")
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)")
# 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)
# Lets you thank the bot
@cog_ext.cog_slash(**params["thank"])
async def thank(self, ctx):
await ctx.send("You're welcome :blush:")
# 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))
# 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))
# 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())
# Finds a random movie
@cog_ext.cog_slash(**params["movie"])
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())
# Generates a random tavern name
@cog_ext.cog_slash(**params["tavern"])
async def tavern(self, ctx):
await ctx.send(self.generators.tavernGen())
# 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)
#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
@cog_ext.cog_slash(**params["wolf"])
async def wolf(self, ctx, query):
await self.nerdShit.wolfSearch(ctx, query)
def setup(bot):
bot.add_cog(MiscCog(bot))