Started work on converting all commands to slash-commands

This commit is contained in:
NikolajDanger
2021-03-29 00:55:31 +02:00
parent e6e6b9b9b9
commit 232f97d0c8
11 changed files with 363 additions and 179 deletions

View File

@ -1,5 +1,7 @@
import discord, asyncio
from discord.ext import commands
from discord_slash import cog_ext
from discord_slash import SlashCommandOptionType as scot
from funcs import logThis

View File

@ -1,7 +1,19 @@
import discord
import discord, json
from discord.ext import commands
from discord_slash import cog_ext
from discord_slash import SlashCommandOptionType as scot
from funcs import spellFunc, monsterFunc, cap
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 LookupCog(commands.Cog):
@ -10,9 +22,9 @@ class LookupCog(commands.Cog):
self.client = client
# Looks up a spell
@commands.command()
async def spell(self, ctx, *, content):
spell = spellFunc(cap(content))
@cog_ext.cog_slash(**params["spell"])
async def spell(self, ctx, query):
spell = spellFunc(cap(query))
if len(spell) > 2000:
await ctx.send(spell[:2000])
await ctx.send(spell[2000:])
@ -20,12 +32,12 @@ class LookupCog(commands.Cog):
await ctx.send(spell)
# Looks up a monster
@commands.command()
async def monster(self, ctx, *, content):
title, text1, text2, text3, text4, text5 = monsterFunc(cap(content))
@cog_ext.cog_slash(**params["monster"])
async def monster(self, ctx, query):
title, text1, text2, text3, text4, text5 = monsterFunc(cap(query))
em1 = discord.Embed(title = title, description = text1, colour=0xDEADBF)
# Sends the received information. Seperates into seperate messages if
# Sends the received information. Separates into separate messages if
# there is too much text
await ctx.send(embed = em1)
if text2 != "":

View File

@ -1,10 +1,20 @@
import discord, codecs, string
import discord, codecs, string, json
from discord.ext import commands
from discord_slash import cog_ext
from funcs import logThis, helloFunc, roll_dice, imageFunc, movieFunc, cap, findWikiPage
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,client):
"""Runs misc commands."""
self.client = client
@ -13,34 +23,15 @@ class MiscCog(commands.Cog):
self.bedreNetflix = client.bedreNetflix
self.nerdShit = client.nerdShit
@commands.command(name = "help")
async def helpCommand(self, ctx, *, content = ""):
if content == "":
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:
logThis(f"Looking for help-{content}.txt",str(ctx.message.channel.id))
with codecs.open(f"resources/help/help-{content}.txt",encoding="utf-8") as f:
text = f.read()
em = discord.Embed(title = content.capitalize(), description = text,colour = 0x59f442)
await ctx.send(embed = em)
# Sends the bot's latency
@commands.command()
@cog_ext.cog_slash(**params["ping"])
async def ping(self, ctx):
await ctx.send(f"Pong!\nLatency is {round(self.client.latency * 1000)} ms")
# Logs whatever is written
@commands.command(hidden = True)
async def log(self, ctx, *, content):
logThis(content,str("Logged by "+ctx.message.author.display_name))
await ctx.send(f"Pong!\nLatency is {round(self.client.latency * 1000)}ms")
# Restarts the bot
@commands.command(hidden = True,aliases=["stop"])
async def restart(self, ctx):
if "#"+str(ctx.message.author.id) in ["#266269899859427329", "#380732645602230272"]:
@cog_ext.cog_slash(**params["stop"])
async def stop(self, ctx):
if "#"+str(ctx.author.id) in self.client.options.admins:
await ctx.send("Pulling git repo and restarting...")
self.client.funcs.stopServer()
@ -48,103 +39,118 @@ class MiscCog(commands.Cog):
logThis("Logging out.")
await self.client.logout()
else:
logThis(f"{ctx.message.author.display_name} tried to stop me! (error code 201)",str(ctx.message.channel.id))
await ctx.send(f"I don't think I will, {ctx.message.author.display_name} (error code 201)")
logThis(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)")
@commands.command(aliases = ["thankyou", "thanku", "thanks"])
# 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:
logThis(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)
# Let's 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
@commands.command(aliases = ["hi","howdy"])
@cog_ext.cog_slash(**params["hello"])
async def hello(self, ctx):
await ctx.send(helloFunc(ctx.message.author.display_name))
await ctx.send(helloFunc(ctx.author.display_name))
# Rolls dice
@commands.command()
async def roll(self, ctx, *, content = "1d20"):
await ctx.send(roll_dice(ctx.message.author.display_name,content))
# Sends an image of the Senkulpa map
@commands.command(name="map")
async def mapCommand(self, ctx):
await ctx.send("https://i.imgur.com/diMXXJs.jpg")
@cog_ext.cog_slash(**params["roll"])
async def roll(self, ctx, dice = "1d20"):
await ctx.send(roll_dice(ctx.author.display_name,dice))
# Sends a random image
@commands.command(aliases = ["img"])
@cog_ext.cog_slash(**params["image"])
async def image(self, ctx):
randomImage = imageFunc()
await ctx.send(randomImage)
# Finds a random movie
@commands.command()
@cog_ext.cog_slash(**params["movie"])
async def movie(self,ctx):
async with ctx.typing():
title, plot, cover, cast = movieFunc()
if title == "error":
await ctx.send("An error occurred. Try again (error code "+plot+")")
else:
try:
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)
except:
logThis("Error embedding (error code 805)")
await ctx.defer()
title, plot, cover, cast = movieFunc()
if title == "error":
await ctx.send("An error occurred. Try again (error code "+plot+")")
else:
try:
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)
except:
logThis("Error embedding (error code 805)")
# Generates a random name
@commands.command()
@cog_ext.cog_slash(**params["name"])
async def name(self, ctx):
await ctx.send(self.generator.nameGen())
# Generates a random tavern name
@commands.command()
@cog_ext.cog_slash(**params["tavern"])
async def tavern(self, ctx):
await ctx.send(self.generator.tavernGen())
# Sets the game Gwendolyn's playing
@commands.command()
async def game(self, ctx, *, content):
gamePlaying = cap(content)
@cog_ext.cog_slash(**params["game"])
async def game(self, ctx, gameText):
gamePlaying = cap(gameText)
game = discord.Game(gamePlaying)
await self.client.change_presence(activity=game)
await ctx.send(f"Setting game to \"{gamePlaying}\"")
# Finds a page on the Senkulpa wiki
@commands.command(aliases = ["wikia"])
async def wiki(self, ctx, *, content):
async with ctx.message.channel.typing():
command = string.capwords(content)
title, content, thumbnail = findWikiPage(command)
if title != "":
logThis("Sending the embedded message",str(ctx.message.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)
@cog_ext.cog_slash(**params["wiki"])
async def wiki(self, ctx, wikiPage):
await ctx.defer()
command = string.capwords(wikiPage)
title, content, thumbnail = findWikiPage(command)
if title != "":
logThis("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 ctx.send(embed = embed)
else:
await ctx.send(content)
#Searches for movie and adds it to Bedre Netflix
@commands.command(aliases = ["rm","addmovie","am"])
async def requestmovie(self, ctx, *, content):
await self.bedreNetflix.requestMovie(ctx,content)
@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
@commands.command(aliases = ["rs","addshow","as","addseries"])
async def requestshow(self, ctx, *, content):
await self.bedreNetflix.requestShow(ctx,content)
@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
@commands.command(aliases = ["downloads"])
async def downloading(self, ctx, *, content = "-d"):
await self.bedreNetflix.downloading(ctx, content)
@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
@commands.command()
async def wolf(self, ctx, *, content):
await self.nerdShit.wolfSearch(ctx,content)
@cog_ext.cog_slash(**params["wolf"])
async def wolf(self, ctx, query):
await self.nerdShit.wolfSearch(ctx, query)
def setup(client):
client.add_cog(MiscCog(client))

View File

@ -1,5 +1,6 @@
import discord, string
from discord.ext import commands
from discord_slash import cog_ext
from funcs import cap
@ -10,16 +11,16 @@ class SwCog(commands.Cog):
self.client = client
# Rolls star wars dice
@commands.command()
async def swroll(self, ctx, *, content = ""):
command = cap(content)
@cog_ext.cog_slash()
async def swroll(self, ctx, dice = ""):
command = cap(dice)
newMessage = self.client.swroll.parseRoll("#"+str(ctx.message.author.id),command)
messageList = newMessage.split("\n")
for messageItem in messageList:
await ctx.send(messageItem)
# Controls destiny points
@commands.command()
@cog_ext.cog_slash()
async def swd(self, ctx, *, content):
newMessage = self.client.swdestiny.parseDestiny("#"+str(ctx.message.author.id),content)
messageList = newMessage.split("\n")
@ -27,7 +28,7 @@ class SwCog(commands.Cog):
await ctx.send(messageItem)
# Rolls for critical injuries
@commands.command()
@cog_ext.cog_slash()
async def swcrit(self, ctx, arg : int = 0):
newMessage = self.client.swroll.critRoll(int(arg))
@ -37,7 +38,7 @@ class SwCog(commands.Cog):
# Accesses and changes character sheet data with the parseChar function
# from funcs/swfuncs/swchar.py
@commands.command(aliases=["sw"])
@cog_ext.cog_slash()
async def swchar(self, ctx, *, content = ""):
command = string.capwords(content.replace("+","+ ").replace("-","- ").replace(",",", "))
title, desc = self.client.swchar.parseChar("#"+str(ctx.message.author.id),command)