mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-06 09:22:31 -05:00
Allow force enabling app commands using flag in extras (#6018)
This commit is contained in:
@@ -61,7 +61,11 @@ class RedTree(CommandTree):
|
||||
Commands will be internally stored until enabled by ``[p]slash enable``.
|
||||
"""
|
||||
# Allow guild specific commands to bypass the internals for development
|
||||
if guild is not MISSING or guilds is not MISSING:
|
||||
if (
|
||||
guild is not MISSING
|
||||
or guilds is not MISSING
|
||||
or command.extras.get("red_force_enable", False)
|
||||
):
|
||||
return super().add_command(
|
||||
command, *args, guild=guild, guilds=guilds, override=override, **kwargs
|
||||
)
|
||||
@@ -171,45 +175,60 @@ class RedTree(CommandTree):
|
||||
"""
|
||||
enabled_commands = await self.client.list_enabled_app_commands()
|
||||
|
||||
to_add_commands = []
|
||||
to_add_context = []
|
||||
to_remove_commands = []
|
||||
to_remove_context = []
|
||||
to_add_commands = set()
|
||||
to_add_context = set()
|
||||
to_remove_commands = set()
|
||||
to_remove_context = set()
|
||||
|
||||
# Add commands
|
||||
for command in enabled_commands["slash"]:
|
||||
if command in self._disabled_global_commands:
|
||||
to_add_commands.append(command)
|
||||
to_add_commands.add(command)
|
||||
|
||||
# Add context
|
||||
for command in enabled_commands["message"]:
|
||||
key = (command, None, discord.AppCommandType.message.value)
|
||||
if key in self._disabled_context_menus:
|
||||
to_add_context.append(key)
|
||||
to_add_context.add(key)
|
||||
for command in enabled_commands["user"]:
|
||||
key = (command, None, discord.AppCommandType.user.value)
|
||||
if key in self._disabled_context_menus:
|
||||
to_add_context.append(key)
|
||||
to_add_context.add(key)
|
||||
|
||||
# Add force enabled commands
|
||||
for command, command_obj in self._disabled_global_commands.items():
|
||||
if command_obj.extras.get("red_force_enable", False):
|
||||
to_add_commands.add(command)
|
||||
|
||||
# Add force enabled context
|
||||
for key, command_obj in self._disabled_context_menus.items():
|
||||
if command_obj.extras.get("red_force_enable", False):
|
||||
to_add_context.add(key)
|
||||
|
||||
# Remove commands
|
||||
for command in self._global_commands:
|
||||
if command not in enabled_commands["slash"]:
|
||||
to_remove_commands.append((command, discord.AppCommandType.chat_input))
|
||||
for command, command_obj in self._global_commands.items():
|
||||
if command not in enabled_commands["slash"] and not command_obj.extras.get(
|
||||
"red_force_enable", False
|
||||
):
|
||||
to_remove_commands.add((command, discord.AppCommandType.chat_input))
|
||||
|
||||
# Remove context
|
||||
for command, guild_id, command_type in self._context_menus:
|
||||
for key, command_obj in self._context_menus.items():
|
||||
command, guild_id, command_type = key
|
||||
if guild_id is not None:
|
||||
continue
|
||||
if (
|
||||
discord.AppCommandType(command_type) is discord.AppCommandType.message
|
||||
and command not in enabled_commands["message"]
|
||||
and not command_obj.extras.get("red_force_enable", False)
|
||||
):
|
||||
to_remove_context.append((command, discord.AppCommandType.message))
|
||||
to_remove_context.add((command, discord.AppCommandType.message))
|
||||
elif (
|
||||
discord.AppCommandType(command_type) is discord.AppCommandType.user
|
||||
and command not in enabled_commands["user"]
|
||||
and not command_obj.extras.get("red_force_enable", False)
|
||||
):
|
||||
to_remove_context.append((command, discord.AppCommandType.user))
|
||||
to_remove_context.add((command, discord.AppCommandType.user))
|
||||
|
||||
# Actually add/remove
|
||||
for command in to_add_commands:
|
||||
|
||||
Reference in New Issue
Block a user