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); +} diff --git a/src/helpers/invites/get_invite.ts b/src/helpers/invites/get_invite.ts index f0781e927..8e5b177e4 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 ?? {}), ); } diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index 4e1249b0c..cdfac97a4 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), 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; diff --git a/src/helpers/webhooks/get_webhook_message.ts b/src/helpers/webhooks/get_webhook_message.ts new file mode 100644 index 000000000..d59fc02a7 --- /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 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. */ +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); +} diff --git a/src/helpers/webhooks/send_webhook.ts b/src/helpers/webhooks/send_webhook.ts index e627e485a..cb90615ed 100644 --- a/src/helpers/webhooks/send_webhook.ts +++ b/src/helpers/webhooks/send_webhook.ts @@ -66,8 +66,8 @@ 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}${ + options.threadId ? `&thread_id=${options.threadId}` : "" }`, { ...options, 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; 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 */ 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 */ 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 */