mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[V3 Config] Allow users to directly specify a cog name with config (#1339)
This commit is contained in:
parent
7c848153f8
commit
d54c129c57
@ -509,7 +509,7 @@ class Config:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_conf(cls, cog_instance, identifier: int,
|
def get_conf(cls, cog_instance, identifier: int,
|
||||||
force_registration=False):
|
force_registration=False, cog_name=None):
|
||||||
"""Get a Config instance for your cog.
|
"""Get a Config instance for your cog.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@ -524,6 +524,10 @@ class Config:
|
|||||||
force_registration : `bool`, optional
|
force_registration : `bool`, optional
|
||||||
Should config require registration of data keys before allowing you
|
Should config require registration of data keys before allowing you
|
||||||
to get/set values? See `force_registration`.
|
to get/set values? See `force_registration`.
|
||||||
|
cog_name : str, optional
|
||||||
|
Config normally uses ``cog_instance`` to determine tha name of your cog.
|
||||||
|
If you wish you may pass ``None`` to ``cog_instance`` and directly specify
|
||||||
|
the name of your cog here.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
@ -531,7 +535,11 @@ class Config:
|
|||||||
A new Config object.
|
A new Config object.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
cog_path_override = cog_data_path(cog_instance)
|
if cog_instance is None and not cog_name is None:
|
||||||
|
cog_path_override = cog_data_path(raw_name=cog_name)
|
||||||
|
else:
|
||||||
|
cog_path_override = cog_data_path(cog_instance=cog_instance)
|
||||||
|
|
||||||
cog_name = cog_path_override.stem
|
cog_name = cog_path_override.stem
|
||||||
uuid = str(hash(identifier))
|
uuid = str(hash(identifier))
|
||||||
|
|
||||||
|
|||||||
@ -80,15 +80,19 @@ def _base_data_path() -> Path:
|
|||||||
return Path(path).resolve()
|
return Path(path).resolve()
|
||||||
|
|
||||||
|
|
||||||
def cog_data_path(cog_instance=None) -> Path:
|
def cog_data_path(cog_instance=None, raw_name: str=None) -> Path:
|
||||||
"""Gets the base cog data path. If you want to get the folder with
|
"""Gets the base cog data path. If you want to get the folder with
|
||||||
which to store your own cog's data please pass in an instance
|
which to store your own cog's data please pass in an instance
|
||||||
of your cog class.
|
of your cog class.
|
||||||
|
|
||||||
|
Either ``cog_instance`` or ``raw_name`` will be used, not both.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
cog_instance
|
cog_instance
|
||||||
The instance of the cog you wish to get a data path for.
|
The instance of the cog you wish to get a data path for.
|
||||||
|
raw_name : str
|
||||||
|
The name of the cog to get a data path for.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
@ -103,7 +107,10 @@ def cog_data_path(cog_instance=None) -> Path:
|
|||||||
raise RuntimeError("You must load the basic config before you"
|
raise RuntimeError("You must load the basic config before you"
|
||||||
" can get the cog data path.") from e
|
" can get the cog data path.") from e
|
||||||
cog_path = base_data_path / basic_config['COG_PATH_APPEND']
|
cog_path = base_data_path / basic_config['COG_PATH_APPEND']
|
||||||
if cog_instance:
|
|
||||||
|
if raw_name is not None:
|
||||||
|
cog_path = cog_path / raw_name
|
||||||
|
elif cog_instance is not None:
|
||||||
cog_path = cog_path / cog_instance.__class__.__name__
|
cog_path = cog_path / cog_instance.__class__.__name__
|
||||||
cog_path.mkdir(exist_ok=True, parents=True)
|
cog_path.mkdir(exist_ok=True, parents=True)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user