diff --git a/redbot/core/bot.py b/redbot/core/bot.py index 522f1228a..601c3a633 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -18,6 +18,8 @@ from .help_formatter import Help, help as help_ from .rpc import RPCMixin from .utils import common_filters +CUSTOM_GROUPS = "CUSTOM_GROUPS" + def _is_submodule(parent, child): return parent == child or child.startswith(parent + ".") @@ -74,6 +76,9 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): self.db.register_user(embeds=None) + self.db.init_custom(CUSTOM_GROUPS, 2) + self.db.register_custom(CUSTOM_GROUPS) + async def prefix_manager(bot, message): if not cli_flags.prefix: global_prefix = await bot.db.prefix() diff --git a/redbot/core/config.py b/redbot/core/config.py index 400e5de7c..b950315fb 100644 --- a/redbot/core/config.py +++ b/redbot/core/config.py @@ -12,11 +12,22 @@ from .drivers import get_driver, IdentifierData if TYPE_CHECKING: from .drivers.red_base import BaseDriver +__all__ = ["Config", "get_latest_confs"] + log = logging.getLogger("red.config") _T = TypeVar("_T") _config_cache = weakref.WeakValueDictionary() +_retrieved = weakref.WeakSet() + + +def get_latest_confs() -> Tuple["Config"]: + global _retrieved + ret = set(_config_cache.values()) - set(_retrieved) + _retrieved |= ret + # noinspection PyTypeChecker + return tuple(ret) class _ValueCtxManager(Awaitable[_T], AsyncContextManager[_T]): diff --git a/redbot/core/events.py b/redbot/core/events.py index 855a68d6e..5bdc00b51 100644 --- a/redbot/core/events.py +++ b/redbot/core/events.py @@ -15,6 +15,7 @@ from pkg_resources import DistributionNotFound from .. import __version__ as red_version, version_info as red_version_info, VersionInfo from . import commands +from .config import get_latest_confs from .data_manager import storage_type from .utils.chat_formatting import inline, bordered, format_perms_list, humanize_timedelta from .utils import fuzzy_command_search, format_fuzzy_results @@ -305,6 +306,14 @@ def init_events(bot, cli_flags): if command_obj is not None: command_obj.enable_in(guild) + @bot.event + async def on_cog_add(cog: commands.Cog): + confs = get_latest_confs() + for c in confs: + uuid = c.unique_identifier + group_data = c.custom_groups + await bot.db.custom("CUSTOM_GROUPS", c.cog_name, uuid).set(group_data) + def _get_startup_screen_specs(): """Get specs for displaying the startup screen on stdout.