mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
feat(handlers/webhook): test slash command name against ^[\w-]{1,32}$ (#613)
* feat(handlers/webhook): test slash command name against ^[\w-]{1,32}$
* Update src/api/handlers/webhook.ts
Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
* Update src/api/handlers/webhook.ts
Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
* Update src/api/handlers/webhook.ts
Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
* Update src/api/handlers/webhook.ts
Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
* move to constants file
* idk
* idk
Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
|||||||
WebhookPayload,
|
WebhookPayload,
|
||||||
} from "../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
import { cache } from "../../util/cache.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 { botHasChannelPermissions } from "../../util/permissions.ts";
|
||||||
import { urlToBase64 } from "../../util/utils.ts";
|
import { urlToBase64 } from "../../util/utils.ts";
|
||||||
import { structures } from "../structures/mod.ts";
|
import { structures } from "../structures/mod.ts";
|
||||||
@@ -282,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.
|
* 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) {
|
export async function createSlashCommand(options: CreateSlashCommandOptions) {
|
||||||
// Use ... for content length due to unicode characters and js .length handling
|
if (!SLASH_COMMANDS_NAME_REGEX.test(options.name)) {
|
||||||
if ([...options.name].length < 2 || [...options.name].length > 32) {
|
|
||||||
throw new Error(Errors.INVALID_SLASH_NAME);
|
throw new Error(Errors.INVALID_SLASH_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,8 +335,7 @@ export async function upsertSlashCommand(
|
|||||||
options: UpsertSlashCommandOptions,
|
options: UpsertSlashCommandOptions,
|
||||||
guildID?: string,
|
guildID?: string,
|
||||||
) {
|
) {
|
||||||
// Use ... for content length due to unicode characters and js .length handling
|
if (!SLASH_COMMANDS_NAME_REGEX.test(options.name)) {
|
||||||
if ([...options.name].length < 2 || [...options.name].length > 32) {
|
|
||||||
throw new Error(Errors.INVALID_SLASH_NAME);
|
throw new Error(Errors.INVALID_SLASH_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,8 +369,7 @@ export async function upsertSlashCommands(
|
|||||||
guildID?: string,
|
guildID?: string,
|
||||||
) {
|
) {
|
||||||
const data = options.map((option) => {
|
const data = options.map((option) => {
|
||||||
// Use ... for content length due to unicode characters and js .length handling
|
if (!SLASH_COMMANDS_NAME_REGEX.test(option.name)) {
|
||||||
if ([...option.name].length < 2 || [...option.name].length > 32) {
|
|
||||||
throw new Error(Errors.INVALID_SLASH_NAME);
|
throw new Error(Errors.INVALID_SLASH_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,8 +402,7 @@ export async function editSlashCommand(
|
|||||||
options: EditSlashCommandOptions,
|
options: EditSlashCommandOptions,
|
||||||
guildID?: string,
|
guildID?: string,
|
||||||
) {
|
) {
|
||||||
// Use ... for content length due to unicode characters and js .length handling
|
if (!SLASH_COMMANDS_NAME_REGEX.test(options.name)) {
|
||||||
if ([...options.name].length < 2 || [...options.name].length > 32) {
|
|
||||||
throw new Error(Errors.INVALID_SLASH_NAME);
|
throw new Error(Errors.INVALID_SLASH_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,3 +175,5 @@ export const endpoints = {
|
|||||||
// oAuth2
|
// oAuth2
|
||||||
OAUTH2_APPLICATION: `${baseEndpoints.BASE_URL}/oauth2/applications/@me`,
|
OAUTH2_APPLICATION: `${baseEndpoints.BASE_URL}/oauth2/applications/@me`,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/;
|
||||||
|
|||||||
Reference in New Issue
Block a user