From 6f9f5d68e3c1a30d599d18fed770dea63f0581ed Mon Sep 17 00:00:00 2001 From: DA344 <108473820+DA-344@users.noreply.github.com> Date: Wed, 20 Mar 2024 10:59:30 +0100 Subject: [PATCH 01/36] Added warning for my fork :v --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 621a69500291..cc2c56aefa57 100644 --- a/README.rst +++ b/README.rst @@ -11,6 +11,9 @@ discord.py :target: https://pypi.python.org/pypi/discord.py :alt: PyPI supported Python versions +Please, donnot use this fork's master branch, it is... not for usage, use the different branches that implement other functions, such as recurrent events or member safety information. +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. Key Features From 6561f741f9df1599b4164ae953667dc489e26896 Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Fri, 19 Jul 2024 11:55:47 -0300 Subject: [PATCH 02/36] Create message reference type Create enums and class attributes tracking the type of a message reference (default or forward) --- discord/enums.py | 5 +++++ discord/message.py | 19 ++++++++++++++++--- discord/types/message.py | 3 +++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/discord/enums.py b/discord/enums.py index eaf8aef5e058..3a2c05ca5c77 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -218,6 +218,11 @@ def __str__(self) -> str: return self.name +class MessageReferenceType(Enum): + default = 0 + forward = 1 + + class MessageType(Enum): default = 0 recipient_add = 1 diff --git a/discord/message.py b/discord/message.py index 1d1a3c96c19c..dbcba53876d7 100644 --- a/discord/message.py +++ b/discord/message.py @@ -49,7 +49,7 @@ from .reaction import Reaction from .emoji import Emoji from .partial_emoji import PartialEmoji -from .enums import InteractionType, MessageType, ChannelType, try_enum +from .enums import InteractionType, MessageReferenceType, MessageType, ChannelType, try_enum from .errors import HTTPException from .components import _component_factory from .embeds import Embed @@ -462,6 +462,8 @@ class MessageReference: Attributes ----------- + type: :class:`MessageReferenceType` + The type of message reference. message_id: Optional[:class:`int`] The id of the message referenced. channel_id: :class:`int` @@ -486,10 +488,19 @@ class MessageReference: .. versionadded:: 1.6 """ - __slots__ = ('message_id', 'channel_id', 'guild_id', 'fail_if_not_exists', 'resolved', '_state') + __slots__ = ('type', 'message_id', 'channel_id', 'guild_id', 'fail_if_not_exists', 'resolved', '_state') - def __init__(self, *, message_id: int, channel_id: int, guild_id: Optional[int] = None, fail_if_not_exists: bool = True): + def __init__( + self, + *, + type: int, + message_id: int, + channel_id: int, + guild_id: Optional[int] = None, + fail_if_not_exists: bool = True, + ): self._state: Optional[ConnectionState] = None + self.type: MessageReferenceType = try_enum(MessageReferenceType, type) self.resolved: Optional[Union[Message, DeletedReferencedMessage]] = None self.message_id: Optional[int] = message_id self.channel_id: int = channel_id @@ -499,6 +510,7 @@ def __init__(self, *, message_id: int, channel_id: int, guild_id: Optional[int] @classmethod def with_state(cls, state: ConnectionState, data: MessageReferencePayload) -> Self: self = cls.__new__(cls) + self.type = try_enum(MessageReferenceType, data.get('type', MessageReferenceType.default)) self.message_id = utils._get_as_snowflake(data, 'message_id') self.channel_id = int(data['channel_id']) self.guild_id = utils._get_as_snowflake(data, 'guild_id') @@ -529,6 +541,7 @@ def from_message(cls, message: PartialMessage, *, fail_if_not_exists: bool = Tru A reference to the message. """ self = cls( + type=0, message_id=message.id, channel_id=message.channel.id, guild_id=getattr(message.guild, 'id', None), diff --git a/discord/types/message.py b/discord/types/message.py index bdb3f10ef9e6..f7a20eea3757 100644 --- a/discord/types/message.py +++ b/discord/types/message.py @@ -103,6 +103,7 @@ class MessageApplication(TypedDict): class MessageReference(TypedDict, total=False): + type: MessageReferenceType message_id: Snowflake channel_id: Required[Snowflake] guild_id: Snowflake @@ -116,6 +117,8 @@ class RoleSubscriptionData(TypedDict): is_renewal: bool +MessageReferenceType = Literal[0, 1] + MessageType = Literal[ 0, 1, From 43e0fd2029b6a0fc5794d533ca796a16c62aec1d Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Fri, 19 Jul 2024 12:02:26 -0300 Subject: [PATCH 03/36] Create MessageSnapshot class Create a class to track a snapshot of a message --- discord/message.py | 89 ++++++++++++++++++++++++++++++++++++++++ discord/types/message.py | 12 ++++++ 2 files changed, 101 insertions(+) diff --git a/discord/message.py b/discord/message.py index dbcba53876d7..8f7fc621fc81 100644 --- a/discord/message.py +++ b/discord/message.py @@ -32,6 +32,7 @@ from typing import ( Dict, TYPE_CHECKING, + Literal, Sequence, Union, List, @@ -72,6 +73,7 @@ Message as MessagePayload, Attachment as AttachmentPayload, MessageReference as MessageReferencePayload, + MessageSnapshot as MessageSnapshotPayload, MessageApplication as MessageApplicationPayload, MessageActivity as MessageActivityPayload, RoleSubscriptionData as RoleSubscriptionDataPayload, @@ -452,6 +454,93 @@ def guild_id(self) -> Optional[int]: return self._parent.guild_id +class MessageSnapshot: + """Represents a message snapshot attached to a forwarded message. + + Attributes + ----------- + type: :class:`MessageType` + The type of message of the snapshotted message. + content: :class:`str` + The actual contents of the snapshotted message. + If :attr:`Intents.message_content` is not enabled this will always be an empty string + unless the bot is mentioned or the message is a direct message. + embeds: List[:class:`Embed`] + A list of embeds the snapshotted message has. + If :attr:`Intents.message_content` is not enabled this will always be an empty list + unless the bot is mentioned or the message is a direct message. + attachments: List[:class:`Attachment`] + A list of attachments given to the snapshotted message. + If :attr:`Intents.message_content` is not enabled this will always be an empty list + unless the bot is mentioned or the message is a direct message. + timestamp: :class:`datetime.datetime` + The snapshotted message's timestamp. + flags: :class:`MessageFlags` + Extra features of the the message snapshot. + """ + + __slots__ = ( + '_cs_raw_channel_mentions', + '_cs_raw_mentions', + '_cs_raw_role_mentions', + '_edited_timestamp', + 'attachments', + 'content', + 'embeds', + 'flags', + 'timestamp', + 'type', + ) + + @classmethod + def _from_value( + cls, + state: ConnectionState, + message_snapshots: Optional[List[Dict[Literal['message'], MessageSnapshotPayload]]], + ): + if not message_snapshots: + return None + + return [MessageSnapshot(state, snapshot['message']) for snapshot in message_snapshots] + + def __init__(self, state: ConnectionState, data: MessageSnapshotPayload): + self.type: MessageType = try_enum(MessageType, data['type']) + self.content: str = data['content'] + self.embeds: List[Embed] = [Embed.from_dict(a) for a in data['embeds']] + self.attachments: List[Attachment] = [Attachment(data=a, state=state) for a in data['attachments']] + self.timestamp: datetime.datetime = utils.parse_time(data['timestamp']) + self._edited_timestamp: Optional[datetime.datetime] = utils.parse_time(data['edited_timestamp']) + self.flags: MessageFlags = MessageFlags._from_value(data.get('flags', 0)) + + def __repr__(self) -> str: + name = self.__class__.__name__ + return f'<{name} type={self.type!r} timestamp={self.timestamp!r} flags={self.flags!r}>' + + @utils.cached_slot_property('_cs_raw_mentions') + def raw_mentions(self) -> List[int]: + """List[:class:`int`]: A property that returns an array of user IDs matched with + the syntax of ``<@user_id>`` in the message content. + + This allows you to receive the user IDs of mentioned users + even in a private message context. + """ + return [int(x) for x in re.findall(r'<@!?([0-9]{15,20})>', self.content)] + + @utils.cached_slot_property('_cs_raw_channel_mentions') + def raw_channel_mentions(self) -> List[int]: + """List[:class:`int`]: A property that returns an array of channel IDs matched with + the syntax of ``<#channel_id>`` in the message content. + """ + return [int(x) for x in re.findall(r'<#([0-9]{15,20})>', self.content)] + + @utils.cached_slot_property('_cs_raw_role_mentions') + def raw_role_mentions(self) -> List[int]: + """List[:class:`int`]: A property that returns an array of role IDs matched with + the syntax of ``<@&role_id>`` in the message content. + """ + return [int(x) for x in re.findall(r'<@&([0-9]{15,20})>', self.content)] + + class MessageReference: """Represents a reference to a :class:`~discord.Message`. diff --git a/discord/types/message.py b/discord/types/message.py index f7a20eea3757..1fbbdcf38b5a 100644 --- a/discord/types/message.py +++ b/discord/types/message.py @@ -157,6 +157,18 @@ class RoleSubscriptionData(TypedDict): ] +class MessageSnapshot(TypedDict): + type: MessageType + content: str + embeds: List[Embed] + attachments: List[Attachment] + timestamp: str + edited_timestamp: Optional[str] + flags: NotRequired[int] + mentions: List[UserWithMember] + mention_roles: SnowflakeList + + class Message(PartialMessage): id: Snowflake author: User From 0c6eb9e450351020133ba3601cf36485cae4dfdb Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Fri, 19 Jul 2024 12:02:44 -0300 Subject: [PATCH 04/36] Store list of message snapshots in message --- discord/message.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/discord/message.py b/discord/message.py index 8f7fc621fc81..12c61b68e5c4 100644 --- a/discord/message.py +++ b/discord/message.py @@ -1864,6 +1864,8 @@ class Message(PartialMessage, Hashable): The poll attached to this message. .. versionadded:: 2.4 + message_snapshots: Optional[List[:class:`MessageSnapshot`]] + The message snapshots attached to this message. """ __slots__ = ( @@ -1900,6 +1902,7 @@ class Message(PartialMessage, Hashable): 'position', 'interaction_metadata', 'poll', + 'message_snapshots' ) if TYPE_CHECKING: @@ -1938,6 +1941,7 @@ def __init__( self.position: Optional[int] = data.get('position') self.application_id: Optional[int] = utils._get_as_snowflake(data, 'application_id') self.stickers: List[StickerItem] = [StickerItem(data=d, state=state) for d in data.get('sticker_items', [])] + self.message_snapshots: Optional[List[MessageSnapshot]] = MessageSnapshot._from_value(state, data.get('message_snapshots')) # This updates the poll so it has the counts, if the message # was previously cached. From 7b7dd83ad98b2648ffb1bacb6c547c9d4a841da0 Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Fri, 19 Jul 2024 15:09:26 -0300 Subject: [PATCH 05/36] Add MessageSnapshot to exported classes Add class MessageSnapshot to classes exported from message.py --- discord/message.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/message.py b/discord/message.py index 12c61b68e5c4..38bdfd272d4a 100644 --- a/discord/message.py +++ b/discord/message.py @@ -110,6 +110,7 @@ 'PartialMessage', 'MessageInteraction', 'MessageReference', + 'MessageSnapshot', 'DeletedReferencedMessage', 'MessageApplication', 'RoleSubscriptionInfo', From cc10a757fd4bc317b0bcc032681729879b0ccac8 Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 12:48:41 -0300 Subject: [PATCH 06/36] Remove trailing spaces --- discord/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/message.py b/discord/message.py index 38bdfd272d4a..534c52453174 100644 --- a/discord/message.py +++ b/discord/message.py @@ -516,7 +516,7 @@ def __init__(self, state: ConnectionState, data: MessageSnapshotPayload): def __repr__(self) -> str: name = self.__class__.__name__ return f'<{name} type={self.type!r} timestamp={self.timestamp!r} flags={self.flags!r}>' - + @utils.cached_slot_property('_cs_raw_mentions') def raw_mentions(self) -> List[int]: """List[:class:`int`]: A property that returns an array of user IDs matched with From 4c65968261ce98e60691bb5cc3b0e28ea4ad041d Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 12:50:35 -0300 Subject: [PATCH 07/36] Add MessageSnapshit to api.rst --- docs/api.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/api.rst b/docs/api.rst index 41cf6549d169..b6eb2792ba3a 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -5166,6 +5166,14 @@ AllowedMentions .. autoclass:: AllowedMentions :members: +MessageSnapshot +~~~~~~~~~~~~~~~~~ + +.. attributetable:: MessageSnapshot + +.. autoclass:: MessageSnapshot + :members: + MessageReference ~~~~~~~~~~~~~~~~~ From 57f5949d3ad842a82f0898801a68d97fdd331ff1 Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 12:56:56 -0300 Subject: [PATCH 08/36] Typo fix --- discord/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/message.py b/discord/message.py index 534c52453174..2c394205869c 100644 --- a/discord/message.py +++ b/discord/message.py @@ -461,7 +461,7 @@ class MessageSnapshot: Attributes ----------- type: :class:`MessageType` - The type of message of the snapshotted message. + The type of the snapshotted message. content: :class:`str` The actual contents of the snapshotted message. If :attr:`Intents.message_content` is not enabled this will always be an empty string From ea5763be570167b869559b7f25e0af3955d02ecf Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 12:57:27 -0300 Subject: [PATCH 09/36] Remove incorrect documentation --- discord/message.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/discord/message.py b/discord/message.py index 2c394205869c..7df9eef0efbf 100644 --- a/discord/message.py +++ b/discord/message.py @@ -464,16 +464,10 @@ class MessageSnapshot: The type of the snapshotted message. content: :class:`str` The actual contents of the snapshotted message. - If :attr:`Intents.message_content` is not enabled this will always be an empty string - unless the bot is mentioned or the message is a direct message. embeds: List[:class:`Embed`] A list of embeds the snapshotted message has. - If :attr:`Intents.message_content` is not enabled this will always be an empty list - unless the bot is mentioned or the message is a direct message. attachments: List[:class:`Attachment`] A list of attachments given to the snapshotted message. - If :attr:`Intents.message_content` is not enabled this will always be an empty list - unless the bot is mentioned or the message is a direct message. timestamp: :class:`datetime.datetime` The snapshotted message's timestamp. flags: :class:`MessageFlags` From 6ed45c156648625e55dbb6510a776b1ae4e5246c Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 12:50:35 -0300 Subject: [PATCH 10/36] Add MessageSnapshot to api.rst --- docs/api.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/api.rst b/docs/api.rst index 41cf6549d169..b6eb2792ba3a 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -5166,6 +5166,14 @@ AllowedMentions .. autoclass:: AllowedMentions :members: +MessageSnapshot +~~~~~~~~~~~~~~~~~ + +.. attributetable:: MessageSnapshot + +.. autoclass:: MessageSnapshot + :members: + MessageReference ~~~~~~~~~~~~~~~~~ From 46d157c930444ea99a84e3235011cbdfbbc734a4 Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 12:56:56 -0300 Subject: [PATCH 11/36] Typo fix --- discord/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/message.py b/discord/message.py index 534c52453174..2c394205869c 100644 --- a/discord/message.py +++ b/discord/message.py @@ -461,7 +461,7 @@ class MessageSnapshot: Attributes ----------- type: :class:`MessageType` - The type of message of the snapshotted message. + The type of the snapshotted message. content: :class:`str` The actual contents of the snapshotted message. If :attr:`Intents.message_content` is not enabled this will always be an empty string From aa01eca04e363589948241fe35be32d5dc4edab8 Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 12:57:27 -0300 Subject: [PATCH 12/36] Remove incorrect documentation --- discord/message.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/discord/message.py b/discord/message.py index 2c394205869c..7df9eef0efbf 100644 --- a/discord/message.py +++ b/discord/message.py @@ -464,16 +464,10 @@ class MessageSnapshot: The type of the snapshotted message. content: :class:`str` The actual contents of the snapshotted message. - If :attr:`Intents.message_content` is not enabled this will always be an empty string - unless the bot is mentioned or the message is a direct message. embeds: List[:class:`Embed`] A list of embeds the snapshotted message has. - If :attr:`Intents.message_content` is not enabled this will always be an empty list - unless the bot is mentioned or the message is a direct message. attachments: List[:class:`Attachment`] A list of attachments given to the snapshotted message. - If :attr:`Intents.message_content` is not enabled this will always be an empty list - unless the bot is mentioned or the message is a direct message. timestamp: :class:`datetime.datetime` The snapshotted message's timestamp. flags: :class:`MessageFlags` From 6867dc61841dc4bc992e5397b637e503ec8d1e7b Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 13:48:17 -0300 Subject: [PATCH 13/36] Use MessageReferenceType in MessageReference initialiser --- discord/message.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/message.py b/discord/message.py index 7df9eef0efbf..d77e5681c572 100644 --- a/discord/message.py +++ b/discord/message.py @@ -577,7 +577,7 @@ class MessageReference: def __init__( self, *, - type: int, + type: MessageReferenceType, message_id: int, channel_id: int, guild_id: Optional[int] = None, @@ -625,7 +625,7 @@ def from_message(cls, message: PartialMessage, *, fail_if_not_exists: bool = Tru A reference to the message. """ self = cls( - type=0, + type=MessageReferenceType.default, message_id=message.id, channel_id=message.channel.id, guild_id=getattr(message.guild, 'id', None), From e58f341f29b5fd921d0b7c7ea53becbea80e81db Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 13:48:30 -0300 Subject: [PATCH 14/36] Rename MessageSnapshot's timestamp to created_at --- discord/message.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/discord/message.py b/discord/message.py index d77e5681c572..19572f8daa9d 100644 --- a/discord/message.py +++ b/discord/message.py @@ -468,8 +468,8 @@ class MessageSnapshot: A list of embeds the snapshotted message has. attachments: List[:class:`Attachment`] A list of attachments given to the snapshotted message. - timestamp: :class:`datetime.datetime` - The snapshotted message's timestamp. + created_at: :class:`datetime.datetime` + The snapshotted message's time of creation. flags: :class:`MessageFlags` Extra features of the the message snapshot. """ @@ -483,7 +483,7 @@ class MessageSnapshot: 'content', 'embeds', 'flags', - 'timestamp', + 'created_at', 'type', ) @@ -503,13 +503,13 @@ def __init__(self, state: ConnectionState, data: MessageSnapshotPayload): self.content: str = data['content'] self.embeds: List[Embed] = [Embed.from_dict(a) for a in data['embeds']] self.attachments: List[Attachment] = [Attachment(data=a, state=state) for a in data['attachments']] - self.timestamp: datetime.datetime = utils.parse_time(data['timestamp']) + self.created_at: datetime.datetime = utils.parse_time(data['timestamp']) self._edited_timestamp: Optional[datetime.datetime] = utils.parse_time(data['edited_timestamp']) self.flags: MessageFlags = MessageFlags._from_value(data.get('flags', 0)) def __repr__(self) -> str: name = self.__class__.__name__ - return f'<{name} type={self.type!r} timestamp={self.timestamp!r} flags={self.flags!r}>' + return f'<{name} type={self.type!r} created_at={self.created_at!r} flags={self.flags!r}>' @utils.cached_slot_property('_cs_raw_mentions') def raw_mentions(self) -> List[int]: From 756f6c6122ee44af6a6412b0e0a7cf7363636f4d Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 13:58:10 -0300 Subject: [PATCH 15/36] Create edited_at property in MessageSnapshot --- discord/message.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/discord/message.py b/discord/message.py index 19572f8daa9d..e2e009712abb 100644 --- a/discord/message.py +++ b/discord/message.py @@ -535,6 +535,10 @@ def raw_role_mentions(self) -> List[int]: """ return [int(x) for x in re.findall(r'<@&([0-9]{15,20})>', self.content)] + @property + def edited_at(self) -> Optional[datetime.datetime]: + """Optional[:class:`datetime.datetime`]: An aware UTC datetime object containing the edited time of the snapshotted message.""" + return self._edited_timestamp class MessageReference: """Represents a reference to a :class:`~discord.Message`. From 64597005800894adfbf1953376210db1d2cb27c7 Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 14:04:43 -0300 Subject: [PATCH 16/36] Add missing line break --- discord/message.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/message.py b/discord/message.py index e2e009712abb..dd1f3573492e 100644 --- a/discord/message.py +++ b/discord/message.py @@ -540,6 +540,7 @@ def edited_at(self) -> Optional[datetime.datetime]: """Optional[:class:`datetime.datetime`]: An aware UTC datetime object containing the edited time of the snapshotted message.""" return self._edited_timestamp + class MessageReference: """Represents a reference to a :class:`~discord.Message`. From 15b54ff93a18b2cddf233e872e8f54f33d1b2e47 Mon Sep 17 00:00:00 2001 From: Red Date: Mon, 22 Jul 2024 14:20:55 -0300 Subject: [PATCH 17/36] Pass 0 to try_enum in MessageReference.with_state() Co-authored-by: MCausc78 --- discord/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/message.py b/discord/message.py index dd1f3573492e..f19123cf3458 100644 --- a/discord/message.py +++ b/discord/message.py @@ -599,7 +599,7 @@ def __init__( @classmethod def with_state(cls, state: ConnectionState, data: MessageReferencePayload) -> Self: self = cls.__new__(cls) - self.type = try_enum(MessageReferenceType, data.get('type', MessageReferenceType.default)) + self.type = try_enum(MessageReferenceType, data.get('type', 0)) self.message_id = utils._get_as_snowflake(data, 'message_id') self.channel_id = int(data['channel_id']) self.guild_id = utils._get_as_snowflake(data, 'guild_id') From 73c690433d488efb9ef4d9b135f63df6aeb0ae46 Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 14:23:15 -0300 Subject: [PATCH 18/36] Use type directly in MessageReference init --- discord/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/message.py b/discord/message.py index f19123cf3458..91996c6b06e5 100644 --- a/discord/message.py +++ b/discord/message.py @@ -589,7 +589,7 @@ def __init__( fail_if_not_exists: bool = True, ): self._state: Optional[ConnectionState] = None - self.type: MessageReferenceType = try_enum(MessageReferenceType, type) + self.type: MessageReferenceType = type self.resolved: Optional[Union[Message, DeletedReferencedMessage]] = None self.message_id: Optional[int] = message_id self.channel_id: int = channel_id From bf1762c88b4b4b29ee38baa0ab07f21ee19d0335 Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 22:52:47 -0300 Subject: [PATCH 19/36] Format message.py --- discord/message.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/discord/message.py b/discord/message.py index 91996c6b06e5..4bee36e6907a 100644 --- a/discord/message.py +++ b/discord/message.py @@ -1902,7 +1902,7 @@ class Message(PartialMessage, Hashable): 'position', 'interaction_metadata', 'poll', - 'message_snapshots' + 'message_snapshots', ) if TYPE_CHECKING: @@ -1941,7 +1941,9 @@ def __init__( self.position: Optional[int] = data.get('position') self.application_id: Optional[int] = utils._get_as_snowflake(data, 'application_id') self.stickers: List[StickerItem] = [StickerItem(data=d, state=state) for d in data.get('sticker_items', [])] - self.message_snapshots: Optional[List[MessageSnapshot]] = MessageSnapshot._from_value(state, data.get('message_snapshots')) + self.message_snapshots: Optional[List[MessageSnapshot]] = MessageSnapshot._from_value( + state, data.get('message_snapshots') + ) # This updates the poll so it has the counts, if the message # was previously cached. From 8da22c051fdd7c58fa7b8a280e5c9c8d9aa15f0b Mon Sep 17 00:00:00 2001 From: Red Magnos Date: Mon, 22 Jul 2024 22:53:54 -0300 Subject: [PATCH 20/36] Move MessageReferenceType definition Move MessageReferenceType definition in types/message.py above MessageReference typed dict --- discord/types/message.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/discord/types/message.py b/discord/types/message.py index 1fbbdcf38b5a..4e60c58b002e 100644 --- a/discord/types/message.py +++ b/discord/types/message.py @@ -102,6 +102,9 @@ class MessageApplication(TypedDict): cover_image: NotRequired[str] +MessageReferenceType = Literal[0, 1] + + class MessageReference(TypedDict, total=False): type: MessageReferenceType message_id: Snowflake @@ -117,8 +120,6 @@ class RoleSubscriptionData(TypedDict): is_renewal: bool -MessageReferenceType = Literal[0, 1] - MessageType = Literal[ 0, 1, From 3e9abf4748b6c3067caed714e23371895c47500c Mon Sep 17 00:00:00 2001 From: Red Date: Wed, 24 Jul 2024 16:38:06 -0300 Subject: [PATCH 21/36] Replace "snapshotted" with "forwarded" in docstrings Co-authored-by: owocado <24418520+owocado@users.noreply.github.com> --- discord/message.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/discord/message.py b/discord/message.py index 4bee36e6907a..81f7881004b6 100644 --- a/discord/message.py +++ b/discord/message.py @@ -461,15 +461,15 @@ class MessageSnapshot: Attributes ----------- type: :class:`MessageType` - The type of the snapshotted message. + The type of the forwarded message. content: :class:`str` - The actual contents of the snapshotted message. + The actual contents of the forwarded message. embeds: List[:class:`Embed`] - A list of embeds the snapshotted message has. + A list of embeds the forwarded message has. attachments: List[:class:`Attachment`] - A list of attachments given to the snapshotted message. + A list of attachments given to the forwarded message. created_at: :class:`datetime.datetime` - The snapshotted message's time of creation. + The forwarded message's time of creation. flags: :class:`MessageFlags` Extra features of the the message snapshot. """ @@ -537,7 +537,7 @@ def raw_role_mentions(self) -> List[int]: @property def edited_at(self) -> Optional[datetime.datetime]: - """Optional[:class:`datetime.datetime`]: An aware UTC datetime object containing the edited time of the snapshotted message.""" + """Optional[:class:`datetime.datetime`]: An aware UTC datetime object containing the edited time of the forwarded message.""" return self._edited_timestamp From 85969e1d71f2faf64d6a9ab31c965b3082169120 Mon Sep 17 00:00:00 2001 From: Developer Anonymous Date: Sun, 29 Sep 2024 18:40:37 +0200 Subject: [PATCH 22/36] Changes --- discord/enums.py | 4 ++- discord/message.py | 80 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/discord/enums.py b/discord/enums.py index 3a2c05ca5c77..0e85b3586669 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -219,9 +219,11 @@ def __str__(self) -> str: class MessageReferenceType(Enum): - default = 0 + reply = 0 forward = 1 + default = 0 + class MessageType(Enum): default = 0 diff --git a/discord/message.py b/discord/message.py index 81f7881004b6..a37170748ac6 100644 --- a/discord/message.py +++ b/discord/message.py @@ -458,6 +458,8 @@ def guild_id(self) -> Optional[int]: class MessageSnapshot: """Represents a message snapshot attached to a forwarded message. + .. versionadded:: 2.5 + Attributes ----------- type: :class:`MessageType` @@ -485,6 +487,7 @@ class MessageSnapshot: 'flags', 'created_at', 'type', + '_state', ) @classmethod @@ -506,6 +509,7 @@ def __init__(self, state: ConnectionState, data: MessageSnapshotPayload): self.created_at: datetime.datetime = utils.parse_time(data['timestamp']) self._edited_timestamp: Optional[datetime.datetime] = utils.parse_time(data['edited_timestamp']) self.flags: MessageFlags = MessageFlags._from_value(data.get('flags', 0)) + self._state: ConnectionState = state def __repr__(self) -> str: name = self.__class__.__name__ @@ -540,6 +544,15 @@ def edited_at(self) -> Optional[datetime.datetime]: """Optional[:class:`datetime.datetime`]: An aware UTC datetime object containing the edited time of the forwarded message.""" return self._edited_timestamp + @property + def cached_message(self) -> Optional[Message]: + """Optional[:class:`Message`]: The resolved message object this snapshot points to, + if cached. + """ + # We do this trick as ID is not provided. + id = int(self.created_at.timestamp()) - utils.DISCORD_EPOCH + return self._state._get_message(id) + class MessageReference: """Represents a reference to a :class:`~discord.Message`. @@ -582,11 +595,11 @@ class MessageReference: def __init__( self, *, - type: MessageReferenceType, message_id: int, channel_id: int, guild_id: Optional[int] = None, fail_if_not_exists: bool = True, + type: MessageReferenceType = MessageReferenceType.reply, ): self._state: Optional[ConnectionState] = None self.type: MessageReferenceType = type @@ -609,7 +622,13 @@ def with_state(cls, state: ConnectionState, data: MessageReferencePayload) -> Se return self @classmethod - def from_message(cls, message: PartialMessage, *, fail_if_not_exists: bool = True) -> Self: + def from_message( + cls, + message: PartialMessage, + *, + fail_if_not_exists: bool = True, + type: MessageReferenceType = MessageReferenceType.reply, + ) -> Self: """Creates a :class:`MessageReference` from an existing :class:`~discord.Message`. .. versionadded:: 1.6 @@ -623,6 +642,10 @@ def from_message(cls, message: PartialMessage, *, fail_if_not_exists: bool = Tru if the message no longer exists or Discord could not fetch the message. .. versionadded:: 1.7 + type: :class:`~discord.MessageReferenceType` + The type of message reference this is. + + .. versionadded:: 2.5 Returns ------- @@ -630,11 +653,11 @@ def from_message(cls, message: PartialMessage, *, fail_if_not_exists: bool = Tru A reference to the message. """ self = cls( - type=MessageReferenceType.default, message_id=message.id, channel_id=message.channel.id, guild_id=getattr(message.guild, 'id', None), fail_if_not_exists=fail_if_not_exists, + type=type, ) self._state = message._state return self @@ -1689,7 +1712,12 @@ async def end_poll(self) -> Message: return Message(state=self._state, channel=self.channel, data=data) - def to_reference(self, *, fail_if_not_exists: bool = True) -> MessageReference: + def to_reference( + self, + *, + fail_if_not_exists: bool = True, + type: MessageReferenceType = MessageReferenceType.reply, + ) -> MessageReference: """Creates a :class:`~discord.MessageReference` from the current message. .. versionadded:: 1.6 @@ -1708,7 +1736,49 @@ def to_reference(self, *, fail_if_not_exists: bool = True) -> MessageReference: The reference to this message. """ - return MessageReference.from_message(self, fail_if_not_exists=fail_if_not_exists) + return MessageReference.from_message(self, fail_if_not_exists=fail_if_not_exists, type=type) + + async def forward( + self, + channel: MessageableChannel, + content: Optional[str] = None, + *, + fail_if_not_exists: bool = True, + **kwargs: Any, + ) -> Message: + """|coro| + + Forwards this message to a channel. + + .. versionadded:: 2.5 + + Parameters + ---------- + channel: :class:`~discord.abc.Messageable` + The channel to forward this message to. + content: Optional[:class:`str`] + The content of the message to send. + fail_if_not_exists: :class:`bool` + Whether replying using the message reference should raise :class:`HTTPException` + if the message no longer exists or Discord could not fetch the message. + \*\*kwargs + Other kwargs to provide to :meth:`~discord.abc.Messageable.send`. + + Raises + ------ + ~discord.HTTPException + Forwarding the message failed. + + Returns + ------- + :class:`.Message` + The message sent to the channel. + """ + reference = self.to_reference( + fail_if_not_exists=fail_if_not_exists, type=MessageReferenceType.forward, + ) + ret = await channel.send(content=content, reference=reference, **kwargs) + return ret def to_message_reference_dict(self) -> MessageReferencePayload: data: MessageReferencePayload = { From 00de465015affec240ff1df35b4bf91041094902 Mon Sep 17 00:00:00 2001 From: Developer Anonymous Date: Sun, 29 Sep 2024 18:48:59 +0200 Subject: [PATCH 23/36] Moved MessageSnapshot to Discord Models --- docs/api.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index fd343ccce9f0..092b734811f3 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -5127,6 +5127,14 @@ PollAnswer .. _discord_api_data: +MessageSnapshot +~~~~~~~~~~~~~~~~~ + +.. attributetable:: MessageSnapshot + +.. autoclass:: MessageSnapshot + :members: + Data Classes -------------- @@ -5166,14 +5174,6 @@ AllowedMentions .. autoclass:: AllowedMentions :members: -MessageSnapshot -~~~~~~~~~~~~~~~~~ - -.. attributetable:: MessageSnapshot - -.. autoclass:: MessageSnapshot - :members: - MessageReference ~~~~~~~~~~~~~~~~~ From f25b1773bb90ea58c53da1d30d3ceff810770bb4 Mon Sep 17 00:00:00 2001 From: Developer Anonymous Date: Sun, 29 Sep 2024 18:58:29 +0200 Subject: [PATCH 24/36] Removed trailing whitespace --- discord/message.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/message.py b/discord/message.py index a7ee5c72ba65..9357ba46ea2e 100644 --- a/discord/message.py +++ b/discord/message.py @@ -630,7 +630,7 @@ def with_state(cls, state: ConnectionState, data: MessageReferencePayload) -> Se @classmethod def from_message( cls, - message: PartialMessage, + message: PartialMessage, *, fail_if_not_exists: bool = True, type: MessageReferenceType = MessageReferenceType.reply, From 893730e834797f8d46abb5d89ad8633d23cc212c Mon Sep 17 00:00:00 2001 From: Developer Anonymous Date: Sun, 29 Sep 2024 19:01:15 +0200 Subject: [PATCH 25/36] Added MessageReferenceType enum --- docs/api.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/api.rst b/docs/api.rst index 092b734811f3..57a10060eca8 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -3663,6 +3663,24 @@ of :class:`enum.Enum`. A burst reaction, also known as a "super reaction". +.. class:: MessageReferenceType + + Represents the type of a message reference. + + .. versionadded:: 2.5 + + .. attribute:: reply + + A message reply. + + .. attribute:: forward + + A forwarded message. + + .. attribute:: default + + An alias for :attr:`.reply`. + .. _discord-api-audit-logs: Audit Log Data From 0f29fb19a7da2b43b321284233324c56d89db8e1 Mon Sep 17 00:00:00 2001 From: Developer Anonymous Date: Sun, 29 Sep 2024 19:06:24 +0200 Subject: [PATCH 26/36] Removed invalid escape sequence and formatted with black --- discord/message.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/discord/message.py b/discord/message.py index 9357ba46ea2e..ced4861a3de1 100644 --- a/discord/message.py +++ b/discord/message.py @@ -1767,7 +1767,7 @@ async def forward( fail_if_not_exists: :class:`bool` Whether replying using the message reference should raise :class:`HTTPException` if the message no longer exists or Discord could not fetch the message. - \*\*kwargs + **kwargs Other kwargs to provide to :meth:`~discord.abc.Messageable.send`. Raises @@ -1781,7 +1781,8 @@ async def forward( The message sent to the channel. """ reference = self.to_reference( - fail_if_not_exists=fail_if_not_exists, type=MessageReferenceType.forward, + fail_if_not_exists=fail_if_not_exists, + type=MessageReferenceType.forward, ) ret = await channel.send(content=content, reference=reference, **kwargs) return ret From 41e0cca7e459c0face3fb6fe0ab630aa99dae85f Mon Sep 17 00:00:00 2001 From: Developer Anonymous Date: Sun, 29 Sep 2024 19:15:00 +0200 Subject: [PATCH 27/36] Added components and stickers to message snapshot --- discord/message.py | 10 ++++++++++ discord/types/message.py | 2 ++ 2 files changed, 12 insertions(+) diff --git a/discord/message.py b/discord/message.py index ced4861a3de1..c872556f72db 100644 --- a/discord/message.py +++ b/discord/message.py @@ -493,6 +493,8 @@ class MessageSnapshot: 'flags', 'created_at', 'type', + 'stickers', + 'components', '_state', ) @@ -515,6 +517,14 @@ def __init__(self, state: ConnectionState, data: MessageSnapshotPayload): self.created_at: datetime.datetime = utils.parse_time(data['timestamp']) self._edited_timestamp: Optional[datetime.datetime] = utils.parse_time(data['edited_timestamp']) self.flags: MessageFlags = MessageFlags._from_value(data.get('flags', 0)) + self.stickers: List[StickerItem] = [StickerItem(data=d, state=state) for d in data.get('stickers_items', [])] + + self.components: List[MessageComponentType] = [] + for component_data in data.get('components', []): + component = _component_factory(component_data) + if component is not None: + self.components.append(component) + self._state: ConnectionState = state def __repr__(self) -> str: diff --git a/discord/types/message.py b/discord/types/message.py index 4e60c58b002e..b3377f652884 100644 --- a/discord/types/message.py +++ b/discord/types/message.py @@ -168,6 +168,8 @@ class MessageSnapshot(TypedDict): flags: NotRequired[int] mentions: List[UserWithMember] mention_roles: SnowflakeList + stickers_items: NotRequired[List[StickerItem]] + components: NotRequired[List[Component]] class Message(PartialMessage): From 7ed85686e5f7000cc93d880597e1882801de167a Mon Sep 17 00:00:00 2001 From: Developer Anonymous Date: Sun, 29 Sep 2024 19:18:59 +0200 Subject: [PATCH 28/36] Added stickers & components to attributes docs --- discord/message.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/discord/message.py b/discord/message.py index c872556f72db..ae126d5c25ba 100644 --- a/discord/message.py +++ b/discord/message.py @@ -480,6 +480,10 @@ class MessageSnapshot: The forwarded message's time of creation. flags: :class:`MessageFlags` Extra features of the the message snapshot. + stickers: List[:class:`StickerItem`] + A list of sticker items given to the message. + components: List[Union[:class:`ActionRow`, :class:`Button`, :class:`SelectMenu`]] + A list of components in the message. """ __slots__ = ( From 46ab67272f867486996c4728a1ede5b4640c3248 Mon Sep 17 00:00:00 2001 From: Developer Anonymous Date: Sun, 29 Sep 2024 22:00:48 +0200 Subject: [PATCH 29/36] Changes - MessageSnapshot.cached_message now returns the correct message - MessageReference.to_dict now passes type for forwards - PartialMessage.forward does not raise errors thanks to the already mentioned fix --- discord/message.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/discord/message.py b/discord/message.py index ae126d5c25ba..d78926b009a2 100644 --- a/discord/message.py +++ b/discord/message.py @@ -488,6 +488,7 @@ class MessageSnapshot: __slots__ = ( '_cs_raw_channel_mentions', + '_cs_cached_message', '_cs_raw_mentions', '_cs_raw_role_mentions', '_edited_timestamp', @@ -559,20 +560,29 @@ def raw_role_mentions(self) -> List[int]: """ return [int(x) for x in re.findall(r'<@&([0-9]{15,20})>', self.content)] + @utils.cached_slot_property('_cs_cached_message') + def cached_message(self) -> Optional[Message]: + """Optional[:class:`Message`]: Returns the cached message this snapshot points to, if any.""" + state = self._state + return utils.find( + lambda m: ( + m.created_at == self.created_at and + m.edited_at == self.edited_at and + m.content == self.content and + m.embeds == self.embeds and + m.components == self.components and + m.stickers == self.stickers and + m.attachments == self.attachments and + m.flags == self.flags + ), + reversed(state._messages) + ) if state._messages else None + @property def edited_at(self) -> Optional[datetime.datetime]: """Optional[:class:`datetime.datetime`]: An aware UTC datetime object containing the edited time of the forwarded message.""" return self._edited_timestamp - @property - def cached_message(self) -> Optional[Message]: - """Optional[:class:`Message`]: The resolved message object this snapshot points to, - if cached. - """ - # We do this trick as ID is not provided. - id = int(self.created_at.timestamp()) - utils.DISCORD_EPOCH - return self._state._get_message(id) - class MessageReference: """Represents a reference to a :class:`~discord.Message`. @@ -586,6 +596,8 @@ class MessageReference: ----------- type: :class:`MessageReferenceType` The type of message reference. + + .. versionadded:: 2.5 message_id: Optional[:class:`int`] The id of the message referenced. channel_id: :class:`int` @@ -700,7 +712,7 @@ def __repr__(self) -> str: return f'' def to_dict(self) -> MessageReferencePayload: - result: Dict[str, Any] = {'message_id': self.message_id} if self.message_id is not None else {} + result: Dict[str, Any] = {'type': self.type.value, 'message_id': self.message_id} if self.message_id is not None else {} result['channel_id'] = self.channel_id if self.guild_id is not None: result['guild_id'] = self.guild_id @@ -1749,6 +1761,10 @@ def to_reference( if the message no longer exists or Discord could not fetch the message. .. versionadded:: 1.7 + type: :class:`MessageReferenceType` + The type of message reference. + + .. versionadded:: 2.5 Returns --------- From 2f9940f76dad601d373311372c2baff3055b4ee8 Mon Sep 17 00:00:00 2001 From: Developer Anonymous Date: Sun, 29 Sep 2024 22:02:24 +0200 Subject: [PATCH 30/36] Run black --- discord/message.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/discord/message.py b/discord/message.py index d78926b009a2..9e082a7a10c5 100644 --- a/discord/message.py +++ b/discord/message.py @@ -564,19 +564,23 @@ def raw_role_mentions(self) -> List[int]: def cached_message(self) -> Optional[Message]: """Optional[:class:`Message`]: Returns the cached message this snapshot points to, if any.""" state = self._state - return utils.find( - lambda m: ( - m.created_at == self.created_at and - m.edited_at == self.edited_at and - m.content == self.content and - m.embeds == self.embeds and - m.components == self.components and - m.stickers == self.stickers and - m.attachments == self.attachments and - m.flags == self.flags - ), - reversed(state._messages) - ) if state._messages else None + return ( + utils.find( + lambda m: ( + m.created_at == self.created_at + and m.edited_at == self.edited_at + and m.content == self.content + and m.embeds == self.embeds + and m.components == self.components + and m.stickers == self.stickers + and m.attachments == self.attachments + and m.flags == self.flags + ), + reversed(state._messages), + ) + if state._messages + else None + ) @property def edited_at(self) -> Optional[datetime.datetime]: @@ -712,7 +716,9 @@ def __repr__(self) -> str: return f'' def to_dict(self) -> MessageReferencePayload: - result: Dict[str, Any] = {'type': self.type.value, 'message_id': self.message_id} if self.message_id is not None else {} + result: Dict[str, Any] = ( + {'type': self.type.value, 'message_id': self.message_id} if self.message_id is not None else {} + ) result['channel_id'] = self.channel_id if self.guild_id is not None: result['guild_id'] = self.guild_id From 17ab276453ee3661544741e1253df0fa0d74fd0f Mon Sep 17 00:00:00 2001 From: DA344 <108473820+DA-344@users.noreply.github.com> Date: Sun, 29 Sep 2024 23:45:53 +0200 Subject: [PATCH 31/36] Update PartialMessage.forward --- discord/message.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/discord/message.py b/discord/message.py index 9e082a7a10c5..f5804fbe4222 100644 --- a/discord/message.py +++ b/discord/message.py @@ -1782,11 +1782,9 @@ def to_reference( async def forward( self, - channel: MessageableChannel, - content: Optional[str] = None, + destination: MessageableChannel, *, fail_if_not_exists: bool = True, - **kwargs: Any, ) -> Message: """|coro| @@ -1796,15 +1794,11 @@ async def forward( Parameters ---------- - channel: :class:`~discord.abc.Messageable` + destination: :class:`~discord.abc.Messageable` The channel to forward this message to. - content: Optional[:class:`str`] - The content of the message to send. fail_if_not_exists: :class:`bool` Whether replying using the message reference should raise :class:`HTTPException` if the message no longer exists or Discord could not fetch the message. - **kwargs - Other kwargs to provide to :meth:`~discord.abc.Messageable.send`. Raises ------ @@ -1820,7 +1814,7 @@ async def forward( fail_if_not_exists=fail_if_not_exists, type=MessageReferenceType.forward, ) - ret = await channel.send(content=content, reference=reference, **kwargs) + ret = await destination.send(reference=reference) return ret def to_message_reference_dict(self) -> MessageReferencePayload: From 081d4f76111242989ec394c598cc8f3adc7e0bfa Mon Sep 17 00:00:00 2001 From: Developer Anonymous Date: Mon, 30 Sep 2024 16:12:42 +0200 Subject: [PATCH 32/36] Added missing versionadded --- discord/message.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discord/message.py b/discord/message.py index f5804fbe4222..bb7f44f3b51d 100644 --- a/discord/message.py +++ b/discord/message.py @@ -1973,6 +1973,8 @@ class Message(PartialMessage, Hashable): .. versionadded:: 2.4 message_snapshots: Optional[List[:class:`MessageSnapshot`]] The message snapshots attached to this message. + + .. versionadded:: 2.5 """ __slots__ = ( From 4fdc1ae592521fe0d8a92a3bde9383cb85dd35d0 Mon Sep 17 00:00:00 2001 From: DA-344 <108473820+DA-344@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:13:00 +0200 Subject: [PATCH 33/36] Update Message.message_snapshots --- discord/message.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/discord/message.py b/discord/message.py index bb7f44f3b51d..249db599f90b 100644 --- a/discord/message.py +++ b/discord/message.py @@ -508,11 +508,11 @@ def _from_value( cls, state: ConnectionState, message_snapshots: Optional[List[Dict[Literal['message'], MessageSnapshotPayload]]], - ): + ) -> List[Self]: if not message_snapshots: - return None + return [] - return [MessageSnapshot(state, snapshot['message']) for snapshot in message_snapshots] + return [cls(state, snapshot['message']) for snapshot in message_snapshots] def __init__(self, state: ConnectionState, data: MessageSnapshotPayload): self.type: MessageType = try_enum(MessageType, data['type']) @@ -1971,7 +1971,7 @@ class Message(PartialMessage, Hashable): The poll attached to this message. .. versionadded:: 2.4 - message_snapshots: Optional[List[:class:`MessageSnapshot`]] + message_snapshots: List[:class:`MessageSnapshot`] The message snapshots attached to this message. .. versionadded:: 2.5 @@ -2050,7 +2050,7 @@ def __init__( self.position: Optional[int] = data.get('position') self.application_id: Optional[int] = utils._get_as_snowflake(data, 'application_id') self.stickers: List[StickerItem] = [StickerItem(data=d, state=state) for d in data.get('sticker_items', [])] - self.message_snapshots: Optional[List[MessageSnapshot]] = MessageSnapshot._from_value( + self.message_snapshots: List[MessageSnapshot] = MessageSnapshot._from_value( state, data.get('message_snapshots') ) From 06a1abf24c75b85c0231ad3f8a0f19418e1e7f24 Mon Sep 17 00:00:00 2001 From: DA344 <108473820+DA-344@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:14:36 +0200 Subject: [PATCH 34/36] Update discord/enums.py Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com> --- discord/enums.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/discord/enums.py b/discord/enums.py index 0e85b3586669..df1741ca276f 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -219,11 +219,10 @@ def __str__(self) -> str: class MessageReferenceType(Enum): + default = 0 reply = 0 forward = 1 - default = 0 - class MessageType(Enum): default = 0 From 340f74ae4aec6f8007c90b37fbe3e017979934b2 Mon Sep 17 00:00:00 2001 From: DA-344 <108473820+DA-344@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:21:33 +0200 Subject: [PATCH 35/36] Run black --- discord/message.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/discord/message.py b/discord/message.py index fc8b1cb1b147..b5e04b11d0e0 100644 --- a/discord/message.py +++ b/discord/message.py @@ -2104,9 +2104,7 @@ def __init__( self.position: Optional[int] = data.get('position') self.application_id: Optional[int] = utils._get_as_snowflake(data, 'application_id') self.stickers: List[StickerItem] = [StickerItem(data=d, state=state) for d in data.get('sticker_items', [])] - self.message_snapshots: List[MessageSnapshot] = MessageSnapshot._from_value( - state, data.get('message_snapshots') - ) + self.message_snapshots: List[MessageSnapshot] = MessageSnapshot._from_value(state, data.get('message_snapshots')) self.poll: Optional[Poll] = None try: From 12c494d754c911c9c46863574b1988f4b0e3305f Mon Sep 17 00:00:00 2001 From: DA344 <108473820+DA-344@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:31:28 +0200 Subject: [PATCH 36/36] Remove README changes --- README.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.rst b/README.rst index cc2c56aefa57..621a69500291 100644 --- a/README.rst +++ b/README.rst @@ -11,9 +11,6 @@ discord.py :target: https://pypi.python.org/pypi/discord.py :alt: PyPI supported Python versions -Please, donnot use this fork's master branch, it is... not for usage, use the different branches that implement other functions, such as recurrent events or member safety information. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. Key Features