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).
This commit is contained in:
parent
580b4baef9
commit
982308da3c
@ -321,6 +321,7 @@ class ConnectionState:
|
|||||||
if message is not None:
|
if message is not None:
|
||||||
reaction = message._add_reaction(data)
|
reaction = message._add_reaction(data)
|
||||||
user = self._get_reaction_user(message.channel, int(data['user_id']))
|
user = self._get_reaction_user(message.channel, int(data['user_id']))
|
||||||
|
if user:
|
||||||
self.dispatch('reaction_add', reaction, user)
|
self.dispatch('reaction_add', reaction, user)
|
||||||
|
|
||||||
def parse_message_reaction_remove_all(self, data):
|
def parse_message_reaction_remove_all(self, data):
|
||||||
@ -339,6 +340,7 @@ class ConnectionState:
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
user = self._get_reaction_user(message.channel, int(data['user_id']))
|
user = self._get_reaction_user(message.channel, int(data['user_id']))
|
||||||
|
if user:
|
||||||
self.dispatch('reaction_remove', reaction, user)
|
self.dispatch('reaction_remove', reaction, user)
|
||||||
|
|
||||||
def parse_presence_update(self, data):
|
def parse_presence_update(self, data):
|
||||||
@ -721,14 +723,9 @@ class ConnectionState:
|
|||||||
self.dispatch('relationship_remove', old)
|
self.dispatch('relationship_remove', old)
|
||||||
|
|
||||||
def _get_reaction_user(self, channel, user_id):
|
def _get_reaction_user(self, channel, user_id):
|
||||||
if isinstance(channel, DMChannel) and user_id == channel.recipient.id:
|
if isinstance(channel, TextChannel):
|
||||||
return channel.recipient
|
|
||||||
elif isinstance(channel, TextChannel):
|
|
||||||
return channel.guild.get_member(user_id)
|
return channel.guild.get_member(user_id)
|
||||||
elif isinstance(channel, GroupChannel):
|
return self.get_user(user_id)
|
||||||
return utils.find(lambda m: m.id == user_id, channel.recipients)
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_reaction_emoji(self, data):
|
def get_reaction_emoji(self, data):
|
||||||
emoji_id = utils._get_as_snowflake(data, 'id')
|
emoji_id = utils._get_as_snowflake(data, 'id')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user