aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-04-09 21:37:49 -0400
committerRapptz <[email protected]>2017-04-09 21:37:49 -0400
commit982308da3c292d9c6aef80ee5cd6e8097d1c900b (patch)
treef7daa35c6721fcabb4cebf5f503d2243ee0c8f05
parentFix view_audit_log incorrect pluralisation. (diff)
downloaddiscord.py-982308da3c292d9c6aef80ee5cd6e8097d1c900b.tar.xz
discord.py-982308da3c292d9c6aef80ee5cd6e8097d1c900b.zip
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).
-rw-r--r--discord/state.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/discord/state.py b/discord/state.py
index f6a1abd9..ad8b26d7 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')