From 232f97d0c8b9e830d7621e9e68ba4678d6511033 Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Mon, 29 Mar 2021 00:55:31 +0200 Subject: [PATCH] :sparkles: Started work on converting all commands to slash-commands --- Gwendolyn.py | 26 ++--- cogs/GamesCog.py | 2 + cogs/LookupCog.py | 28 ++++-- cogs/MiscCog.py | 174 +++++++++++++++++---------------- cogs/SwCog.py | 13 +-- funcs/other/bedreNetflix.py | 4 +- funcs/other/nerdShit.py | 125 +++++++++++------------ resources/slashParameters.json | 154 +++++++++++++++++++++++++++++ resources/startingFiles.json | 2 +- utils/__init__.py | 5 + utils/options.py | 9 ++ 11 files changed, 363 insertions(+), 179 deletions(-) create mode 100644 resources/slashParameters.json create mode 100644 utils/__init__.py create mode 100644 utils/options.py diff --git a/Gwendolyn.py b/Gwendolyn.py index a07cafd..94696b8 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -1,10 +1,10 @@ import discord, os, finnhub, platform, asyncio, traceback from discord.ext import commands +from discord_slash import SlashCommand from pymongo import MongoClient from funcs import logThis, makeFiles, Money, Funcs, SwChar, SwDestiny, SwRoll, Games, Generators, BedreNetflix, NerdShit - -commandPrefix = "!" +from utils import Options if platform.system() == "Windows": asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) @@ -23,14 +23,6 @@ class Credentials(): self.radarrKey = data[6][15:].replace(" ","") self.sonarrKey = data[7][15:].replace(" ","") -class Options(): - def __init__(self): - with open("options.txt","r") as f: - data = f.read().splitlines() - - self.prefix = data[0][7:].replace(" ","") - self.testing = (data[1][8:].replace(" ","").lower() == "true") - class Gwendolyn(commands.Bot): def __init__(self): self.options = Options() @@ -57,13 +49,15 @@ class Gwendolyn(commands.Bot): self.money = Money(self) self.funcs = Funcs(self) - super().__init__(command_prefix=commandPrefix, case_insensitive=True) + super().__init__(command_prefix=" ", case_insensitive=True) + # Creates the required files makeFiles() # Creates the Bot client = Gwendolyn() +slash = SlashCommand(client, sync_commands=True, sync_on_cog_reload=True, override_type=True) # Logs in @client.event @@ -74,16 +68,16 @@ async def on_ready(): # Logs when user sends a command @client.event -async def on_command(ctx): - logThis(f"{ctx.message.author.display_name} ran {ctx.message.content}") +async def on_slash_command(ctx): + logThis(f"{ctx.author.display_name} ran {ctx.name}") # Logs if a command experiences an error @client.event -async def on_command_error(ctx, error): +async def on_slash_command_error(ctx, error): if isinstance(error, commands.CommandNotFound): await ctx.send("That's not a command (error code 001)") elif isinstance(error,commands.errors.MissingRequiredArgument): - logThis(f"{error}",str(ctx.message.channel.id)) + logThis(f"{error}",str(ctx.channel_id)) await ctx.send("Missing command parameters (error code 002). Try using `!help [command]` to find out how to use the command.") else: exception = traceback.format_exception(type(error), error, error.__traceback__) @@ -93,7 +87,7 @@ async def on_command_error(ctx, error): exception = exception[:index] exceptionString = "".join(exception) - logThis([f"exception in command !{ctx.command}", f"{exceptionString}"],str(ctx.message.channel.id), 40) + logThis([f"exception in {ctx.name} command", f"{exceptionString}"],str(ctx.channel_id), 40) await ctx.send("Something went wrong (error code 000)") #Loads cogs diff --git a/cogs/GamesCog.py b/cogs/GamesCog.py index ef33952..3a177aa 100644 --- a/cogs/GamesCog.py +++ b/cogs/GamesCog.py @@ -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 diff --git a/cogs/LookupCog.py b/cogs/LookupCog.py index 5296db5..b272fda 100644 --- a/cogs/LookupCog.py +++ b/cogs/LookupCog.py @@ -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 != "": diff --git a/cogs/MiscCog.py b/cogs/MiscCog.py index 91f560a..18aeef0 100644 --- a/cogs/MiscCog.py +++ b/cogs/MiscCog.py @@ -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)) diff --git a/cogs/SwCog.py b/cogs/SwCog.py index 4e63fac..adfd980 100644 --- a/cogs/SwCog.py +++ b/cogs/SwCog.py @@ -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) diff --git a/funcs/other/bedreNetflix.py b/funcs/other/bedreNetflix.py index ac13937..034befe 100644 --- a/funcs/other/bedreNetflix.py +++ b/funcs/other/bedreNetflix.py @@ -83,7 +83,7 @@ class BedreNetflix(): await channel.send(postData["title"]+" successfully added to Bedre Netflix") logThis("Added "+postData["title"]+" to Bedre Netflix") elif r.status_code == 400: - await channel.send("The movie is already requested for Bedre Netflix") + await channel.send("The movie is already requested for or added to Bedre Netflix") else: await channel.send("Something went wrong") logThis(str(r.status_code)+" "+r.reason) @@ -159,7 +159,7 @@ class BedreNetflix(): await channel.send(postData["title"]+" successfully added to Bedre Netflix") logThis("Added a "+postData["title"]+" to Bedre Netflix") elif r.status_code == 400: - await channel.send("The show is already requested for Bedre Netflix") + await channel.send("The show is already requested for or added to Bedre Netflix") else: await channel.send("Something went wrong") logThis(str(r.status_code)+" "+r.reason) diff --git a/funcs/other/nerdShit.py b/funcs/other/nerdShit.py index a786a0b..21730f3 100644 --- a/funcs/other/nerdShit.py +++ b/funcs/other/nerdShit.py @@ -9,73 +9,74 @@ class NerdShit(): async def wolfSearch(self,ctx,content): fnt = ImageFont.truetype('resources/times-new-roman.ttf', 20) - async with ctx.message.channel.typing(): - logThis("Requesting data") - client = wolframalpha.Client(self.client.credentials.wolfKey) - res = client.query(content) + await ctx.defer() + logThis("Requesting data") + client = wolframalpha.Client(self.client.credentials.wolfKey) + res = client.query(content) - logThis("Processing data") - titles = [] - pods = [] - if int(res.numpods) > 0: - for pod in res.pods: - titles += [pod.title] - for x, sub in enumerate(pod.subpods): - pods += [sub] - if x > 0: - titles += [""] + logThis("Processing data") + titles = [] + pods = [] + if int(res.numpods) > 0: + for pod in res.pods: + titles += [pod.title] + for x, sub in enumerate(pod.subpods): + pods += [sub] + if x > 0: + titles += [""] - podChunks = [pods[x:x+2] for x in range(0, len(pods), 2)] - titleChucks = [titles[x:x+2] for x in range(0, len(titles), 2)] + podChunks = [pods[x:x+2] for x in range(0, len(pods), 2)] + titleChucks = [titles[x:x+2] for x in range(0, len(titles), 2)] + await ctx.send(f"Response for \"{content}\"") - for x, chunk in enumerate(podChunks): - width = 0 - for title in titleChucks[x]: - width = max(width,fnt.getsize(title)[0]) - height = 5 - heights = [] - for count, pod in enumerate(chunk): - heights += [height] - width = max(width,int(list(pod.img)[0]["@width"])) - if titleChucks[x][count] == "": - placeForText = 0 - else: - placeForText = 30 - height += int(list(pod.img)[0]["@height"]) + 10 + placeForText + for x, chunk in enumerate(podChunks): + width = 0 + for title in titleChucks[x]: + width = max(width,fnt.getsize(title)[0]) + height = 5 + heights = [] + for count, pod in enumerate(chunk): + heights += [height] + width = max(width,int(list(pod.img)[0]["@width"])) + if titleChucks[x][count] == "": + placeForText = 0 + else: + placeForText = 30 + height += int(list(pod.img)[0]["@height"]) + 10 + placeForText - width += 10 - height += 5 - wolfImage = Image.new("RGB",(width,height),color=(255,255,255)) + width += 10 + height += 5 + wolfImage = Image.new("RGB",(width,height),color=(255,255,255)) - for count, pod in enumerate(chunk): - response = requests.get(list(pod.img)[0]["@src"]) - file = open("resources/wolfTemp.png", "wb") - file.write(response.content) - file.close() - oldImage = Image.open("resources/wolfTemp.png") - oldSize = oldImage.size - if titleChucks[x][count] == "": - placeForText = 0 - else: - placeForText = 30 - newSize = (width,int(oldSize[1]+10+placeForText)) - newImage = Image.new("RGB",newSize,color=(255,255,255)) - newImage.paste(oldImage, (int((int(oldSize[0]+10)-oldSize[0])/2),int(((newSize[1]-placeForText)-oldSize[1])/2)+placeForText)) - if titleChucks[x][count] != "": - d = ImageDraw.Draw(newImage,"RGB") - d.text((5,7),titleChucks[x][count],font=fnt,fill=(150,150,150)) + for count, pod in enumerate(chunk): + response = requests.get(list(pod.img)[0]["@src"]) + file = open("resources/wolfTemp.png", "wb") + file.write(response.content) + file.close() + oldImage = Image.open("resources/wolfTemp.png") + oldSize = oldImage.size + if titleChucks[x][count] == "": + placeForText = 0 + else: + placeForText = 30 + newSize = (width,int(oldSize[1]+10+placeForText)) + newImage = Image.new("RGB",newSize,color=(255,255,255)) + newImage.paste(oldImage, (int((int(oldSize[0]+10)-oldSize[0])/2),int(((newSize[1]-placeForText)-oldSize[1])/2)+placeForText)) + if titleChucks[x][count] != "": + d = ImageDraw.Draw(newImage,"RGB") + d.text((5,7),titleChucks[x][count],font=fnt,fill=(150,150,150)) - wolfImage.paste(newImage,(0,heights[count])) - newImage.close() - oldImage.close() - count += 1 + wolfImage.paste(newImage,(0,heights[count])) + newImage.close() + oldImage.close() + count += 1 - wolfImage.save("resources/wolf.png") - wolfImage.close() - await ctx.message.channel.send(file = discord.File("resources/wolf.png")) + wolfImage.save("resources/wolf.png") + wolfImage.close() + await ctx.send(file = discord.File("resources/wolf.png")) - os.remove("resources/wolf.png") - os.remove("resources/wolfTemp.png") - else: - logThis("No returned data") - await ctx.message.channel.send("Could not find anything relating to your search") \ No newline at end of file + os.remove("resources/wolf.png") + os.remove("resources/wolfTemp.png") + else: + logThis("No returned data") + await ctx.send("Could not find anything relating to your search") \ No newline at end of file diff --git a/resources/slashParameters.json b/resources/slashParameters.json new file mode 100644 index 0000000..cb1c2a3 --- /dev/null +++ b/resources/slashParameters.json @@ -0,0 +1,154 @@ +{ + "addMovie" : { + "name" : "addMovie", + "description" : "Request a movie for Bedre Netflix", + "options" : [ + { + "name" : "movie", + "description" : "The movie to request", + "type" : 3, + "required" : "true" + } + ] + }, + "addShow" : { + "name" : "addShow", + "description" : "Request a show for Bedre Netflix", + "options" : [ + { + "name" : "show", + "description" : "The show to request", + "type" : 3, + "required" : "true" + } + ] + }, + "downloading" : { + "name" : "downloading", + "description" : "See current downloads for Bedre Netflix", + "options" : [ + { + "name" : "parameters", + "description" : "Parameters for the command", + "type" : 3, + "required" : "false" + } + ] + }, + "game" : { + "name" : "game", + "description" : "Set the 'playing' text for Gwendolyn", + "options" : [ + { + "name" : "gameText", + "description" : "The game to set the 'playing' text to", + "type" : 3, + "required" : "true" + } + ] + }, + "hello" : { + "name" : "hello", + "description" : "Greet Gwendolyn" + }, + "help" : { + "name" : "help", + "description" : "Get help with a command", + "options" : [ + { + "name" : "command", + "description" : "The command you want help with", + "type" : 3, + "required" : "false" + } + ] + }, + "image" : { + "name" : "image", + "description" : "Get a random image from Bing" + }, + "monster" : { + "name" : "monster", + "description" : "Look up a monster", + "options" : [ + { + "name" : "query", + "description" : "The monster to look up", + "type" : 3, + "required" : "true" + } + ] + }, + "movie" : { + "name" : "movie", + "description" : "Get the name and information of a random movie" + }, + "name" : { + "name" : "name", + "description" : "Generate a random name" + }, + "ping" : { + "name" : "ping", + "description" : "Get the Gwendolyn's latency to the server" + }, + "roll" : { + "name" : "roll", + "description" : "Roll rpg dice", + "options" : [ + { + "name" : "dice", + "description" : "The dice to roll", + "type" : 3, + "required" : "false" + } + ] + }, + "spell" : { + "name" : "spell", + "description" : "Look up a spell", + "options" : [ + { + "name" : "query", + "description" : "The spell to look up", + "type" : 3, + "required" : "true" + } + ] + }, + "stop" : { + "name" : "stop", + "description" : "Restart Gwendolyn" + }, + "tavern" : { + "name" : "tavern", + "description" : "Generate a random tavern" + }, + "thank" : { + "name" : "thank", + "description" : "Thank Gwendolyn for her service" + }, + "wiki" : { + "name" : "wiki", + "description" : "Searches for and gets the info for a wiki page", + "options" : [ + { + "name" : "wikiPage", + "description" : "The page to find", + "type" : 3, + "required" : "true" + } + ] + }, + "wolf" : { + "name" : "wolf", + "description" : "Performs a search on Wolfram Alpha", + "options" : [ + { + "name" : "query", + "description" : "What to search for on Wolfram Alpha", + "type" : 3, + "required" : "true" + } + ] + } +} \ No newline at end of file diff --git a/resources/startingFiles.json b/resources/startingFiles.json index baaa5f4..a17b123 100644 --- a/resources/startingFiles.json +++ b/resources/startingFiles.json @@ -60,7 +60,7 @@ "resources/movies.txt": "The Room", "resources/names.txt": "Gandalf", "credentials.txt" : "Bot token: TOKEN\nFinnhub API key: KEY\nWordnik API Key: KEY\nMongoDB user: USERNAME\nMongoDB password: PASSWORD\nWolframAlpha AppID: APPID\nRadarr API key: KEY\nSonarr API key: KEY", - "options.txt" : "Prefix: !\nTesting: True" + "options.txt" : "Testing: True" }, "folder" : [ "resources/games/blackjackTables", diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 0000000..2c13604 --- /dev/null +++ b/utils/__init__.py @@ -0,0 +1,5 @@ +"""A collections of utilities used by Gwendolyn and her functions""" + +__all__ = ["Options"] + +from .options import Options \ No newline at end of file diff --git a/utils/options.py b/utils/options.py new file mode 100644 index 0000000..5eebf7d --- /dev/null +++ b/utils/options.py @@ -0,0 +1,9 @@ +class Options(): + def __init__(self): + with open("options.txt","r") as f: + data = f.read().splitlines() + + self.testing = (data[0][8:].replace(" ","").lower() == "true") + guildIds = data[1][17:].replace(" ","").split(",") + self.guildIds = [int(i) for i in guildIds] + self.admins = data[2][7:].replace(" ","").split(",") \ No newline at end of file