From 204c945b552c4dcfc41ed12c0a0270b23c2cd7c1 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Wed, 7 Jun 2023 21:18:47 +0200 Subject: [PATCH 1/9] feat: add `DefaultAvatar.fuchsia` (5) --- disnake/enums.py | 1 + docs/api/users.rst | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/disnake/enums.py b/disnake/enums.py index 7937c1d1e9..54b25d2f72 100644 --- a/disnake/enums.py +++ b/disnake/enums.py @@ -322,6 +322,7 @@ class DefaultAvatar(Enum): green = 2 orange = 3 red = 4 + fuchsia = 5 def __str__(self) -> str: return self.name diff --git a/docs/api/users.rst b/docs/api/users.rst index 274b84aac9..36bfdc1faa 100644 --- a/docs/api/users.rst +++ b/docs/api/users.rst @@ -127,7 +127,7 @@ DefaultAvatar .. class:: DefaultAvatar - Represents the default avatar of a Discord :class:`User` + Represents the default avatar of a Discord :class:`User`. .. attribute:: blurple @@ -152,6 +152,12 @@ DefaultAvatar Represents the default avatar with the color red. See also :attr:`Colour.red` + .. attribute:: fuchsia + + Represents the default avatar with the color fuchsia. + See also :attr:`Colour.fuchsia` + + .. versionadded:: 2.9 Events ------ From 04ef79fc72c0ebe0f13307dc5e570b6ab327347b Mon Sep 17 00:00:00 2001 From: shiftinv Date: Wed, 7 Jun 2023 21:19:24 +0200 Subject: [PATCH 2/9] feat: update `BaseUser.default_avatar` to correctly handle legacy and migrated users --- disnake/user.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/disnake/user.py b/disnake/user.py index 8f9333b9cd..2a307464c8 100644 --- a/disnake/user.py +++ b/disnake/user.py @@ -157,11 +157,11 @@ def default_avatar(self) -> Asset: Added handling for users migrated to the new username system without discriminators. """ if self.discriminator == "0": - num = self.id >> 22 + index = (self.id >> 22) % len(DefaultAvatar) else: # legacy behavior - num = int(self.discriminator) - return Asset._from_default_avatar(self._state, num % len(DefaultAvatar)) + index = int(self.discriminator) % 5 + return Asset._from_default_avatar(self._state, index) @property def display_avatar(self) -> Asset: From dcd6a6a9f2abaf5a419379c7ad8ca654972dac45 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Wed, 7 Jun 2023 21:41:28 +0200 Subject: [PATCH 3/9] revert(docs): bot display names are no longer planned to be their application names --- disnake/abc.py | 2 -- disnake/user.py | 4 ---- 2 files changed, 6 deletions(-) diff --git a/disnake/abc.py b/disnake/abc.py index d7a2991297..78abdbb623 100644 --- a/disnake/abc.py +++ b/disnake/abc.py @@ -143,8 +143,6 @@ class User(Snowflake, Protocol): The user's global display name, if set. This takes precedence over :attr:`.name` when shown. - For bots, this is the application name. - .. versionadded:: 2.9 avatar: :class:`~disnake.Asset` diff --git a/disnake/user.py b/disnake/user.py index 2a307464c8..c1eda3655f 100644 --- a/disnake/user.py +++ b/disnake/user.py @@ -318,8 +318,6 @@ class ClientUser(BaseUser): The user's global display name, if set. This takes precedence over :attr:`.name` when shown. - For bots, this is the application name. - .. versionadded:: 2.9 bot: :class:`bool` @@ -464,8 +462,6 @@ class User(BaseUser, disnake.abc.Messageable): The user's global display name, if set. This takes precedence over :attr:`.name` when shown. - For bots, this is the application name. - .. versionadded:: 2.9 bot: :class:`bool` From a9eee1e1b0b58d516c7ae477029cb0a4308d62b9 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Wed, 7 Jun 2023 21:53:09 +0200 Subject: [PATCH 4/9] fix(docs): clarify that pomelo changes won't apply to bots, for now --- disnake/abc.py | 2 +- disnake/guild.py | 3 +-- disnake/member.py | 2 +- disnake/team.py | 2 +- disnake/user.py | 10 ++-------- disnake/widget.py | 2 +- 6 files changed, 7 insertions(+), 14 deletions(-) diff --git a/disnake/abc.py b/disnake/abc.py index 78abdbb623..0f31ab7e60 100644 --- a/disnake/abc.py +++ b/disnake/abc.py @@ -134,7 +134,7 @@ class User(Snowflake, Protocol): The user's discriminator. .. note:: - This is being phased out by Discord; the username system is moving away from ``username#discriminator`` + This is being phased out by Discord for non-bot users; the username system is moving away from ``username#discriminator`` to users having a globally unique username. The value of a single zero (``"0"``) indicates that the user has been migrated to the new system. See the `help article `__ for details. diff --git a/disnake/guild.py b/disnake/guild.py index 614489d1f6..240f7d210b 100644 --- a/disnake/guild.py +++ b/disnake/guild.py @@ -1141,8 +1141,7 @@ def get_member_named(self, name: str, /) -> Optional[Member]: 2. Lookup by global name. 3. Lookup by username. - While the migration away from discriminators is still ongoing, - the name can have an optional discriminator argument, e.g. "Jake#0001", + The name can have an optional discriminator argument, e.g. "Jake#0001", in which case it will be treated as a username + discriminator combo (note: this only works with usernames, not nicknames). diff --git a/disnake/member.py b/disnake/member.py index 96db64f907..9b2baf2a98 100644 --- a/disnake/member.py +++ b/disnake/member.py @@ -494,7 +494,7 @@ def discriminator(self) -> str: """:class:`str`:The user's discriminator. .. note:: - This is being phased out by Discord; the username system is moving away from ``username#discriminator`` + This is being phased out by Discord for non-bot users; the username system is moving away from ``username#discriminator`` to users having a globally unique username. The value of a single zero (``"0"``) indicates that the user has been migrated to the new system. See the `help article `__ for details. diff --git a/disnake/team.py b/disnake/team.py index 6465128ffe..d15fe60fe3 100644 --- a/disnake/team.py +++ b/disnake/team.py @@ -98,7 +98,7 @@ class TeamMember(BaseUser): The team member's discriminator. .. note:: - This is being phased out by Discord; the username system is moving away from ``username#discriminator`` + This is being phased out by Discord for non-bot users; the username system is moving away from ``username#discriminator`` to users having a globally unique username. The value of a single zero (``"0"``) indicates that the user has been migrated to the new system. See the `help article `__ for details. diff --git a/disnake/user.py b/disnake/user.py index c1eda3655f..5aa929ff68 100644 --- a/disnake/user.py +++ b/disnake/user.py @@ -297,7 +297,7 @@ class ClientUser(BaseUser): .. describe:: str(x) - Returns the user's username (with discriminator, if not migrated to new system yet). + Returns the user's username (with discriminator). Attributes ---------- @@ -308,12 +308,6 @@ class ClientUser(BaseUser): discriminator: :class:`str` The user's discriminator. - .. note:: - This is being phased out by Discord; the username system is moving away from ``username#discriminator`` - to users having a globally unique username. - The value of a single zero (``"0"``) indicates that the user has been migrated to the new system. - See the `help article `__ for details. - global_name: Optional[:class:`str`] The user's global display name, if set. This takes precedence over :attr:`.name` when shown. @@ -453,7 +447,7 @@ class User(BaseUser, disnake.abc.Messageable): The user's discriminator. .. note:: - This is being phased out by Discord; the username system is moving away from ``username#discriminator`` + This is being phased out by Discord for non-bot users; the username system is moving away from ``username#discriminator`` to users having a globally unique username. The value of a single zero (``"0"``) indicates that the user has been migrated to the new system. See the `help article `__ for details. diff --git a/disnake/widget.py b/disnake/widget.py index d5056d82dc..bc7950d853 100644 --- a/disnake/widget.py +++ b/disnake/widget.py @@ -117,7 +117,7 @@ class WidgetMember(BaseUser): The member's anonymized discriminator. .. note:: - This is being phased out by Discord; the username system is moving away from ``username#discriminator`` + This is being phased out by Discord for non-bot users; the username system is moving away from ``username#discriminator`` to users having a globally unique username. See the `help article `__ for details. status: :class:`Status` From d1f415c21a76315ba6a7a7b379d4e65cc7d8d380 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Wed, 7 Jun 2023 22:18:56 +0200 Subject: [PATCH 5/9] docs: update and add changelog --- changelog/1025.feature.rst | 2 +- changelog/1044.feature.rst | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelog/1044.feature.rst diff --git a/changelog/1025.feature.rst b/changelog/1025.feature.rst index 7a063ba158..714dcdf4c8 100644 --- a/changelog/1025.feature.rst +++ b/changelog/1025.feature.rst @@ -4,4 +4,4 @@ Add support for new username system - see the official `help article `__ for details. Existing functionality is kept backwards-compatible while the migration is still ongoing. +- Add :attr:`User.global_name`, and update attributes/methods to account for it: + - :attr:`User.display_name` and :attr:`Member.display_name` + - :meth:`Guild.get_member_named` + - |commands| :class:`~ext.commands.UserConverter` and :class:`~ext.commands.MemberConverter`, now largely matching the behavior of :meth:`Guild.get_member_named` +- Update ``str(user)`` and ``str(member)`` to not include ``#0`` discriminator of migrated users. +- Adjust :attr:`User.default_avatar` to account for new default avatar handling, also adding :attr:`DefaultAvatar.fuchsia`. From 93c1ffc290535188d2eefe468182b8cdc80623c6 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Sun, 11 Jun 2023 20:51:33 +0200 Subject: [PATCH 6/9] chore: use `% 6` instead of enum size --- disnake/user.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/disnake/user.py b/disnake/user.py index 5aa929ff68..b76d83367a 100644 --- a/disnake/user.py +++ b/disnake/user.py @@ -8,7 +8,7 @@ from .asset import Asset from .colour import Colour -from .enums import DefaultAvatar, Locale, try_enum +from .enums import Locale, try_enum from .flags import PublicUserFlags from .utils import MISSING, _assetbytes_to_base64_data, snowflake_time @@ -157,7 +157,7 @@ def default_avatar(self) -> Asset: Added handling for users migrated to the new username system without discriminators. """ if self.discriminator == "0": - index = (self.id >> 22) % len(DefaultAvatar) + index = (self.id >> 22) % 6 else: # legacy behavior index = int(self.discriminator) % 5 From 443e05ddd83fe3ff2a609198226757eb6b337fb8 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Sun, 11 Jun 2023 22:03:10 +0200 Subject: [PATCH 7/9] revert: undo "for non-bot users" wording --- disnake/abc.py | 2 +- disnake/member.py | 2 +- disnake/team.py | 2 +- disnake/user.py | 2 +- disnake/widget.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/disnake/abc.py b/disnake/abc.py index 0f31ab7e60..78abdbb623 100644 --- a/disnake/abc.py +++ b/disnake/abc.py @@ -134,7 +134,7 @@ class User(Snowflake, Protocol): The user's discriminator. .. note:: - This is being phased out by Discord for non-bot users; the username system is moving away from ``username#discriminator`` + This is being phased out by Discord; the username system is moving away from ``username#discriminator`` to users having a globally unique username. The value of a single zero (``"0"``) indicates that the user has been migrated to the new system. See the `help article `__ for details. diff --git a/disnake/member.py b/disnake/member.py index 9b2baf2a98..96db64f907 100644 --- a/disnake/member.py +++ b/disnake/member.py @@ -494,7 +494,7 @@ def discriminator(self) -> str: """:class:`str`:The user's discriminator. .. note:: - This is being phased out by Discord for non-bot users; the username system is moving away from ``username#discriminator`` + This is being phased out by Discord; the username system is moving away from ``username#discriminator`` to users having a globally unique username. The value of a single zero (``"0"``) indicates that the user has been migrated to the new system. See the `help article `__ for details. diff --git a/disnake/team.py b/disnake/team.py index d15fe60fe3..6465128ffe 100644 --- a/disnake/team.py +++ b/disnake/team.py @@ -98,7 +98,7 @@ class TeamMember(BaseUser): The team member's discriminator. .. note:: - This is being phased out by Discord for non-bot users; the username system is moving away from ``username#discriminator`` + This is being phased out by Discord; the username system is moving away from ``username#discriminator`` to users having a globally unique username. The value of a single zero (``"0"``) indicates that the user has been migrated to the new system. See the `help article `__ for details. diff --git a/disnake/user.py b/disnake/user.py index b76d83367a..2fb7657dfe 100644 --- a/disnake/user.py +++ b/disnake/user.py @@ -447,7 +447,7 @@ class User(BaseUser, disnake.abc.Messageable): The user's discriminator. .. note:: - This is being phased out by Discord for non-bot users; the username system is moving away from ``username#discriminator`` + This is being phased out by Discord; the username system is moving away from ``username#discriminator`` to users having a globally unique username. The value of a single zero (``"0"``) indicates that the user has been migrated to the new system. See the `help article `__ for details. diff --git a/disnake/widget.py b/disnake/widget.py index bc7950d853..d5056d82dc 100644 --- a/disnake/widget.py +++ b/disnake/widget.py @@ -117,7 +117,7 @@ class WidgetMember(BaseUser): The member's anonymized discriminator. .. note:: - This is being phased out by Discord for non-bot users; the username system is moving away from ``username#discriminator`` + This is being phased out by Discord; the username system is moving away from ``username#discriminator`` to users having a globally unique username. See the `help article `__ for details. status: :class:`Status` From 7b39fd94b4945cab21e5bd261710e4e13a978c56 Mon Sep 17 00:00:00 2001 From: shiftinv Date: Sun, 11 Jun 2023 22:03:22 +0200 Subject: [PATCH 8/9] chore(docs): spacing nit --- disnake/member.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/disnake/member.py b/disnake/member.py index 96db64f907..daf8fa7cbf 100644 --- a/disnake/member.py +++ b/disnake/member.py @@ -491,7 +491,7 @@ def tag(self) -> str: @property def discriminator(self) -> str: - """:class:`str`:The user's discriminator. + """:class:`str`: The user's discriminator. .. note:: This is being phased out by Discord; the username system is moving away from ``username#discriminator`` From 95d0f2470fb3a990b0bacb7966fcf1120d3746dd Mon Sep 17 00:00:00 2001 From: shiftinv Date: Mon, 12 Jun 2023 14:36:28 +0200 Subject: [PATCH 9/9] revert(docs): keep `ClientUser.__str__` changes --- disnake/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/disnake/user.py b/disnake/user.py index 2fb7657dfe..b2b05acb54 100644 --- a/disnake/user.py +++ b/disnake/user.py @@ -297,7 +297,7 @@ class ClientUser(BaseUser): .. describe:: str(x) - Returns the user's username (with discriminator). + Returns the user's username (with discriminator, if not migrated to new system yet). Attributes ----------