Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
19 changes: 18 additions & 1 deletion discord/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions discord/primary_guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -62,6 +75,16 @@ def __init__(self, data: PrimaryGuildPayload, state: "ConnectionState") -> None:
def __repr__(self) -> str:
return f"<PrimaryGuild identity_guild_id={self.identity_guild_id} identity_enabled={self.identity_enabled} tag={self.tag}>"

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.
Expand Down
2 changes: 2 additions & 0 deletions discord/types/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from typing import Literal, TypedDict

from .primary_guild import PrimaryGuild
from .snowflake import Snowflake


Expand All @@ -51,3 +52,4 @@ class User(PartialUser, total=False):
flags: int
premium_type: PremiumType
public_flags: int
primary_guild: PrimaryGuild
1 change: 1 addition & 0 deletions docs/api/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ Members/Users
- username
- discriminator
- global_name
- primary_guild

This requires :attr:`Intents.members` to be enabled.

Expand Down