forked from viveksantayana/geas-bot
103 lines
4.0 KiB
Python
103 lines
4.0 KiB
Python
import os
|
|
from dotenv import load_dotenv # Import OS variables from Dotenv file.
|
|
load_dotenv() # Load Dotenv. Delete this for production
|
|
import asyncio # Discord Py Dependency
|
|
import discord # Main Lib
|
|
from discord.ext import commands # Commands module
|
|
from discord_slash import SlashCommand, SlashContext, cog_ext, utils # Slash Command Library
|
|
from discord_slash.utils.manage_commands import create_choice, create_option # Slash Command features
|
|
|
|
from bot import clearConfig, configFile, loadCog, loadCogs, setConfig, unloadCog, unloadCogs, yaml_dump, yaml_load
|
|
|
|
##### Debug Cog
|
|
class Debug(commands.Cog, name='Debug Commands'):
|
|
def __init__(self, client):
|
|
self.client = client
|
|
|
|
#### Permission Check: Only available to the bot's maintainer.
|
|
async def cog_check(self, ctx):
|
|
return ctx.author.id == int(os.getenv('BOT_MAINTAINER_ID'))
|
|
|
|
@commands.command(
|
|
name='reloadcogs',
|
|
description='Reloads cogs within the specified category, or provide `all` for all cogs. Default: `all`.',
|
|
brief='Reload multiple cogs by category.'
|
|
)
|
|
async def _reload(self, ctx, cog_category: str='all'):
|
|
unloadCogs(cog_category)
|
|
loadCogs(cog_category)
|
|
await ctx.reply(f'`{cog_category}` cogs have been reloaded.')
|
|
|
|
@commands.command(
|
|
name='unloadcogs',
|
|
description='Unload cogs within the specified category, or provide `all` for all cogs. Default: `all`.',
|
|
brief='Unload multiple cogs by category.'
|
|
)
|
|
async def _unloadcogs(self, ctx, cog_category: str='all'):
|
|
unloadCogs(cog_category)
|
|
loadCogs(cog_category)
|
|
await ctx.reply(f'`{cog_category}` cogs have been unloaded.')
|
|
|
|
@commands.command(
|
|
name='loadcogs',
|
|
description='Load cogs within the specified category, or provide `all` for all cogs. Default: `all`.',
|
|
brief='Load multiple cogs by category.'
|
|
)
|
|
async def _loadcogs(self, ctx, cog_category: str='all'):
|
|
unloadCogs(cog_category)
|
|
loadCogs(cog_category)
|
|
await ctx.reply(f'`{cog_category}` cogs have been loaded.')
|
|
|
|
@commands.command(
|
|
name='deletecommands',
|
|
aliases=['delallcommands','deleteslashcommands'],
|
|
description='Deletes all the public and guild slash commands registered by the bot.',
|
|
brief='Delets all slash commands'
|
|
)
|
|
async def _deleteAll(self, ctx):
|
|
await utils.manage_commands.remove_all_commands(
|
|
bot_id=self.client.user.id,
|
|
bot_token=os.getenv('TEST_3_TOKEN'),
|
|
guild_ids=None
|
|
)
|
|
await utils.manage_commands.remove_all_commands(
|
|
bot_id=self.client.user.id,
|
|
bot_token=os.getenv('TEST_3_TOKEN'),
|
|
guild_ids=[ int(g) for g in yaml_load(configFile)]
|
|
)
|
|
await ctx.reply('All slash commands have been deleted.')
|
|
|
|
@commands.command(
|
|
name='retrievecommands',
|
|
aliases=['slashcommands','retrieveslashcommands'],
|
|
description='Debugging command that retrieves all slash commands currently registered for this guild and this bot to the Python console.',
|
|
brief='Retrieves registered slash commands to console.'
|
|
)
|
|
async def _retrievecommands(self, ctx:commands.Context):
|
|
c = await utils.manage_commands.get_all_commands(self.client.user.id,os.getenv('TEST_3_TOKEN'),guild_id=ctx.guild.id)
|
|
print(c)
|
|
|
|
@commands.command(
|
|
name='clearconfig',
|
|
aliases=['configclear'],
|
|
description='Clears any redundant entries in the config file of guilds the bot is not in. Does not require any argument.',
|
|
brief='Clears redundant entries from config file.'
|
|
)
|
|
async def _clearconfig(self, ctx:commands.Context):
|
|
conf = yaml_load(configFile)
|
|
for key in list(conf):
|
|
clearConfig(key)
|
|
await ctx.reply(f'Config entries have been cleared.')
|
|
|
|
@commands.command(
|
|
name='setconfig',
|
|
aliases=['configsetup'],
|
|
description='Creates a config entry for the current guild, and if there are existing entries sets default values. Ignores any values that have already been set. Does not require any argument as it infers the guild from the context in which it was called.',
|
|
brief='Sets config entry for the current guild.'
|
|
)
|
|
async def _setconfig(self, ctx:commands.Context):
|
|
setConfig(ctx.guild)
|
|
await ctx.reply(f'Config entry has been added for guild `{ctx.guild.name}`.')
|
|
|
|
def setup(client):
|
|
client.add_cog(Debug(client)) |