mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-23 03:08:01 -05:00
Create cog disabling API (#4043)
* create cog disbale base * Because defaults... * lol * announcer needs to respect this * defaultdict mishap * Allow None as guild - Mostly for interop with with ctx.guild * a whitespace issue * Apparently, I broke this too * Apply suggestions from code review Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> * This can probably be more optimized later, but since this is a cached value, it's not a large issue * Report tunnel closing * mod too * whitespace issue * Fix Artifact of prior method naming * these 3 places should have the check if i understood it correctly * Announce the closed tunnels * tunnel oversight * Make the player stop at next track * added where draper said to put it * Apply suggestions from code review Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> Co-authored-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>
This commit is contained in:
@@ -2174,9 +2174,83 @@ class Core(commands.Cog, CoreLogic):
|
||||
@checks.guildowner_or_permissions(administrator=True)
|
||||
@commands.group(name="command")
|
||||
async def command_manager(self, ctx: commands.Context):
|
||||
"""Manage the bot's commands."""
|
||||
"""Manage the bot's commands and cogs."""
|
||||
pass
|
||||
|
||||
@checks.is_owner()
|
||||
@command_manager.command(name="defaultdisablecog")
|
||||
async def command_default_disable_cog(self, ctx: commands.Context, *, cogname: str):
|
||||
"""Set the default state for a cog as disabled."""
|
||||
cog = self.bot.get_cog(cogname)
|
||||
if not cog:
|
||||
return await ctx.send(_("Cog with the given name doesn't exist."))
|
||||
if cog == self:
|
||||
return await ctx.send(_("You can't disable this cog by default."))
|
||||
await self.bot._disabled_cog_cache.default_disable(cogname)
|
||||
await ctx.send(_("{cogname} has been set as disabled by default.").format(cogname=cogname))
|
||||
|
||||
@checks.is_owner()
|
||||
@command_manager.command(name="defaultenablecog")
|
||||
async def command_default_enable_cog(self, ctx: commands.Context, *, cogname: str):
|
||||
"""Set the default state for a cog as enabled."""
|
||||
cog = self.bot.get_cog(cogname)
|
||||
if not cog:
|
||||
return await ctx.send(_("Cog with the given name doesn't exist."))
|
||||
await self.bot._disabled_cog_cache.default_enable(cogname)
|
||||
await ctx.send(_("{cogname} has been set as enabled by default.").format(cogname=cogname))
|
||||
|
||||
@commands.guild_only()
|
||||
@command_manager.command(name="disablecog")
|
||||
async def command_disable_cog(self, ctx: commands.Context, *, cogname: str):
|
||||
"""Disable a cog in this guild."""
|
||||
cog = self.bot.get_cog(cogname)
|
||||
if not cog:
|
||||
return await ctx.send(_("Cog with the given name doesn't exist."))
|
||||
if cog == self:
|
||||
return await ctx.send(_("You can't disable this cog as you would lock yourself out."))
|
||||
if await self.bot._disabled_cog_cache.disable_cog_in_guild(cogname, ctx.guild.id):
|
||||
await ctx.send(_("{cogname} has been disabled in this guild.").format(cogname=cogname))
|
||||
else:
|
||||
await ctx.send(
|
||||
_("{cogname} was already disabled (nothing to do).").format(cogname=cogname)
|
||||
)
|
||||
|
||||
@commands.guild_only()
|
||||
@command_manager.command(name="enablecog")
|
||||
async def command_enable_cog(self, ctx: commands.Context, *, cogname: str):
|
||||
"""Enable a cog in this guild."""
|
||||
if await self.bot._disabled_cog_cache.enable_cog_in_guild(cogname, ctx.guild.id):
|
||||
await ctx.send(_("{cogname} has been enabled in this guild.").format(cogname=cogname))
|
||||
else:
|
||||
# putting this here allows enabling a cog that isn't loaded but was disabled.
|
||||
cog = self.bot.get_cog(cogname)
|
||||
if not cog:
|
||||
return await ctx.send(_("Cog with the given name doesn't exist."))
|
||||
|
||||
await ctx.send(
|
||||
_("{cogname} was not disabled (nothing to do).").format(cogname=cogname)
|
||||
)
|
||||
|
||||
@commands.guild_only()
|
||||
@command_manager.command(name="listdisabledcogs")
|
||||
async def command_list_disabled_cogs(self, ctx: commands.Context):
|
||||
"""List the cogs which are disabled in this guild."""
|
||||
disabled = [
|
||||
cog.qualified_name
|
||||
for cog in self.bot.cogs.values()
|
||||
if await self.bot._disabled_cog_cache.cog_disabled_in_guild(
|
||||
cog.qualified_name, ctx.guild.id
|
||||
)
|
||||
]
|
||||
if disabled:
|
||||
output = _("The following cogs are disabled in this guild:\n")
|
||||
output += humanize_list(disabled)
|
||||
|
||||
for page in pagify(output):
|
||||
await ctx.send(page)
|
||||
else:
|
||||
await ctx.send(_("There are no disabled cogs in this guild."))
|
||||
|
||||
@command_manager.group(name="listdisabled", invoke_without_command=True)
|
||||
async def list_disabled(self, ctx: commands.Context):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user