From 526a3cab23116898bdd4b674cd248b447619ab76 Mon Sep 17 00:00:00 2001 From: retr0init Date: Sat, 27 Jul 2024 22:07:36 +0100 Subject: [PATCH 1/5] feat: add `thread_name` field in the webhook field --- interactions/api/http/http_requests/webhooks.py | 6 +++++- interactions/models/discord/webhooks.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/interactions/api/http/http_requests/webhooks.py b/interactions/api/http/http_requests/webhooks.py index f5b372c1c..97ffed4e6 100644 --- a/interactions/api/http/http_requests/webhooks.py +++ b/interactions/api/http/http_requests/webhooks.py @@ -126,6 +126,7 @@ async def execute_webhook( payload: dict, wait: bool = False, thread_id: "Snowflake_Type" = None, + thread_name: Optional[str] = None, files: list["UPLOADABLE_TYPE"] | None = None, ) -> Optional[discord_typings.MessageData]: """ @@ -136,13 +137,16 @@ async def execute_webhook( webhook_token: The token for the webhook payload: The JSON payload for the message wait: Waits for server confirmation of message send before response - thread_id: Send a message to the specified thread + thread_id: Send a message to the specified thread. Note that this cannot be used with `thread_name` + thread_name: Create a thread with this name. Note that this cannot be used with `thread_id` files: The files to send with this message Returns: The sent `message`, if `wait` is True else None """ + if thread_name is not None: + payload["thread_name"] = thread_name return await self.request( Route("POST", "/webhooks/{webhook_id}/{webhook_token}", webhook_id=webhook_id, webhook_token=webhook_token), params=dict_filter_none({"wait": "true" if wait else "false", "thread_id": thread_id}), diff --git a/interactions/models/discord/webhooks.py b/interactions/models/discord/webhooks.py index 548eaec9f..7e00a4a97 100644 --- a/interactions/models/discord/webhooks.py +++ b/interactions/models/discord/webhooks.py @@ -196,6 +196,7 @@ async def send( avatar_url: str | None = None, wait: bool = False, thread: "Snowflake_Type" = None, + thread_name: Optional[str] = None **kwargs, ) -> Optional["Message"]: """ @@ -218,7 +219,8 @@ async def send( username: The username to use avatar_url: The url of an image to use as the avatar wait: Waits for confirmation of delivery. Set this to True if you intend to edit the message - thread: Send this webhook to a thread channel + thread: Send this webhook to a thread channel. Note that this cannot be used with `thread_name` set + thread_name: Create a thread with `thread_name` with this webhook. Note that this cannot be used with `thread` set Returns: New message object that was sent if `wait` is set to True @@ -256,6 +258,7 @@ async def send( message_payload, wait, to_optional_snowflake(thread), + thread_name, files=files or file, ) if message_data: From bd0263e095da9ba030bd7c157d9d33523d963d31 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 27 Jul 2024 21:15:19 +0000 Subject: [PATCH 2/5] ci: correct from checks. --- interactions/models/discord/webhooks.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/interactions/models/discord/webhooks.py b/interactions/models/discord/webhooks.py index 7e00a4a97..214f4e64e 100644 --- a/interactions/models/discord/webhooks.py +++ b/interactions/models/discord/webhooks.py @@ -196,8 +196,7 @@ async def send( avatar_url: str | None = None, wait: bool = False, thread: "Snowflake_Type" = None, - thread_name: Optional[str] = None - **kwargs, + thread_name: Optional[str] = None**kwargs, ) -> Optional["Message"]: """ Send a message as this webhook. From 6b0b8e22c3a2db9685c2baf7a7e1e645360fe0d4 Mon Sep 17 00:00:00 2001 From: retr0init Date: Sat, 27 Jul 2024 22:21:09 +0100 Subject: [PATCH 3/5] fixed: Add a missing comma --- interactions/models/discord/webhooks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interactions/models/discord/webhooks.py b/interactions/models/discord/webhooks.py index 214f4e64e..1e7f24831 100644 --- a/interactions/models/discord/webhooks.py +++ b/interactions/models/discord/webhooks.py @@ -196,7 +196,8 @@ async def send( avatar_url: str | None = None, wait: bool = False, thread: "Snowflake_Type" = None, - thread_name: Optional[str] = None**kwargs, + thread_name: Optional[str] = None, + **kwargs, ) -> Optional["Message"]: """ Send a message as this webhook. From 191d97e5cda884c4bda6d1fa4b5e092cb1d7cc9f Mon Sep 17 00:00:00 2001 From: retr0init Date: Sat, 27 Jul 2024 23:00:36 +0100 Subject: [PATCH 4/5] feat: check exclusive relationship between `thread` and `thread_name` --- interactions/api/http/http_requests/webhooks.py | 2 +- interactions/models/discord/webhooks.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/interactions/api/http/http_requests/webhooks.py b/interactions/api/http/http_requests/webhooks.py index 97ffed4e6..1aa098a3b 100644 --- a/interactions/api/http/http_requests/webhooks.py +++ b/interactions/api/http/http_requests/webhooks.py @@ -138,7 +138,7 @@ async def execute_webhook( payload: The JSON payload for the message wait: Waits for server confirmation of message send before response thread_id: Send a message to the specified thread. Note that this cannot be used with `thread_name` - thread_name: Create a thread with this name. Note that this cannot be used with `thread_id` + thread_name: Create a thread with this name. Note that this is only valid for forum channel and cannot be used with `thread_id` files: The files to send with this message Returns: diff --git a/interactions/models/discord/webhooks.py b/interactions/models/discord/webhooks.py index 1e7f24831..c96f98bee 100644 --- a/interactions/models/discord/webhooks.py +++ b/interactions/models/discord/webhooks.py @@ -220,7 +220,7 @@ async def send( avatar_url: The url of an image to use as the avatar wait: Waits for confirmation of delivery. Set this to True if you intend to edit the message thread: Send this webhook to a thread channel. Note that this cannot be used with `thread_name` set - thread_name: Create a thread with `thread_name` with this webhook. Note that this cannot be used with `thread` set + thread_name: Create a thread with `thread_name` with this webhook. Note that this is only valid for forum channel and cannot be used with `thread` set Returns: New message object that was sent if `wait` is set to True @@ -231,6 +231,9 @@ async def send( if not content and not embeds and not embed and not files and not file and not stickers: raise EmptyMessageException("You cannot send a message without any content, embeds, files, or stickers") + + if thread is not None and thread_name is not None: + raise ValueError("You cannot create a thread and send the message to another thread with a webhook at the same time!") if suppress_embeds: if isinstance(flags, int): From 6a610161f3e0a0da47f25969fd1cea87c01e7605 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 27 Jul 2024 22:01:00 +0000 Subject: [PATCH 5/5] ci: correct from checks. --- interactions/models/discord/webhooks.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interactions/models/discord/webhooks.py b/interactions/models/discord/webhooks.py index c96f98bee..96a614b94 100644 --- a/interactions/models/discord/webhooks.py +++ b/interactions/models/discord/webhooks.py @@ -231,9 +231,11 @@ async def send( if not content and not embeds and not embed and not files and not file and not stickers: raise EmptyMessageException("You cannot send a message without any content, embeds, files, or stickers") - + if thread is not None and thread_name is not None: - raise ValueError("You cannot create a thread and send the message to another thread with a webhook at the same time!") + raise ValueError( + "You cannot create a thread and send the message to another thread with a webhook at the same time!" + ) if suppress_embeds: if isinstance(flags, int):