Skip to content

Commit b17efde

Browse files
ToothyDevPaillat-devpre-commit-ci[bot]
authored
fix: 🐛 Primary guild update not firing on_user_update (#3077)
Co-authored-by: Paillat <jeremiecotti@ik.me> Co-authored-by: Paillat-dev <me@paillat.dev> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Paillat <paillat@pycord.dev>
1 parent 26e6721 commit b17efde

5 files changed

Lines changed: 48 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ These changes are available on the `master` branch, but have not yet been releas
1414

1515
- Added `.extension` attribute to the `AppEmoji` and `GuildEmoji` classes.
1616
([#3055](https://github.com/Pycord-Development/pycord/pull/3055))
17+
- Added the ability to compare instances of `PrimaryGuild`.
18+
([#3077](https://github.com/Pycord-Development/pycord/pull/3077))
1719

1820
### Changed
1921

@@ -42,6 +44,8 @@ These changes are available on the `master` branch, but have not yet been releas
4244
- Fixed an issue where the optional parameters of the `InteractionResponse.send_message`
4345
method were not type-hinted as optional.
4446
([#3061](https://github.com/Pycord-Development/pycord/pull/3061))
47+
- Fixed the update of a user's `primary_guild` to now cause an `on_user_update` event to
48+
fire. ([#3077](https://github.com/Pycord-Development/pycord/pull/3077))
4549

4650
### Removed
4751

discord/member.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,14 +462,30 @@ def _presence_update(
462462

463463
def _update_inner_user(self, user: UserPayload) -> tuple[User, User] | None:
464464
u = self._user
465-
original = (u.name, u._avatar, u.discriminator, u.global_name, u._public_flags)
465+
original = (
466+
u.name,
467+
u._avatar,
468+
u.discriminator,
469+
u.global_name,
470+
u._public_flags,
471+
u.primary_guild,
472+
)
466473
# These keys seem to always be available
474+
if (
475+
new_primary_guild_data := user.get("primary_guild")
476+
) and new_primary_guild_data.get("identity_enabled"):
477+
new_primary_guild: PrimaryGuild | None = PrimaryGuild(
478+
new_primary_guild_data, state=self._state
479+
)
480+
else:
481+
new_primary_guild = None
467482
modified = (
468483
user["username"],
469484
user["avatar"],
470485
user["discriminator"],
471486
user.get("global_name", None) or None,
472487
user.get("public_flags", 0),
488+
new_primary_guild,
473489
)
474490
if original != modified:
475491
to_return = User._copy(self._user)
@@ -479,6 +495,7 @@ def _update_inner_user(self, user: UserPayload) -> tuple[User, User] | None:
479495
u.discriminator,
480496
u.global_name,
481497
u._public_flags,
498+
u.primary_guild,
482499
) = modified
483500
# Signal to dispatch on_user_update
484501
return to_return, u

discord/primary_guild.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ class PrimaryGuild:
4040
4141
.. versionadded:: 2.7
4242
43+
.. container:: operations
44+
45+
.. describe:: x == y
46+
47+
Checks if two Primary Guilds are equal.
48+
49+
.. describe:: x != y
50+
51+
Checks if two Primary Guilds are not equal.
52+
53+
.. versionchanged:: 2.7.1
54+
Primary Guilds are now comparable.
55+
4356
Attributes
4457
----------
4558
identity_guild_id: int
@@ -62,6 +75,16 @@ def __init__(self, data: PrimaryGuildPayload, state: "ConnectionState") -> None:
6275
def __repr__(self) -> str:
6376
return f"<PrimaryGuild identity_guild_id={self.identity_guild_id} identity_enabled={self.identity_enabled} tag={self.tag}>"
6477

78+
def __eq__(self, other: object) -> bool:
79+
if not isinstance(other, PrimaryGuild):
80+
return NotImplemented
81+
82+
return (
83+
self.identity_guild_id == other.identity_guild_id
84+
and self.identity_enabled == other.identity_enabled
85+
and self.tag == other.tag
86+
)
87+
6588
@cached_property
6689
def badge(self) -> Asset | None:
6790
"""Returns the badge asset, if available.

discord/types/user.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from typing import Literal, TypedDict
2929

30+
from .primary_guild import PrimaryGuild
3031
from .snowflake import Snowflake
3132

3233

@@ -51,3 +52,4 @@ class User(PartialUser, total=False):
5152
flags: int
5253
premium_type: PremiumType
5354
public_flags: int
55+
primary_guild: PrimaryGuild

docs/api/events.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ Members/Users
736736
- username
737737
- discriminator
738738
- global_name
739+
- primary_guild
739740

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

0 commit comments

Comments
 (0)