Browse Source

Add `RawReactionActionEvent.member`

pull/2482/head
NCPlayz 5 years ago
committed by Rapptz
parent
commit
bb71f14ce3
  1. 9
      discord/raw_models.py
  2. 10
      discord/state.py

9
discord/raw_models.py

@ -127,13 +127,19 @@ class RawReactionActionEvent(_RawReprMixin):
The guild ID where the reaction got added or removed, if applicable.
emoji: :class:`PartialEmoji`
The custom or unicode emoji being used.
member: Optional[:class:`Member`]
The member who added the reaction. Only available if `event_type` is `REACTION_ADD`.
.. versionadded:: 1.3
event_type: :class:`str`
The event type that triggered this action. Can be
``REACTION_ADD`` for reaction addition or
``REACTION_REMOVE`` for reaction removal.
"""
__slots__ = ('message_id', 'user_id', 'channel_id', 'guild_id', 'emoji')
__slots__ = ('message_id', 'user_id', 'channel_id', 'guild_id', 'emoji',
'event_type', 'member')
def __init__(self, data, emoji, event_type):
self.message_id = int(data['message_id'])
@ -141,6 +147,7 @@ class RawReactionActionEvent(_RawReprMixin):
self.user_id = int(data['user_id'])
self.emoji = emoji
self.event_type = event_type
self.member = None
try:
self.guild_id = int(data['guild_id'])

10
discord/state.py

@ -456,6 +456,13 @@ class ConnectionState:
emoji_id = utils._get_as_snowflake(emoji, 'id')
emoji = PartialEmoji.with_state(self, animated=emoji.get('animated', False), id=emoji_id, name=emoji['name'])
raw = RawReactionActionEvent(data, emoji, 'REACTION_ADD')
member_data = data.get('member')
if member_data:
guild = self._get_guild(raw.guild_id)
raw.member = Member(data=member_data, guild=guild, state=self)
else:
raw.member = None
self.dispatch('raw_reaction_add', raw)
# rich interface here
@ -463,7 +470,8 @@ class ConnectionState:
if message is not None:
emoji = self._upgrade_partial_emoji(emoji)
reaction = message._add_reaction(data, emoji, raw.user_id)
user = self._get_reaction_user(message.channel, raw.user_id)
user = raw.member or self._get_reaction_user(message.channel, raw.user_id)
if user:
self.dispatch('reaction_add', reaction, user)

Loading…
Cancel
Save