diff --git a/redbot/core/config.py b/redbot/core/config.py index b950315fb..30bf50252 100644 --- a/redbot/core/config.py +++ b/redbot/core/config.py @@ -7,7 +7,7 @@ import weakref import discord from .data_manager import cog_data_path, core_data_path -from .drivers import get_driver, IdentifierData +from .drivers import get_driver, IdentifierData, BackendType if TYPE_CHECKING: from .drivers.red_base import BaseDriver @@ -562,6 +562,10 @@ class Config: def defaults(self): return deepcopy(self._defaults) + @staticmethod + def _create_uuid(identifier: int): + return str(identifier) + @classmethod def get_conf(cls, cog_instance, identifier: int, force_registration=False, cog_name=None): """Get a Config instance for your cog. @@ -602,7 +606,8 @@ class Config: cog_path_override = cog_data_path(cog_instance=cog_instance) cog_name = cog_path_override.stem - uuid = str(hash(identifier)) + # uuid = str(hash(identifier)) + uuid = cls._create_uuid(identifier) # We have to import this here otherwise we have a circular dependency from .data_manager import basic_config @@ -613,6 +618,9 @@ class Config: driver = get_driver( driver_name, cog_name, uuid, data_path_override=cog_path_override, **driver_details ) + if driver_name == BackendType.JSON.value: + driver.migrate_identifier(identifier) + conf = cls( cog_name=cog_name, unique_identifier=uuid, diff --git a/redbot/core/drivers/red_json.py b/redbot/core/drivers/red_json.py index 28c92adf5..73023ffeb 100644 --- a/redbot/core/drivers/red_json.py +++ b/redbot/core/drivers/red_json.py @@ -96,6 +96,18 @@ class JSON(BaseDriver): self.data = {} self.jsonIO._save_json(self.data) + def migrate_identifier(self, raw_identifier: int): + if self.unique_cog_identifier in self.data: + # Data has already been migrated + return + poss_identifiers = [str(raw_identifier), str(hash(raw_identifier))] + for ident in poss_identifiers: + if ident in self.data: + self.data[self.unique_cog_identifier] = self.data[ident] + del self.data[ident] + self.jsonIO._save_json(self.data) + break + async def get(self, identifier_data: IdentifierData): partial = self.data full_identifiers = identifier_data.to_tuple()