-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for message snapshots used in message forwarding #9892
Conversation
Create enums and class attributes tracking the type of a message reference (default or forward)
Create a class to track a snapshot of a message
Add class MessageSnapshot to classes exported from message.py
Can't this use the existing Message class? With a potential |
Message snapshots don't have all Message information; in particular, they don't have an author. |
Co-authored-by: MCausc78 <[email protected]>
Move MessageReferenceType definition in types/message.py above MessageReference typed dict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that "forwarded" would make more sense here (in context of users reading relevant documentation) instead of "snapshotted".
Co-authored-by: owocado <[email protected]>
@@ -452,6 +455,92 @@ def guild_id(self) -> Optional[int]: | |||
return self._parent.guild_id | |||
|
|||
|
|||
class MessageSnapshot: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could have a cached_message
attribute that, as its name indicates, has the cached message of this snapshot, if found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ever found? I tested it for a while and none of the forwards I saw had that attribute non-empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As said, if the message is found in the cache then this would be non-empty. If a user forwards a message the bot has cached then the attribute would be filled, else not.
As forwarding is just referencing a message, this would be almost the same as MessageReference.cached_message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait sorry I misunderstood. Yeah that seems like not a bad idea, though I'd need to look into how the cache works exactly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea, it shouldn't be a complicated add either. You already pass the connection state as a parameter but you need to bind it to make it into a property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, some minor nits.
@@ -452,6 +455,92 @@ def guild_id(self) -> Optional[int]: | |||
return self._parent.guild_id | |||
|
|||
|
|||
class MessageSnapshot: | |||
"""Represents a message snapshot attached to a forwarded message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a .. versionadded:: 2.5
into it.
@@ -452,6 +455,92 @@ def guild_id(self) -> Optional[int]: | |||
return self._parent.guild_id | |||
|
|||
|
|||
class MessageSnapshot: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good idea, it shouldn't be a complicated add either. You already pass the connection state as a parameter but you need to bind it to make it into a property.
@@ -218,6 +218,11 @@ def __str__(self) -> str: | |||
return self.name | |||
|
|||
|
|||
class MessageReferenceType(Enum): | |||
default = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be called reply
with an alias to default
. The API docs even call it REPLY
and DEFAULT
despite not mentioning the former. https://discord.com/developers/docs/resources/message#message-reference-types
type: :class:`MessageReferenceType` | ||
The type of message reference. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a versionadded
.
def __init__( | ||
self, | ||
*, | ||
type: MessageReferenceType, | ||
message_id: int, | ||
channel_id: int, | ||
guild_id: Optional[int] = None, | ||
fail_if_not_exists: bool = True, | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MessageReference
is a 'data class' in discord.py which means users can create it, making this a breaking change for those who did since they no longer have a type
parameter. You should give it a default value.
MessageSnapshot | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
.. attributetable:: MessageSnapshot | ||
|
||
.. autoclass:: MessageSnapshot | ||
:members: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is an API received object it needs to be in the model section with the constructor hidden.
As new PR opened on Discord's side, this is missing following fields in |
Sorry, it's unlikely I'll be able to resume work on this PR anytime soon. If anybody wants to take the code, I encourage it. |
Superseded by #9950 |
Summary
Message forwarding was introduced on July 18, 2024. Messages now have a new optional parameter,
message_snapshots
, which is an array of Message Snapshots containing immutable snapshots of a message being forwarded. Such messages will, additionally, always have a reference to the message being forwarded, and that reference will havetype = 1
.This PR adds a
MessageSnapshot
class and amessage_snapshots
parameter to theMessage
class. It also adds thetype
parameter to theMessageReference
class, in order to track whether a reference is a reply or a forward.Checklist