From f8999b63ae5f331452eec611b874002aa6a88658 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 8 Apr 2019 07:40:26 -0400 Subject: Fix long-standing issue with user updates not dispatching properly. This fix is long coming. For a long time due to the addition of a global user cache, the on_member_update event would only have the updated user in the very first dispatch due to a quirk in the reference only being updated once. In order to fix this issue two things had to change: 1. There had to be a new event, `on_user_update` to complement the equivalent member event. 2. Unnecessary copies of User had to be removed to compensate for the performance hit from the diffing. While doing these two fixes I also re-evaluated some more unnecessary copies done during the PRESENCE_UPDATE to add member case while fetch_offline_members=False is set or due to chunking issues. The number of copies was brought down from 2 to 1, discounting the original Member creation. Unsure on the benefits of this one, however. N.B: this doesn't change the pre-existing behaviour of on_member_update --- discord/state.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'discord/state.py') diff --git a/discord/state.py b/discord/state.py index ab3f2ac7..3d420a0a 100644 --- a/discord/state.py +++ b/discord/state.py @@ -461,11 +461,14 @@ class ConnectionState: # skip these useless cases. return - member = Member(guild=guild, data=data, state=self) + member, old_member = Member._from_presence_update(guild=guild, data=data, state=self) guild._add_member(member) + else: + old_member = Member._copy(member) + user_update = member._presence_update(data=data, user=user) + if user_update: + self.dispatch('user_update', user_update[0], user_update[1]) - old_member = Member._copy(member) - member._presence_update(data=data, user=user) self.dispatch('member_update', old_member, member) def parse_user_update(self, data): -- cgit v1.2.3