Browse Source

Parse full message for raw message edit event

pull/10082/head
Soheab 3 months ago
committed by GitHub
parent
commit
ed95f2f106
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      discord/raw_models.py
  2. 18
      discord/state.py
  3. 3
      discord/types/gateway.py

18
discord/raw_models.py

@ -166,20 +166,22 @@ class RawMessageUpdateEvent(_RawReprMixin):
cached_message: Optional[:class:`Message`]
The cached message, if found in the internal message cache. Represents the message before
it is modified by the data in :attr:`RawMessageUpdateEvent.data`.
message: :class:`Message`
The updated message.
.. versionadded:: 2.5
"""
__slots__ = ('message_id', 'channel_id', 'guild_id', 'data', 'cached_message')
__slots__ = ('message_id', 'channel_id', 'guild_id', 'data', 'cached_message', 'message')
def __init__(self, data: MessageUpdateEvent) -> None:
self.message_id: int = int(data['id'])
self.channel_id: int = int(data['channel_id'])
def __init__(self, data: MessageUpdateEvent, message: Message) -> None:
self.message_id: int = message.id
self.channel_id: int = message.channel.id
self.data: MessageUpdateEvent = data
self.message: Message = message
self.cached_message: Optional[Message] = None
try:
self.guild_id: Optional[int] = int(data['guild_id'])
except KeyError:
self.guild_id: Optional[int] = None
self.guild_id: Optional[int] = message.guild.id if message.guild else None
class RawReactionActionEvent(_RawReprMixin):

18
discord/state.py

@ -690,17 +690,21 @@ class ConnectionState(Generic[ClientT]):
self._messages.remove(msg) # type: ignore
def parse_message_update(self, data: gw.MessageUpdateEvent) -> None:
raw = RawMessageUpdateEvent(data)
message = self._get_message(raw.message_id)
if message is not None:
older_message = copy.copy(message)
channel, _ = self._get_guild_channel(data)
# channel would be the correct type here
updated_message = Message(channel=channel, data=data, state=self) # type: ignore
raw = RawMessageUpdateEvent(data=data, message=updated_message)
cached_message = self._get_message(updated_message.id)
if cached_message is not None:
older_message = copy.copy(cached_message)
raw.cached_message = older_message
self.dispatch('raw_message_edit', raw)
message._update(data)
cached_message._update(data)
# Coerce the `after` parameter to take the new updated Member
# ref: #5999
older_message.author = message.author
self.dispatch('message_edit', older_message, message)
older_message.author = updated_message.author
self.dispatch('message_edit', older_message, updated_message)
else:
self.dispatch('raw_message_edit', raw)

3
discord/types/gateway.py

@ -92,8 +92,7 @@ class MessageDeleteBulkEvent(TypedDict):
guild_id: NotRequired[Snowflake]
class MessageUpdateEvent(Message):
channel_id: Snowflake
MessageUpdateEvent = MessageCreateEvent
class MessageReactionAddEvent(TypedDict):

Loading…
Cancel
Save