mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[V3 Config] Remove redundancies and update old docs Re:#1033 (#1039)
* Remove MemberGroup class and _super_group method Also found some docstrings which were missing stuff * Update documentation
This commit is contained in:
parent
3b96e94992
commit
fe61ef167e
@ -134,18 +134,21 @@ Notice a few things in the above examples:
|
|||||||
* :py:meth:`Config.role` which takes :py:class:`discord.Role`.
|
* :py:meth:`Config.role` which takes :py:class:`discord.Role`.
|
||||||
* :py:meth:`Config.channel` which takes :py:class:`discord.TextChannel`.
|
* :py:meth:`Config.channel` which takes :py:class:`discord.TextChannel`.
|
||||||
|
|
||||||
If you need to wipe data from the config, you want to look at :py:meth:`Group.clear` or :py:meth:`Group.clear_all`.
|
If you need to wipe data from the config, you want to look at :py:meth:`Group.clear`, or :py:meth:`Config.clear_all`
|
||||||
|
and similar methods, such as :py:meth:`Config.clear_all_guilds`.
|
||||||
|
|
||||||
Which one you should use depends on what you want to do. If you're looking to clear data for a
|
Which one you should use depends on what you want to do.
|
||||||
single guild/member/channel/role/user, you want to use :py:meth:`Group.clear` as that will clear the
|
|
||||||
data only for the specified thing (though, if used on global, it will reset all of the data
|
|
||||||
for keys registered with :py:meth:`Config.register_global`). If using :py:meth:`Group.clear_all`, it will reset
|
|
||||||
all data for all guilds/members/channels/roles/users (or if used on a global, it will reset
|
|
||||||
everything for all kinds).
|
|
||||||
|
|
||||||
.. note::
|
If you're looking to clear data for a single guild/member/channel/role/user,
|
||||||
|
you want to use :py:meth:`Group.clear` as that will clear the data only for the
|
||||||
|
specified thing.
|
||||||
|
|
||||||
Members have a special clearing methods, see :py:class:`MemberGroup`
|
If using :py:meth:`Config.clear_all`, it will reset all data everywhere.
|
||||||
|
|
||||||
|
There are other methods provided to reset data from a particular scope. For
|
||||||
|
example, :py:meth:`Config.clear_all_guilds` resets all guild data. For member
|
||||||
|
data, you can clear on both a per-guild and guild-independent basis, see
|
||||||
|
:py:meth:`Config.clear_all_members` for more info.
|
||||||
|
|
||||||
*************
|
*************
|
||||||
API Reference
|
API Reference
|
||||||
@ -172,12 +175,6 @@ Group
|
|||||||
:members:
|
:members:
|
||||||
:special-members:
|
:special-members:
|
||||||
|
|
||||||
MemberGroup
|
|
||||||
^^^^^^^^^^^
|
|
||||||
|
|
||||||
.. autoclass:: MemberGroup
|
|
||||||
:members:
|
|
||||||
|
|
||||||
Value
|
Value
|
||||||
^^^^^
|
^^^^^
|
||||||
|
|
||||||
|
|||||||
@ -187,16 +187,6 @@ class Group(Value):
|
|||||||
spawner=self.spawner
|
spawner=self.spawner
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def _super_group(self) -> 'Group':
|
|
||||||
super_group = Group(
|
|
||||||
self.identifiers[:-1],
|
|
||||||
defaults={},
|
|
||||||
spawner=self.spawner,
|
|
||||||
force_registration=self.force_registration
|
|
||||||
)
|
|
||||||
return super_group
|
|
||||||
|
|
||||||
def is_group(self, item: str) -> bool:
|
def is_group(self, item: str) -> bool:
|
||||||
"""A helper method for `__getattr__`. Most developers will have no need
|
"""A helper method for `__getattr__`. Most developers will have no need
|
||||||
to use this.
|
to use this.
|
||||||
@ -329,33 +319,6 @@ class Group(Value):
|
|||||||
await self.set({})
|
await self.set({})
|
||||||
|
|
||||||
|
|
||||||
class MemberGroup(Group):
|
|
||||||
"""A specific group class for use with member data only.
|
|
||||||
|
|
||||||
Inherits from `Group`. In this group data is stored as
|
|
||||||
:code:`GUILD_ID -> MEMBER_ID -> data`.
|
|
||||||
"""
|
|
||||||
@property
|
|
||||||
def _super_group(self) -> Group:
|
|
||||||
new_identifiers = self.identifiers[:2]
|
|
||||||
group_obj = Group(
|
|
||||||
identifiers=new_identifiers,
|
|
||||||
defaults={},
|
|
||||||
spawner=self.spawner
|
|
||||||
)
|
|
||||||
return group_obj
|
|
||||||
|
|
||||||
@property
|
|
||||||
def _guild_group(self) -> Group:
|
|
||||||
new_identifiers = self.identifiers[:3]
|
|
||||||
group_obj = Group(
|
|
||||||
identifiers=new_identifiers,
|
|
||||||
defaults={},
|
|
||||||
spawner=self.spawner
|
|
||||||
)
|
|
||||||
return group_obj
|
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
"""Configuration manager for cogs and Red.
|
"""Configuration manager for cogs and Red.
|
||||||
|
|
||||||
@ -610,7 +573,7 @@ class Config:
|
|||||||
def register_guild(self, **kwargs):
|
def register_guild(self, **kwargs):
|
||||||
"""Register default values on a per-guild level.
|
"""Register default values on a per-guild level.
|
||||||
|
|
||||||
See :py:meth:`register_global` for more details.
|
See `register_global` for more details.
|
||||||
"""
|
"""
|
||||||
self._register_default(self.GUILD, **kwargs)
|
self._register_default(self.GUILD, **kwargs)
|
||||||
|
|
||||||
@ -647,10 +610,9 @@ class Config:
|
|||||||
"""
|
"""
|
||||||
self._register_default(self.MEMBER, **kwargs)
|
self._register_default(self.MEMBER, **kwargs)
|
||||||
|
|
||||||
def _get_base_group(self, key: str, *identifiers: str,
|
def _get_base_group(self, key: str, *identifiers: str) -> Group:
|
||||||
group_class=Group) -> Group:
|
|
||||||
# noinspection PyTypeChecker
|
# noinspection PyTypeChecker
|
||||||
return group_class(
|
return Group(
|
||||||
identifiers=(self.unique_identifier, key) + identifiers,
|
identifiers=(self.unique_identifier, key) + identifiers,
|
||||||
defaults=self._defaults.get(key, {}),
|
defaults=self._defaults.get(key, {}),
|
||||||
spawner=self.spawner,
|
spawner=self.spawner,
|
||||||
@ -665,6 +627,11 @@ class Config:
|
|||||||
guild : discord.Guild
|
guild : discord.Guild
|
||||||
A guild object.
|
A guild object.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
Group
|
||||||
|
The guild's Group object.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self._get_base_group(self.GUILD, guild.id)
|
return self._get_base_group(self.GUILD, guild.id)
|
||||||
|
|
||||||
@ -678,6 +645,11 @@ class Config:
|
|||||||
channel : `discord.abc.GuildChannel`
|
channel : `discord.abc.GuildChannel`
|
||||||
A channel object.
|
A channel object.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
Group
|
||||||
|
The channel's Group object.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self._get_base_group(self.CHANNEL, channel.id)
|
return self._get_base_group(self.CHANNEL, channel.id)
|
||||||
|
|
||||||
@ -689,6 +661,11 @@ class Config:
|
|||||||
role : discord.Role
|
role : discord.Role
|
||||||
A role object.
|
A role object.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
Group
|
||||||
|
The role's Group object.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self._get_base_group(self.ROLE, role.id)
|
return self._get_base_group(self.ROLE, role.id)
|
||||||
|
|
||||||
@ -700,10 +677,15 @@ class Config:
|
|||||||
user : discord.User
|
user : discord.User
|
||||||
A user object.
|
A user object.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
Group
|
||||||
|
The user's Group object.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self._get_base_group(self.USER, user.id)
|
return self._get_base_group(self.USER, user.id)
|
||||||
|
|
||||||
def member(self, member: discord.Member) -> MemberGroup:
|
def member(self, member: discord.Member) -> Group:
|
||||||
"""Returns a `Group` for the given member.
|
"""Returns a `Group` for the given member.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@ -711,9 +693,13 @@ class Config:
|
|||||||
member : discord.Member
|
member : discord.Member
|
||||||
A member object.
|
A member object.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
Group
|
||||||
|
The member's Group object.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self._get_base_group(self.MEMBER, member.guild.id, member.id,
|
return self._get_base_group(self.MEMBER, member.guild.id, member.id)
|
||||||
group_class=MemberGroup)
|
|
||||||
|
|
||||||
async def _all_from_scope(self, scope: str):
|
async def _all_from_scope(self, scope: str):
|
||||||
"""Get a dict of all values from a particular scope of data.
|
"""Get a dict of all values from a particular scope of data.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user