From ff1eb2e6f2db4524b8fec75d9371626cb21d1135 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:04:01 +0200 Subject: [PATCH 01/12] add: getWebhookMessage --- src/helpers/webhooks/get_webhook_message.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/helpers/webhooks/get_webhook_message.ts diff --git a/src/helpers/webhooks/get_webhook_message.ts b/src/helpers/webhooks/get_webhook_message.ts new file mode 100644 index 000000000..eddee7609 --- /dev/null +++ b/src/helpers/webhooks/get_webhook_message.ts @@ -0,0 +1,18 @@ +import { rest } from "../../rest/rest.ts"; +import { structures } from "../../structures/mod.ts"; +import { Message } from "../../types/messages/message.ts"; +import { endpoints } from "../../util/constants.ts"; + +/** Returns a previousy-sent webhook message from the same token. Returns a message object on success. */ +export async function getWebhookMessage( + webhookId: bigint, + webhookToken: string, + messageId: bigint, +) { + const result = await rest.runMethod( + "get", + endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId), + ); + + return await structures.createDiscordenoMessage(result); +} From dd8baf93f5672b754809566d72a4723e21d85f6c Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:06:32 +0200 Subject: [PATCH 02/12] add: getOriginalinteractionResponse --- .../commands/get_original_interaction_response.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/helpers/commands/get_original_interaction_response.ts diff --git a/src/helpers/commands/get_original_interaction_response.ts b/src/helpers/commands/get_original_interaction_response.ts new file mode 100644 index 000000000..b6009c94f --- /dev/null +++ b/src/helpers/commands/get_original_interaction_response.ts @@ -0,0 +1,15 @@ +import { applicationId } from "../../bot.ts"; +import { rest } from "../../rest/rest.ts"; +import { structures } from "../../structures/mod.ts"; +import type { Message } from "../../types/messages/message.ts"; +import { endpoints } from "../../util/constants.ts"; + +/** Returns the initial Interactio response. Functions the same as Get Webhook Message */ +export async function getOriginalInteractionResponse(token: string) { + const result = await rest.runMethod( + "get", + endpoints.INTERACTION_ORIGINAL_ID_TOKEN(applicationId, token), + ); + + return await structures.createDiscordenoMessage(result); +} From 38b8ea5532f5995b969f92e4a2ee6f7ca11820cf Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:06:40 +0200 Subject: [PATCH 03/12] fix: imports use type --- src/helpers/webhooks/get_webhook_message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/webhooks/get_webhook_message.ts b/src/helpers/webhooks/get_webhook_message.ts index eddee7609..d59fc02a7 100644 --- a/src/helpers/webhooks/get_webhook_message.ts +++ b/src/helpers/webhooks/get_webhook_message.ts @@ -1,6 +1,6 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; -import { Message } from "../../types/messages/message.ts"; +import type { Message } from "../../types/messages/message.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns a previousy-sent webhook message from the same token. Returns a message object on success. */ From 09d6177b5fa2e3979ee67df1d4536e21750b5340 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:07:43 +0200 Subject: [PATCH 04/12] add: new handlers mod export --- src/helpers/mod.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 6d0aea748..903614119 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -19,6 +19,7 @@ import { deleteSlashCommand } from "./commands/delete_slash_command.ts"; import { deleteSlashResponse } from "./commands/delete_slash_response.ts"; import { editSlashCommandPermissions } from "./commands/edit_slash_command_permissions.ts"; import { editSlashResponse } from "./commands/edit_slash_response.ts"; +import { getOriginalInteractionResponse } from "./commands/get_original_interaction_response.ts"; import { getSlashCommand } from "./commands/get_slash_command.ts"; import { getSlashCommands } from "./commands/get_slash_commands.ts"; import { getSlashCommandPermission } from "./commands/get_slash_command_permission.ts"; @@ -111,6 +112,9 @@ import { editGuildTemplate } from "./templates/edit_guild_template.ts"; import { getGuildTemplates } from "./templates/get_guild_templates.ts"; import { getTemplate } from "./templates/get_template.ts"; import { syncGuildTemplate } from "./templates/sync_guild_template.ts"; +// Type Guards +import { isActionRow } from "./type_guards/is_action_row.ts"; +import { isButton } from "./type_guards/is_button.ts"; import { createWebhook } from "./webhooks/create_webhook.ts"; import { deleteWebhook } from "./webhooks/delete_webhook.ts"; import { deleteWebhookMessage } from "./webhooks/delete_webhook_message.ts"; @@ -118,13 +122,11 @@ import { deleteWebhookWithToken } from "./webhooks/delete_webhook_with_token.ts" import { editWebhook } from "./webhooks/edit_webhook.ts"; import { editWebhookMessage } from "./webhooks/edit_webhook_message.ts"; import { editWebhookWithToken } from "./webhooks/edit_webhook_with_token.ts"; -import { sendWebhook } from "./webhooks/send_webhook.ts"; import { getWebhook } from "./webhooks/get_webhook.ts"; import { getWebhooks } from "./webhooks/get_webhooks.ts"; +import { getWebhookMessage } from "./webhooks/get_webhook_message.ts"; import { getWebhookWithToken } from "./webhooks/get_webhook_with_token.ts"; -// Type Guards -import { isActionRow } from "./type_guards/is_action_row.ts"; -import { isButton } from "./type_guards/is_button.ts"; +import { sendWebhook } from "./webhooks/send_webhook.ts"; export { addDiscoverySubcategory, @@ -205,6 +207,7 @@ export { getMembers, getMessage, getMessages, + getOriginalInteractionResponse, getPins, getPruneCount, getReactions, @@ -218,6 +221,7 @@ export { getVanityURL, getVoiceRegions, getWebhook, + getWebhookMessage, getWebhooks, getWebhookWithToken, getWelcomeScreen, @@ -289,6 +293,7 @@ export let helpers = { getSlashCommands, upsertSlashCommand, upsertSlashCommands, + getOriginalInteractionResponse, // emojis createEmoji, deleteEmoji, @@ -396,6 +401,7 @@ export let helpers = { getWebhookWithToken, getWebhook, getWebhooks, + getWebhookMessage, }; export type Helpers = typeof helpers; From b0ea2549ad42ba0b13017c1976f158972f7c8052 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:12:04 +0200 Subject: [PATCH 05/12] getinvites add options --- src/helpers/invites/get_invite.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/helpers/invites/get_invite.ts b/src/helpers/invites/get_invite.ts index f0781e927..12772f327 100644 --- a/src/helpers/invites/get_invite.ts +++ b/src/helpers/invites/get_invite.ts @@ -1,11 +1,14 @@ import { rest } from "../../rest/rest.ts"; +import { GetInvite } from "../../types/invites/get_invite.ts"; import type { Invite } from "../../types/invites/invite.ts"; import { endpoints } from "../../util/constants.ts"; +import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Returns an invite for the given code or throws an error if the invite doesn't exists. */ -export async function getInvite(inviteCode: string) { +export async function getInvite(inviteCode: string, options: GetInvite) { return await rest.runMethod( "get", endpoints.INVITE(inviteCode), + camelKeysToSnakeCase(options), ); } From 2d25f275a9cfc94f01fd62d02a8f0b0e405291bc Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:20:14 +0200 Subject: [PATCH 06/12] nonce has been removed --- src/types/messages/create_message.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/types/messages/create_message.ts b/src/types/messages/create_message.ts index fa1704f90..c59ef410f 100644 --- a/src/types/messages/create_message.ts +++ b/src/types/messages/create_message.ts @@ -8,13 +8,11 @@ import { MessageComponents } from "./components/message_components.ts"; export interface CreateMessage { /** The message contents (up to 2000 characters) */ content?: string; - /** A nonce that can be used for optimistic message sending */ - nonce?: number | string; /** true if this is a TTS message */ tts?: boolean; /** Embedded `rich` content */ embed?: Embed; - /** Allowed mentions for a message */ + /** Allowed mentions for the message */ allowedMentions?: AllowedMentions; /** Include to make your message a reply */ messageReference?: MessageReference; From 3694c377ebdb641cbf8d76e13af8c94c639a00a2 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:20:36 +0200 Subject: [PATCH 07/12] Update send_message.ts --- src/helpers/messages/send_message.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index ff80dfb53..7e5b815dd 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -145,13 +145,6 @@ export async function sendMessage( } } - if ( - content.nonce && - !validateLength(content.nonce.toString(), { max: 25 }) - ) { - throw new Error(Errors.NONCE_TOO_LONG); - } - const result = await rest.runMethod( "post", endpoints.CHANNEL_MESSAGES(channelId), From 3ecfaef780358b9e93fec53a498840e04c5df653 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:22:41 +0200 Subject: [PATCH 08/12] edit message can now have files --- src/types/messages/edit_message.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/types/messages/edit_message.ts b/src/types/messages/edit_message.ts index 41169bc55..0ca2f06d9 100644 --- a/src/types/messages/edit_message.ts +++ b/src/types/messages/edit_message.ts @@ -1,4 +1,5 @@ import { Embed } from "../embeds/embed.ts"; +import { FileContent } from "../misc/file_content.ts"; import { AllowedMentions } from "./allowed_mentions.ts"; import { Attachment } from "./attachment.ts"; @@ -10,6 +11,8 @@ export interface EditMessage { embed?: Embed | null; /** Edit the flags of the message (only `SUPRESS_EMBEDS` can currently be set/unset) */ flags?: 4 | null; + /** The contents of the file being sent/edited */ + file?: FileContent | FileContent[] | null; /** Allowed mentions for the message */ allowedMentions?: AllowedMentions | null; /** Attached files to keep */ From 147453cd1e7f155946a0910a8201b1389968ad0b Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:22:53 +0200 Subject: [PATCH 09/12] fix files can be nullable --- src/types/webhooks/edit_webhook_message.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/webhooks/edit_webhook_message.ts b/src/types/webhooks/edit_webhook_message.ts index 6317c70fe..d8fc7ba3c 100644 --- a/src/types/webhooks/edit_webhook_message.ts +++ b/src/types/webhooks/edit_webhook_message.ts @@ -1,7 +1,7 @@ import { Embed } from "../embeds/embed.ts"; import { AllowedMentions } from "../messages/allowed_mentions.ts"; -import { FileContent } from "../misc/file_content.ts"; import { Attachment } from "../messages/attachment.ts"; +import { FileContent } from "../misc/file_content.ts"; /** https://discord.com/developers/docs/resources/webhook#edit-webhook-message-jsonform-params */ export interface EditWebhookMessage { @@ -10,7 +10,7 @@ export interface EditWebhookMessage { /** Embedded `rich` content */ embeds?: Embed[] | null; /** The contents of the file being sent/edited */ - file?: FileContent | FileContent[]; + file?: FileContent | FileContent[] | null; /** Allowed mentions for the message */ allowedMentions?: AllowedMentions | null; /** Attached files to keep */ From c5cf4ba3533734aa3b485ee6d8737e3fcc30cf40 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:24:37 +0200 Subject: [PATCH 10/12] Update get_invite.ts --- src/helpers/invites/get_invite.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/invites/get_invite.ts b/src/helpers/invites/get_invite.ts index 12772f327..8e5b177e4 100644 --- a/src/helpers/invites/get_invite.ts +++ b/src/helpers/invites/get_invite.ts @@ -5,10 +5,10 @@ import { endpoints } from "../../util/constants.ts"; import { camelKeysToSnakeCase } from "../../util/utils.ts"; /** Returns an invite for the given code or throws an error if the invite doesn't exists. */ -export async function getInvite(inviteCode: string, options: GetInvite) { +export async function getInvite(inviteCode: string, options?: GetInvite) { return await rest.runMethod( "get", endpoints.INVITE(inviteCode), - camelKeysToSnakeCase(options), + camelKeysToSnakeCase(options ?? {}), ); } From d16280512cbdfa0179f3df8fc8bc9081c6056e4f Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Tue, 4 May 2021 22:36:00 +0200 Subject: [PATCH 11/12] add: webhook thread support --- src/helpers/webhooks/send_webhook.ts | 6 +++--- src/types/webhooks/execute_webhook.ts | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/helpers/webhooks/send_webhook.ts b/src/helpers/webhooks/send_webhook.ts index e627e485a..20cd92e46 100644 --- a/src/helpers/webhooks/send_webhook.ts +++ b/src/helpers/webhooks/send_webhook.ts @@ -66,9 +66,9 @@ export async function sendWebhook( const result = await rest.runMethod( "post", - `${endpoints.WEBHOOK(webhookId, webhookToken)}${ - options.wait ? "?wait=true" : "" - }`, + `${endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${ + options.wait ? "true" : "false" + }${options.threadId ? `&thread_id=${options.threadId}` : ""}`, { ...options, allowed_mentions: options.allowedMentions, diff --git a/src/types/webhooks/execute_webhook.ts b/src/types/webhooks/execute_webhook.ts index 9268f21bf..bce114c30 100644 --- a/src/types/webhooks/execute_webhook.ts +++ b/src/types/webhooks/execute_webhook.ts @@ -7,6 +7,8 @@ import { SnakeCasedPropertiesDeep } from "../util.ts"; export interface ExecuteWebhook { /** Waits for server confirmation of message send before response, and returns the created message body (defaults to `false`; when `false` a message that is not saved does not return an error) */ wait?: boolean; + /** Send a message to the specified thread within a webhook's channel. The thread will automatically be unarchived. */ + threadId?: bigint; /** The message contents (up to 2000 characters) */ content?: string; /** Override the default username of the webhook */ From 774d7649f5bc78c43eb1714325a8f6fe1e742070 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Wed, 5 May 2021 15:54:41 +0200 Subject: [PATCH 12/12] Update send_webhook.ts --- src/helpers/webhooks/send_webhook.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/webhooks/send_webhook.ts b/src/helpers/webhooks/send_webhook.ts index 20cd92e46..cb90615ed 100644 --- a/src/helpers/webhooks/send_webhook.ts +++ b/src/helpers/webhooks/send_webhook.ts @@ -66,9 +66,9 @@ export async function sendWebhook( const result = await rest.runMethod( "post", - `${endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${ - options.wait ? "true" : "false" - }${options.threadId ? `&thread_id=${options.threadId}` : ""}`, + `${endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${options.wait}${ + options.threadId ? `&thread_id=${options.threadId}` : "" + }`, { ...options, allowed_mentions: options.allowedMentions,