From 205514e3cdd625fa244bc0ad4c8f91854cb65a34 Mon Sep 17 00:00:00 2001 From: Om Date: Sat, 24 Jun 2023 00:46:53 +0530 Subject: [PATCH 1/6] add undocmented parameters --- discord/interactions.py | 22 ++++++++++++++++++++++ discord/webhook/async_.py | 14 +++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/discord/interactions.py b/discord/interactions.py index 4a74edf201..4d02065f7a 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -33,6 +33,7 @@ from .enums import InteractionResponseType, InteractionType, try_enum from .errors import ClientException, InteractionResponded, InvalidArgument from .file import File +from .flags import MessageFlags from .member import Member from .message import Attachment, Message from .object import Object @@ -386,6 +387,7 @@ async def edit_original_response( view: View | None = MISSING, allowed_mentions: AllowedMentions | None = None, delete_after: float | None = None, + suppress: bool = False, ) -> InteractionMessage: """|coro| @@ -453,6 +455,7 @@ async def edit_original_response( view=view, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, + suppress=suppress, ) adapter = async_context.get() http = self._state.http @@ -936,6 +939,8 @@ async def edit_message( attachments: list[Attachment] = MISSING, view: View | None = MISSING, delete_after: float | None = None, + suppress: bool = False, + allowed_mentions: AllowedMentions | None = None, ) -> None: """|coro| @@ -1029,6 +1034,21 @@ async def edit_message( # we keep previous attachments when adding new files payload["attachments"] = [a.to_dict() for a in msg.attachments] + if suppress is not MISSING: + payload["flags"] = MessageFlags(suppress_embeds=suppress).value + + if allowed_mentions is None: + payload["allowed_mentions"] = ( + state.allowed_mentions and state.allowed_mentions.to_dict() + ) + + elif state.allowed_mentions is not None: + payload["allowed_mentions"] = state.allowed_mentions.merge( + allowed_mentions + ).to_dict() + else: + payload["allowed_mentions"] = allowed_mentions.to_dict() + adapter = async_context.get() http = parent._state.http try: @@ -1215,6 +1235,7 @@ async def edit( view: View | None = MISSING, allowed_mentions: AllowedMentions | None = None, delete_after: float | None = None, + suppress: bool = False, ) -> InteractionMessage: """|coro| @@ -1276,6 +1297,7 @@ async def edit( view=view, allowed_mentions=allowed_mentions, delete_after=delete_after, + suppress=suppress, ) async def delete(self, *, delay: float | None = None) -> None: diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index f7d98f80a9..ceb9ac6839 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -53,6 +53,7 @@ from ..object import Object from ..threads import Thread from ..user import BaseUser, User +from ..flags import MessageFlags __all__ = ( "Webhook", @@ -622,6 +623,7 @@ def handle_message_parameters( view: View | None = MISSING, allowed_mentions: AllowedMentions | None = MISSING, previous_allowed_mentions: AllowedMentions | None = None, + suppress: bool = MISSING, ) -> ExecuteWebhookParameters: if files is not MISSING and file is not MISSING: raise TypeError("Cannot mix file and files keyword arguments.") @@ -648,8 +650,16 @@ def handle_message_parameters( payload["avatar_url"] = str(avatar_url) if username: payload["username"] = username + + flags = MessageFlags._from_value(0) + if ephemeral: - payload["flags"] = 64 + flags.ephemeral = True + payload["flags"] = flags.value + + if suppress is not MISSING: + flags.suppress_embeds = suppress + payload["flags"] = flags.value if allowed_mentions: if previous_allowed_mentions is not None: @@ -1845,6 +1855,7 @@ async def edit_message( view: View | None = MISSING, allowed_mentions: AllowedMentions | None = None, thread: Snowflake | None = MISSING, + suppress: bool = MISSING, ) -> WebhookMessage: """|coro| @@ -1939,6 +1950,7 @@ async def edit_message( view=view, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, + suppress=suppress, ) thread_id: int | None = None From 29284a797cedd9d142b06d4392f9c3cb24af5fe2 Mon Sep 17 00:00:00 2001 From: Om Date: Sat, 24 Jun 2023 01:31:17 +0530 Subject: [PATCH 2/6] docs and improved logic --- discord/interactions.py | 23 ++++++++++++++++++++--- discord/webhook/async_.py | 27 +++++++++++++++------------ discord/webhook/sync.py | 14 ++++++++++++++ 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/discord/interactions.py b/discord/interactions.py index 4d02065f7a..83ca14f128 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -426,6 +426,8 @@ async def edit_original_response( If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored. + suppress: :class:`bool` + Whether to suppress embeds for the message. Returns ------- @@ -939,7 +941,7 @@ async def edit_message( attachments: list[Attachment] = MISSING, view: View | None = MISSING, delete_after: float | None = None, - suppress: bool = False, + suppress: bool | None = MISSING, allowed_mentions: AllowedMentions | None = None, ) -> None: """|coro| @@ -971,6 +973,15 @@ async def edit_message( If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored. + suppress: Optional[:class:`bool`] + Whether to suppress embeds for the message. + allowed_mentions: Optional[:class:`~discord.AllowedMentions`] + Controls the mentions being processed in this message. If this is + passed, then the object is merged with :attr:`~discord.Client.allowed_mentions`. + The merging behaviour only overrides attributes that have been explicitly passed + to the object, otherwise it uses the attributes set in :attr:`~discord.Client.allowed_mentions`. + If no object is passed at all then the defaults given by :attr:`~discord.Client.allowed_mentions` + are used instead. Raises ------ @@ -1035,7 +1046,9 @@ async def edit_message( payload["attachments"] = [a.to_dict() for a in msg.attachments] if suppress is not MISSING: - payload["flags"] = MessageFlags(suppress_embeds=suppress).value + flags = MessageFlags._from_value(self._parent.message.flags.value) + flags.suppress_embeds = suppress + payload["flags"] = flags.value if allowed_mentions is None: payload["allowed_mentions"] = ( @@ -1235,7 +1248,7 @@ async def edit( view: View | None = MISSING, allowed_mentions: AllowedMentions | None = None, delete_after: float | None = None, - suppress: bool = False, + suppress: bool | None = MISSING, ) -> InteractionMessage: """|coro| @@ -1268,6 +1281,8 @@ async def edit( If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored. + suppress: Optional[:class:`bool`] + Whether to suppress embeds for the message. Returns ------- @@ -1287,6 +1302,8 @@ async def edit( """ if attachments is MISSING: attachments = self.attachments or MISSING + if suppress is MISSING: + suppress = self.flags.suppress_embeds return await self._state._interaction.edit_original_response( content=content, embeds=embeds, diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index ceb9ac6839..2a8140f8bc 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -623,7 +623,7 @@ def handle_message_parameters( view: View | None = MISSING, allowed_mentions: AllowedMentions | None = MISSING, previous_allowed_mentions: AllowedMentions | None = None, - suppress: bool = MISSING, + suppress: bool = False, ) -> ExecuteWebhookParameters: if files is not MISSING and file is not MISSING: raise TypeError("Cannot mix file and files keyword arguments.") @@ -650,16 +650,10 @@ def handle_message_parameters( payload["avatar_url"] = str(avatar_url) if username: payload["username"] = username - - flags = MessageFlags._from_value(0) - - if ephemeral: - flags.ephemeral = True - payload["flags"] = flags.value - - if suppress is not MISSING: - flags.suppress_embeds = suppress - payload["flags"] = flags.value + + flags = MessageFlags(suppress_embeds=suppress, ephemeral=ephemeral) + + payload["flags"] = flags.value if allowed_mentions: if previous_allowed_mentions is not None: @@ -837,6 +831,7 @@ async def edit( attachments: list[Attachment] = MISSING, view: View | None = MISSING, allowed_mentions: AllowedMentions | None = None, + suppress: bool | None = MISSING, ) -> WebhookMessage: """|coro| @@ -878,6 +873,8 @@ async def edit( the view is removed. .. versionadded:: 2.0 + suppress: Optional[:class:`bool`] + Whether to suppress embeds for the message. Returns ------- @@ -908,6 +905,9 @@ async def edit( if attachments is MISSING: attachments = self.attachments or MISSING + if suppress is MISSING: + suppress = self.flags.suppress_embeds + return await self._state._webhook.edit_message( self.id, content=content, @@ -919,6 +919,7 @@ async def edit( view=view, allowed_mentions=allowed_mentions, thread=thread, + suppress=suppress, ) async def delete(self, *, delay: float | None = None) -> None: @@ -1855,7 +1856,7 @@ async def edit_message( view: View | None = MISSING, allowed_mentions: AllowedMentions | None = None, thread: Snowflake | None = MISSING, - suppress: bool = MISSING, + suppress: bool = False, ) -> WebhookMessage: """|coro| @@ -1903,6 +1904,8 @@ async def edit_message( .. versionadded:: 2.0 thread: Optional[:class:`~discord.abc.Snowflake`] The thread that contains the message. + suppress: :class:`bool` + Whether to suppress embeds for the message. Returns ------- diff --git a/discord/webhook/sync.py b/discord/webhook/sync.py index 042130ac25..9e812b5709 100644 --- a/discord/webhook/sync.py +++ b/discord/webhook/sync.py @@ -472,6 +472,7 @@ def edit( file: File = MISSING, files: list[File] = MISSING, allowed_mentions: AllowedMentions | None = None, + suppress: bool | None = MISSING, ) -> SyncWebhookMessage: """Edits the message. @@ -492,6 +493,8 @@ def edit( allowed_mentions: :class:`AllowedMentions` Controls the mentions being processed in this message. See :meth:`.abc.Messageable.send` for more information. + suppress: Optional[:class:`bool`] + Whether to suppress embeds for the message. Returns ------- @@ -517,6 +520,9 @@ def edit( elif isinstance(self.channel, Thread): thread = Object(self.channel.id) + if suppress is MISSING: + suppress = self.flags.suppress_embeds + return self._state._webhook.edit_message( self.id, content=content, @@ -526,6 +532,7 @@ def edit( files=files, allowed_mentions=allowed_mentions, thread=thread, + suppress=suppress, ) def delete(self, *, delay: float | None = None) -> None: @@ -952,6 +959,7 @@ def send( thread: Snowflake = MISSING, thread_name: str | None = None, wait: Literal[False] = ..., + suppress: bool = MISSING, ) -> None: ... @@ -970,6 +978,7 @@ def send( thread: Snowflake = MISSING, thread_name: str | None = None, wait: bool = False, + suppress: bool = False, ) -> SyncWebhookMessage | None: """Sends a message using the webhook. @@ -1022,6 +1031,8 @@ def send( The name of the thread to create. Only works for forum channels. .. versionadded:: 2.0 + suppress: :class:`bool` + Whether to suppress embeds for the message. Returns ------- @@ -1070,6 +1081,7 @@ def send( embeds=embeds, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, + suppress=suppress, ) adapter: WebhookAdapter = _get_webhook_adapter() thread_id: int | None = None @@ -1151,6 +1163,7 @@ def edit_message( files: list[File] = MISSING, allowed_mentions: AllowedMentions | None = None, thread: Snowflake | None = MISSING, + suppress: bool = False, ) -> SyncWebhookMessage: """Edits a message owned by this webhook. @@ -1211,6 +1224,7 @@ def edit_message( embeds=embeds, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, + suppress=suppress, ) adapter: WebhookAdapter = _get_webhook_adapter() From 04f6328c43d849709a40e2eb09d27d8c00c4faf5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 23 Jun 2023 20:37:00 +0000 Subject: [PATCH 3/6] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/webhook/async_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index 2a8140f8bc..ef3849a86f 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -47,13 +47,13 @@ InvalidArgument, NotFound, ) +from ..flags import MessageFlags from ..http import Route from ..message import Attachment, Message from ..mixins import Hashable from ..object import Object from ..threads import Thread from ..user import BaseUser, User -from ..flags import MessageFlags __all__ = ( "Webhook", From 5b54db60cf9dd50b158c493d5791c375c1daa483 Mon Sep 17 00:00:00 2001 From: Om Date: Sat, 24 Jun 2023 03:04:29 +0530 Subject: [PATCH 4/6] Changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb7bb88942..31d99654a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2106](https://github.com/Pycord-Development/pycord/pull/2106)) - Added Annotated forms support for typehinting slash command options. ([#2124](https://github.com/Pycord-Development/pycord/pull/2124)) +- Added `suppress` and `allowed_mentions` parameters to `Webhook` and `InteractionResponse` edit methods. + ([#2138](https://github.com/Pycord-Development/pycord/pull/2138)) ### Changed From 2f79ceeea6768bf388468dc2f8b9a067aa3270b2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 23 Jun 2023 21:34:53 +0000 Subject: [PATCH 5/6] style(pre-commit): auto fixes from pre-commit.com hooks --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31d99654a9..7e42278642 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,7 +68,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2106](https://github.com/Pycord-Development/pycord/pull/2106)) - Added Annotated forms support for typehinting slash command options. ([#2124](https://github.com/Pycord-Development/pycord/pull/2124)) -- Added `suppress` and `allowed_mentions` parameters to `Webhook` and `InteractionResponse` edit methods. +- Added `suppress` and `allowed_mentions` parameters to `Webhook` and + `InteractionResponse` edit methods. ([#2138](https://github.com/Pycord-Development/pycord/pull/2138)) ### Changed From a207f987b5718e5a089b2ccec6d79e9aa18acae1 Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Sat, 24 Jun 2023 19:29:52 +0300 Subject: [PATCH 6/6] Remove unnecessary empty line Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- discord/webhook/async_.py | 1 - 1 file changed, 1 deletion(-) diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index ef3849a86f..3a98c4baca 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -652,7 +652,6 @@ def handle_message_parameters( payload["username"] = username flags = MessageFlags(suppress_embeds=suppress, ephemeral=ephemeral) - payload["flags"] = flags.value if allowed_mentions: