forked from viveksantayana/geas-bot
Finished Config command group
This commit is contained in:
@ -6,8 +6,9 @@ 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 pprint import pprint
|
||||
|
||||
from bot import clearConfig, configFile, loadCog, loadCogs, setConfig, unloadCog, unloadCogs, yaml_dump, yaml_load
|
||||
from bot import clearConfig, configFile, loadCog, loadCogs, setConfig, unloadCog, unloadCogs, yaml_dump, yaml_load, reloadCog, reloadCogs
|
||||
|
||||
##### Debug Cog
|
||||
class Debug(commands.Cog, name='Debug Commands'):
|
||||
@ -23,9 +24,8 @@ class Debug(commands.Cog, name='Debug Commands'):
|
||||
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)
|
||||
async def _reload(self, ctx, cog_category: str='--all'):
|
||||
reloadCogs(cog_category)
|
||||
await ctx.reply(f'````{cog_category}` cogs have been reloaded.```')
|
||||
|
||||
@commands.command(
|
||||
@ -33,7 +33,7 @@ class Debug(commands.Cog, name='Debug Commands'):
|
||||
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'):
|
||||
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.```')
|
||||
@ -43,30 +43,11 @@ class Debug(commands.Cog, name='Debug Commands'):
|
||||
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'):
|
||||
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','clearcommands','clearslashcommands'],
|
||||
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'],
|
||||
@ -74,10 +55,74 @@ class Debug(commands.Cog, name='Debug Commands'):
|
||||
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)
|
||||
c = await utils.manage_commands.get_all_commands(
|
||||
bot_id=self.client.user.id,
|
||||
bot_token=os.getenv('TEST_3_TOKEN'),
|
||||
guild_id=ctx.guild.id
|
||||
)
|
||||
pprint(c)
|
||||
await ctx.reply(f'```All registered `/commands` have been fetched and sent to the Python console.```')
|
||||
|
||||
@commands.command(
|
||||
name='deletecommand',
|
||||
aliases=['removecommand','delcommand','removeslashcommand', 'clearcommand', 'clearslashcommand'],
|
||||
description='Debugging command that deletes a specified slash command. Key parameters `--all` for all commands in guild and `--global` for all commands globally',
|
||||
brief='Deletes slash command. Default: all local commands.'
|
||||
)
|
||||
async def _deleteCommand(self, ctx:commands.Context, command: str='--all'):
|
||||
if command == '--all' or command == '-a':
|
||||
await utils.manage_commands.remove_all_commands(
|
||||
bot_id=self.client.user.id,
|
||||
bot_token=os.getenv('TEST_3_TOKEN'),
|
||||
guild_ids=[ ctx.guild.id ]
|
||||
)
|
||||
await ctx.reply(f'```All slash commands have been deleted for the guold {ctx.guild.name}.```')
|
||||
elif command == '--global' or command == '-g':
|
||||
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 globally.```')
|
||||
else:
|
||||
c = await utils.manage_commands.get_all_commands(
|
||||
bot_id=self.client.user.id,
|
||||
bot_token=os.getenv('TEST_3_TOKEN'),
|
||||
guild_id=ctx.guild.id
|
||||
)
|
||||
# try:
|
||||
target = list(filter(lambda t: t['name'] == command, c))[0]['id']
|
||||
await utils.manage_commands.remove_slash_command(
|
||||
bot_id=self.client.user.id,
|
||||
bot_token=os.getenv('TEST_3_TOKEN'),
|
||||
guild_id=ctx.guild.id,
|
||||
cmd_id=target
|
||||
)
|
||||
await ctx.reply(f'```Slash command {command} has been deleted for the guild {ctx.guild.name}.```')
|
||||
# except:
|
||||
# raise commands.CommandError(message=f'The command `/{command}` was not found.')
|
||||
|
||||
@commands.command(
|
||||
name='addcommand',
|
||||
aliases=['installcommand','addslashcommand'],
|
||||
description='Adds a slash command to the guild. Use keyword `--global` to add command globally.',
|
||||
brief='Adds slash command'
|
||||
)
|
||||
async def _addCommand(self, ctx:commands.Context, command:str, key:str=''):
|
||||
await utils.manage_commands.add_slash_command(
|
||||
bot_id=self.client.user.id,
|
||||
bot_token=os.getenv('TEST_3_TOKEN'),
|
||||
guild_id= None if key == '--global' or key == '-g' else ctx.guild.id,
|
||||
cmd_name=command,
|
||||
description='No Description'
|
||||
)
|
||||
await ctx.reply(f'```The command /{command} has been added for the guild {ctx.guild.name}.```')
|
||||
|
||||
@commands.command(
|
||||
name='clearconfig',
|
||||
aliases=['configclear'],
|
||||
@ -100,5 +145,41 @@ class Debug(commands.Cog, name='Debug Commands'):
|
||||
setConfig(ctx.guild)
|
||||
await ctx.reply(f'```Config entry has been added for guild `{ctx.guild.name}`.```')
|
||||
|
||||
@commands.command(
|
||||
name='synccommands',
|
||||
aliases=['syncallcommands','syncslashcommands','resynccommands','sync','resync','syncall','resyncall'],
|
||||
description='Syncs all slash commands between the bot and the Server.',
|
||||
brief='Resyncs slash commands.'
|
||||
)
|
||||
async def _synccommands(self, ctx:commands.Context):
|
||||
await self.client.slash.sync_all_commands()
|
||||
await ctx.reply(f'```All slash commands have been synced with the Server.```')
|
||||
|
||||
# @commands.command(
|
||||
# name='removecogcommands',
|
||||
# aliases=['clearcogcommands'],
|
||||
# description='Removes /commands defined in a particular cog.',
|
||||
# brief='Remove /command by cog.'
|
||||
# )
|
||||
# async def _removecogcommands(self, ctx:commands.Context, cogName:str):
|
||||
# try:
|
||||
# SlashCommand.remove_cog_commands(self.client, cogName)
|
||||
# await ctx.reply(f'```All commands from cog `{cogName}` have been removed.```')
|
||||
# except Exception as e:
|
||||
# raise commands.CommandError(e)
|
||||
|
||||
# @commands.command(
|
||||
# name='getcogcommands',
|
||||
# aliases=['addcogcommands'],
|
||||
# description='Adds /commands defined in a particular cog.',
|
||||
# brief='Add /command by cog.'
|
||||
# )
|
||||
# async def _getcogcommands(self, ctx:commands.Context, cogName:str):
|
||||
# try:
|
||||
# SlashCommand.get_cog_commands(cogName)
|
||||
# await ctx.reply(f'```All commands from cog `{cogName}` have been removed.```')
|
||||
# except Exception as e:
|
||||
# raise commands.CommandError(e)
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(Debug(client))
|
Reference in New Issue
Block a user