diff --git a/CHANGELOG.md b/CHANGELOG.md index 8210bcb658..b0cd6f4a66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ These changes are available on the `master` branch, but have not yet been releas - Added `.extension` attribute to the `AppEmoji` and `GuildEmoji` classes. ([#3055](https://github.com/Pycord-Development/pycord/pull/3055)) +- Added the ability to compare instances of `PrimaryGuild`. + ([#3077](https://github.com/Pycord-Development/pycord/pull/3077)) ### Changed @@ -42,6 +44,8 @@ These changes are available on the `master` branch, but have not yet been releas - Fixed an issue where the optional parameters of the `InteractionResponse.send_message` method were not type-hinted as optional. ([#3061](https://github.com/Pycord-Development/pycord/pull/3061)) +- Fixed the update of a user's `primary_guild` to now cause an `on_user_update` event to + fire. ([#3077](https://github.com/Pycord-Development/pycord/pull/3077)) ### Removed diff --git a/discord/member.py b/discord/member.py index 72cbb912d9..8210d129bf 100644 --- a/discord/member.py +++ b/discord/member.py @@ -462,14 +462,30 @@ def _presence_update( def _update_inner_user(self, user: UserPayload) -> tuple[User, User] | None: u = self._user - original = (u.name, u._avatar, u.discriminator, u.global_name, u._public_flags) + original = ( + u.name, + u._avatar, + u.discriminator, + u.global_name, + u._public_flags, + u.primary_guild, + ) # These keys seem to always be available + if ( + new_primary_guild_data := user.get("primary_guild") + ) and new_primary_guild_data.get("identity_enabled"): + new_primary_guild: PrimaryGuild | None = PrimaryGuild( + new_primary_guild_data, state=self._state + ) + else: + new_primary_guild = None modified = ( user["username"], user["avatar"], user["discriminator"], user.get("global_name", None) or None, user.get("public_flags", 0), + new_primary_guild, ) if original != modified: to_return = User._copy(self._user) @@ -479,6 +495,7 @@ def _update_inner_user(self, user: UserPayload) -> tuple[User, User] | None: u.discriminator, u.global_name, u._public_flags, + u.primary_guild, ) = modified # Signal to dispatch on_user_update return to_return, u diff --git a/discord/primary_guild.py b/discord/primary_guild.py index 27edba7e97..645d3be65b 100644 --- a/discord/primary_guild.py +++ b/discord/primary_guild.py @@ -40,6 +40,19 @@ class PrimaryGuild: .. versionadded:: 2.7 + .. container:: operations + + .. describe:: x == y + + Checks if two Primary Guilds are equal. + + .. describe:: x != y + + Checks if two Primary Guilds are not equal. + + .. versionchanged:: 2.7.1 + Primary Guilds are now comparable. + Attributes ---------- identity_guild_id: int @@ -62,6 +75,16 @@ def __init__(self, data: PrimaryGuildPayload, state: "ConnectionState") -> None: def __repr__(self) -> str: return f"" + def __eq__(self, other: object) -> bool: + if not isinstance(other, PrimaryGuild): + return NotImplemented + + return ( + self.identity_guild_id == other.identity_guild_id + and self.identity_enabled == other.identity_enabled + and self.tag == other.tag + ) + @cached_property def badge(self) -> Asset | None: """Returns the badge asset, if available. diff --git a/discord/types/user.py b/discord/types/user.py index a0383e4f04..61b60c2c3a 100644 --- a/discord/types/user.py +++ b/discord/types/user.py @@ -27,6 +27,7 @@ from typing import Literal, TypedDict +from .primary_guild import PrimaryGuild from .snowflake import Snowflake @@ -51,3 +52,4 @@ class User(PartialUser, total=False): flags: int premium_type: PremiumType public_flags: int + primary_guild: PrimaryGuild diff --git a/docs/api/events.rst b/docs/api/events.rst index 45d8c1e279..519350e5f0 100644 --- a/docs/api/events.rst +++ b/docs/api/events.rst @@ -736,6 +736,7 @@ Members/Users - username - discriminator - global_name + - primary_guild This requires :attr:`Intents.members` to be enabled.