mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-09 04:38:55 -05:00
[V3 Config] Record custom group information using cog_add event (#2550)
* Do things differently * Uncomment critical lines * Reduce, reuse, recycle * Check groups on all new config objects after a cog loads * I don't know why this is failing now or why we need the global keyword * gotta fix this too
This commit is contained in:
parent
e347ffa336
commit
ba19179e4f
@ -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()
|
||||
|
||||
@ -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]):
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user