mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
Merge pull request #845 from discordeno/feat-validate-length
feat: add validateLength util
This commit is contained in:
@@ -10,6 +10,7 @@ import { PermissionStrings } from "../../types/permissions/permission_strings.ts
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
import { camelKeysToSnakeCase } from "../../util/utils.ts";
|
||||
import { validateLength } from "../../util/validate_length.ts";
|
||||
|
||||
/** Send a message to the channel. Requires SEND_MESSAGES permission. */
|
||||
export async function sendMessage(
|
||||
@@ -48,7 +49,7 @@ export async function sendMessage(
|
||||
}
|
||||
|
||||
// Use ... for content length due to unicode characters and js .length handling
|
||||
if (content.content && [...content.content].length > 2000) {
|
||||
if (content.content && !validateLength(content.content, { max: 2000 })) {
|
||||
throw new Error(Errors.MESSAGE_MAX_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import { DiscordWebhook } from "../../types/webhooks/webhook.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||
import { snakeKeysToCamelCase, urlToBase64 } from "../../util/utils.ts";
|
||||
import { validateLength } from "../../util/validate_length.ts";
|
||||
|
||||
/**
|
||||
* Create a new webhook. Requires the MANAGE_WEBHOOKS permission. Returns a webhook object on success. Webhook names follow our naming restrictions that can be found in our Usernames and Nicknames documentation, with the following additional stipulations:
|
||||
@@ -21,9 +22,7 @@ export async function createWebhook(
|
||||
if (
|
||||
// Specific usernames that discord does not allow
|
||||
options.name === "clyde" ||
|
||||
// Character limit checks. [...] checks are because of js unicode length handling
|
||||
[...options.name].length < 2 ||
|
||||
[...options.name].length > 32
|
||||
!validateLength(options.name, { min: 2, max: 32 })
|
||||
) {
|
||||
throw new Error(Errors.INVALID_WEBHOOK_NAME);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user