From 982308da3c292d9c6aef80ee5cd6e8097d1c900b Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 9 Apr 2017 21:37:49 -0400 Subject: [PATCH] Use global user cache to fetch reaction event data. Also make sure it isn't dispatched unless the data meets the integrity checks (i.e. not None). --- discord/state.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/discord/state.py b/discord/state.py index f6a1abd94..ad8b26d70 100644 --- a/discord/state.py +++ b/discord/state.py @@ -321,7 +321,8 @@ class ConnectionState: if message is not None: reaction = message._add_reaction(data) user = self._get_reaction_user(message.channel, int(data['user_id'])) - self.dispatch('reaction_add', reaction, user) + if user: + self.dispatch('reaction_add', reaction, user) def parse_message_reaction_remove_all(self, data): message = self._get_message(int(data['message_id'])) @@ -339,7 +340,8 @@ class ConnectionState: pass else: user = self._get_reaction_user(message.channel, int(data['user_id'])) - self.dispatch('reaction_remove', reaction, user) + if user: + self.dispatch('reaction_remove', reaction, user) def parse_presence_update(self, data): guild_id = utils._get_as_snowflake(data, 'guild_id') @@ -721,14 +723,9 @@ class ConnectionState: self.dispatch('relationship_remove', old) def _get_reaction_user(self, channel, user_id): - if isinstance(channel, DMChannel) and user_id == channel.recipient.id: - return channel.recipient - elif isinstance(channel, TextChannel): + if isinstance(channel, TextChannel): return channel.guild.get_member(user_id) - elif isinstance(channel, GroupChannel): - return utils.find(lambda m: m.id == user_id, channel.recipients) - else: - return None + return self.get_user(user_id) def get_reaction_emoji(self, data): emoji_id = utils._get_as_snowflake(data, 'id')