diff --git a/src/api/handlers/webhook.ts b/src/api/handlers/webhook.ts index 4f3eef451..15f9039d1 100644 --- a/src/api/handlers/webhook.ts +++ b/src/api/handlers/webhook.ts @@ -17,7 +17,7 @@ import { WebhookPayload, } from "../../types/mod.ts"; import { cache } from "../../util/cache.ts"; -import { endpoints } from "../../util/constants.ts"; +import { endpoints, SLASH_COMMANDS_NAME_REGEX } from "../../util/constants.ts"; import { botHasChannelPermissions } from "../../util/permissions.ts"; import { urlToBase64 } from "../../util/utils.ts"; import { structures } from "../structures/mod.ts"; @@ -252,9 +252,10 @@ export async function editWebhookMessage( const result = await RequestManager.patch( endpoints.WEBHOOK_MESSAGE(webhookID, webhookToken, messageID), { ...options, allowed_mentions: options.allowed_mentions }, - ); + ) as MessageCreateOptions; - return result; + const message = await structures.createMessage(result); + return message; } export async function deleteWebhookMessage( @@ -281,8 +282,7 @@ export async function deleteWebhookMessage( * Guild commands update **instantly**. We recommend you use guild commands for quick testing, and global commands when they're ready for public use. */ export async function createSlashCommand(options: CreateSlashCommandOptions) { - // Use ... for content length due to unicode characters and js .length handling - if ([...options.name].length < 2 || [...options.name].length > 32) { + if (!SLASH_COMMANDS_NAME_REGEX.test(options.name)) { throw new Error(Errors.INVALID_SLASH_NAME); } @@ -335,11 +335,7 @@ export async function upsertSlashCommand( options: UpsertSlashCommandOptions, guildID?: string, ) { - // Use ... for content length due to unicode characters and js .length handling - if ( - options.name && - ([...options.name].length < 2 || [...options.name].length > 32) - ) { + if (options.name && !SLASH_COMMANDS_NAME_REGEX.test(options.name)) { throw new Error(Errors.INVALID_SLASH_NAME); } @@ -375,11 +371,7 @@ export async function upsertSlashCommands( guildID?: string, ) { const data = options.map((option) => { - // Use ... for content length due to unicode characters and js .length handling - if ( - option.name && - ([...option.name].length < 2 || [...option.name].length > 32) - ) { + if (option.name && !SLASH_COMMANDS_NAME_REGEX.test(option.name)) { throw new Error(Errors.INVALID_SLASH_NAME); } @@ -414,8 +406,7 @@ export async function editSlashCommand( options: EditSlashCommandOptions, guildID?: string, ) { - // Use ... for content length due to unicode characters and js .length handling - if ([...options.name].length < 2 || [...options.name].length > 32) { + if (!SLASH_COMMANDS_NAME_REGEX.test(options.name)) { throw new Error(Errors.INVALID_SLASH_NAME); } @@ -562,5 +553,11 @@ export async function editSlashResponse( options, ); - return result; + // If the original message was edited, this will not return a message + if (!options.messageID) return result; + + const message = await structures.createMessage( + result as MessageCreateOptions, + ); + return message; } diff --git a/src/types/api/embed.ts b/src/types/api/embed.ts index 2188c3c11..0535d4516 100644 --- a/src/types/api/embed.ts +++ b/src/types/api/embed.ts @@ -56,6 +56,8 @@ export interface DiscordEmbedThumbnail { export interface DiscordEmbedVideo { /** source url of video */ url?: string; + /** a proxied url of the video */ + proxy_url?: string; /** height of video */ height?: number; /** width of video */ diff --git a/src/types/message.ts b/src/types/message.ts index 24f036a95..86f0e4d63 100644 --- a/src/types/message.ts +++ b/src/types/message.ts @@ -99,6 +99,8 @@ export interface EmbedThumbnail { export interface EmbedVideo { /** The source url of video */ url?: string; + /** a proxied url of the video */ + proxy_url?: string; /** The height of the video */ height?: number; /** The width of the video */ diff --git a/src/util/constants.ts b/src/util/constants.ts index afad4433c..af1d8ef57 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -175,3 +175,5 @@ export const endpoints = { // oAuth2 OAUTH2_APPLICATION: `${baseEndpoints.BASE_URL}/oauth2/applications/@me`, }; + +export const SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/;