mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 18:27:59 -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:
@@ -37,7 +37,12 @@ from .dev_commands import Dev
|
||||
from .events import init_events
|
||||
from .global_checks import init_global_checks
|
||||
|
||||
from .settings_caches import PrefixManager, IgnoreManager, WhitelistBlacklistManager
|
||||
from .settings_caches import (
|
||||
PrefixManager,
|
||||
IgnoreManager,
|
||||
WhitelistBlacklistManager,
|
||||
DisabledCogCache,
|
||||
)
|
||||
|
||||
from .rpc import RPCMixin
|
||||
from .utils import common_filters
|
||||
@@ -132,12 +137,16 @@ class RedBase(
|
||||
self._config.register_channel(embeds=None, ignored=False)
|
||||
self._config.register_user(embeds=None)
|
||||
|
||||
self._config.init_custom("COG_DISABLE_SETTINGS", 2)
|
||||
self._config.register_custom("COG_DISABLE_SETTINGS", disabled=None)
|
||||
|
||||
self._config.init_custom(CUSTOM_GROUPS, 2)
|
||||
self._config.register_custom(CUSTOM_GROUPS)
|
||||
|
||||
self._config.init_custom(SHARED_API_TOKENS, 2)
|
||||
self._config.register_custom(SHARED_API_TOKENS)
|
||||
self._prefix_cache = PrefixManager(self._config, cli_flags)
|
||||
self._disabled_cog_cache = DisabledCogCache(self._config)
|
||||
self._ignored_cache = IgnoreManager(self._config)
|
||||
self._whiteblacklist_cache = WhitelistBlacklistManager(self._config)
|
||||
|
||||
@@ -217,6 +226,41 @@ class RedBase(
|
||||
return_exceptions=return_exceptions,
|
||||
)
|
||||
|
||||
async def cog_disabled_in_guild(
|
||||
self, cog: commands.Cog, guild: Optional[discord.Guild]
|
||||
) -> bool:
|
||||
"""
|
||||
Check if a cog is disabled in a guild
|
||||
|
||||
Parameters
|
||||
----------
|
||||
cog: commands.Cog
|
||||
guild: Optional[discord.Guild]
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
"""
|
||||
if guild is None:
|
||||
return False
|
||||
return await self._disabled_cog_cache.cog_disabled_in_guild(cog.qualified_name, guild.id)
|
||||
|
||||
async def cog_disabled_in_guild_raw(self, cog_name: str, guild_id: int) -> bool:
|
||||
"""
|
||||
Check if a cog is disabled in a guild without the cog or guild object
|
||||
|
||||
Parameters
|
||||
----------
|
||||
cog_name: str
|
||||
This should be the cog's qualified name, not neccessarily the classname
|
||||
guild_id: int
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
"""
|
||||
return await self._disabled_cog_cache.cog_disabled_in_guild(cog_name, guild_id)
|
||||
|
||||
def remove_before_invoke_hook(self, coro: PreInvokeCoroutine) -> None:
|
||||
"""
|
||||
Functional method to remove a `before_invoke` hook.
|
||||
|
||||
Reference in New Issue
Block a user