mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -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.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
|
||||
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).
|
||||
Which one you should use depends on what you want to do.
|
||||
|
||||
.. 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
|
||||
@ -172,12 +175,6 @@ Group
|
||||
:members:
|
||||
:special-members:
|
||||
|
||||
MemberGroup
|
||||
^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: MemberGroup
|
||||
:members:
|
||||
|
||||
Value
|
||||
^^^^^
|
||||
|
||||
|
||||
@ -187,16 +187,6 @@ class Group(Value):
|
||||
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:
|
||||
"""A helper method for `__getattr__`. Most developers will have no need
|
||||
to use this.
|
||||
@ -329,33 +319,6 @@ class Group(Value):
|
||||
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:
|
||||
"""Configuration manager for cogs and Red.
|
||||
|
||||
@ -610,7 +573,7 @@ class Config:
|
||||
def register_guild(self, **kwargs):
|
||||
"""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)
|
||||
|
||||
@ -647,10 +610,9 @@ class Config:
|
||||
"""
|
||||
self._register_default(self.MEMBER, **kwargs)
|
||||
|
||||
def _get_base_group(self, key: str, *identifiers: str,
|
||||
group_class=Group) -> Group:
|
||||
def _get_base_group(self, key: str, *identifiers: str) -> Group:
|
||||
# noinspection PyTypeChecker
|
||||
return group_class(
|
||||
return Group(
|
||||
identifiers=(self.unique_identifier, key) + identifiers,
|
||||
defaults=self._defaults.get(key, {}),
|
||||
spawner=self.spawner,
|
||||
@ -665,6 +627,11 @@ class Config:
|
||||
guild : discord.Guild
|
||||
A guild object.
|
||||
|
||||
Returns
|
||||
-------
|
||||
Group
|
||||
The guild's Group object.
|
||||
|
||||
"""
|
||||
return self._get_base_group(self.GUILD, guild.id)
|
||||
|
||||
@ -678,6 +645,11 @@ class Config:
|
||||
channel : `discord.abc.GuildChannel`
|
||||
A channel object.
|
||||
|
||||
Returns
|
||||
-------
|
||||
Group
|
||||
The channel's Group object.
|
||||
|
||||
"""
|
||||
return self._get_base_group(self.CHANNEL, channel.id)
|
||||
|
||||
@ -689,6 +661,11 @@ class Config:
|
||||
role : discord.Role
|
||||
A role object.
|
||||
|
||||
Returns
|
||||
-------
|
||||
Group
|
||||
The role's Group object.
|
||||
|
||||
"""
|
||||
return self._get_base_group(self.ROLE, role.id)
|
||||
|
||||
@ -700,10 +677,15 @@ class Config:
|
||||
user : discord.User
|
||||
A user object.
|
||||
|
||||
Returns
|
||||
-------
|
||||
Group
|
||||
The user's Group object.
|
||||
|
||||
"""
|
||||
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.
|
||||
|
||||
Parameters
|
||||
@ -711,9 +693,13 @@ class Config:
|
||||
member : discord.Member
|
||||
A member object.
|
||||
|
||||
Returns
|
||||
-------
|
||||
Group
|
||||
The member's Group object.
|
||||
|
||||
"""
|
||||
return self._get_base_group(self.MEMBER, member.guild.id, member.id,
|
||||
group_class=MemberGroup)
|
||||
return self._get_base_group(self.MEMBER, member.guild.id, member.id)
|
||||
|
||||
async def _all_from_scope(self, scope: str):
|
||||
"""Get a dict of all values from a particular scope of data.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user