Browse Source

Add cached_message to on_raw_message_edit event

Also add documentation for this behavior
pull/2144/head
Vexs 6 years ago
committed by Rapptz
parent
commit
82a39eb148
  1. 7
      discord/raw_models.py
  2. 5
      discord/state.py
  3. 3
      docs/api.rst

7
discord/raw_models.py

@ -86,14 +86,17 @@ class RawMessageUpdateEvent:
The message ID that got updated. The message ID that got updated.
data: :class:`dict` data: :class:`dict`
The raw data given by the The raw data given by the
`gateway <https://discordapp.com/developers/docs/topics/gateway#message-update>`_ `gateway <https://discordapp.com/developers/docs/topics/gateway#message-update>`
cached_message: Optional[:class:`Message`]
The cached message, if found in the internal message cache.
""" """
__slots__ = ('message_id', 'data') __slots__ = ('message_id', 'data', 'cached_message')
def __init__(self, data): def __init__(self, data):
self.message_id = int(data['id']) self.message_id = int(data['id'])
self.data = data self.data = data
self.cached_message = None
class RawReactionActionEvent: class RawReactionActionEvent:
"""Represents the payload for a :func:`on_raw_reaction_add` or """Represents the payload for a :func:`on_raw_reaction_add` or

5
discord/state.py

@ -386,10 +386,11 @@ class ConnectionState:
def parse_message_update(self, data): def parse_message_update(self, data):
raw = RawMessageUpdateEvent(data) raw = RawMessageUpdateEvent(data)
self.dispatch('raw_message_edit', raw)
message = self._get_message(raw.message_id) message = self._get_message(raw.message_id)
if message is not None: if message is not None:
older_message = copy.copy(message) older_message = copy.copy(message)
raw.cached_message = older_message
self.dispatch('raw_message_edit', raw)
if 'call' in data: if 'call' in data:
# call state message edit # call state message edit
message._handle_call(data['call']) message._handle_call(data['call'])
@ -400,6 +401,8 @@ class ConnectionState:
message._update(channel=message.channel, data=data) message._update(channel=message.channel, data=data)
self.dispatch('message_edit', older_message, message) self.dispatch('message_edit', older_message, message)
else:
self.dispatch('raw_message_edit', raw)
def parse_message_reaction_add(self, data): def parse_message_reaction_add(self, data):
emoji_data = data['emoji'] emoji_data = data['emoji']

3
docs/api.rst

@ -296,6 +296,9 @@ to handle it, which defaults to print a traceback and ignoring the exception.
Called when a message is edited. Unlike :func:`on_message_edit`, this is called Called when a message is edited. Unlike :func:`on_message_edit`, this is called
regardless of the state of the internal message cache. regardless of the state of the internal message cache.
If the message is found in the message cache,
it can be accessed via :attr:`RawMessageUpdateEvent.cached_message`
Due to the inherently raw nature of this event, the data parameter coincides with Due to the inherently raw nature of this event, the data parameter coincides with
the raw data given by the `gateway <https://discordapp.com/developers/docs/topics/gateway#message-update>`_ the raw data given by the `gateway <https://discordapp.com/developers/docs/topics/gateway#message-update>`_

Loading…
Cancel
Save