Browse Source

Handle user updates within GUILD_MEMBER_UPDATE

pull/5849/head
Rapptz 5 years ago
parent
commit
c261f7c4a3
  1. 21
      discord/member.py
  2. 6
      discord/state.py

21
discord/member.py

@ -272,17 +272,20 @@ class Member(discord.abc.Messageable, _BaseUser):
self._client_status[None] = data['status'] self._client_status[None] = data['status']
if len(user) > 1: if len(user) > 1:
u = self._user return self._update_inner_user(user)
original = (u.name, u.avatar, u.discriminator)
# These keys seem to always be available
modified = (user['username'], user['avatar'], user['discriminator'])
if original != modified:
to_return = User._copy(self._user)
u.name, u.avatar, u.discriminator = modified
# Signal to dispatch on_user_update
return to_return, u
return False return False
def _update_inner_user(self, user):
u = self._user
original = (u.name, u.avatar, u.discriminator)
# These keys seem to always be available
modified = (user['username'], user['avatar'], user['discriminator'])
if original != modified:
to_return = User._copy(self._user)
u.name, u.avatar, u.discriminator = modified
# Signal to dispatch on_user_update
return to_return, u
@property @property
def status(self): def status(self):
""":class:`Status`: The member's overall status. If the value is unknown, then it will be a :class:`str` instead.""" """:class:`Status`: The member's overall status. If the value is unknown, then it will be a :class:`str` instead."""

6
discord/state.py

@ -698,8 +698,12 @@ class ConnectionState:
member = guild.get_member(user_id) member = guild.get_member(user_id)
if member is not None: if member is not None:
old_member = copy.copy(member) old_member = Member._copy(member)
member._update(data) member._update(data)
user_update = member._update_inner_user(user)
if user_update:
self.dispatch('user_update', user_update[0], user_update[1])
self.dispatch('member_update', old_member, member) self.dispatch('member_update', old_member, member)
else: else:
log.debug('GUILD_MEMBER_UPDATE referencing an unknown member ID: %s. Discarding.', user_id) log.debug('GUILD_MEMBER_UPDATE referencing an unknown member ID: %s. Discarding.', user_id)

Loading…
Cancel
Save