mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
BREAKING CHANGE: formatters export removed (prev. deprecated) BREAKING CHANGE: `SelectMenuBuilder` and `SelectMenuOptionBuilder` have been removed (prev. deprecated) BREAKING CHANGE: `EmbedBuilder` no longer takes camalCase options BREAKING CHANGE: `ActionRowBuilder` now has specialized `[add/set]X` methods as opposed to the current `[add/set]Components` BREAKING CHANGE: Removed `equals` methods BREAKING CHANGE: Sapphire -> zod for validation BREAKING CHANGE: Removed the ability to pass `null`/`undefined` to clear fields, use `clearX()` instead BREAKING CHANGE: Renamed all "slash command" symbols to instead use "chat input command" BREAKING CHANGE: Removed `ContextMenuCommandBuilder` in favor of `MessageCommandBuilder` and `UserCommandBuilder` BREAKING CHANGE: Removed support for passing the "string key"s of enums BREAKING CHANGE: Removed `Button` class in favor for specialized classes depending on the style BREAKING CHANGE: Removed nested `addX` styled-methods in favor of plural `addXs` Co-authored-by: Vlad Frangu <me@vladfrangu.dev> Co-authored-by: Almeida <github@almeidx.dev>
71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import { z } from 'zod';
|
|
import { refineURLPredicate } from '../../Assertions.js';
|
|
import { embedLength } from '../../util/componentUtil.js';
|
|
|
|
const namePredicate = z.string().min(1).max(256);
|
|
|
|
const iconURLPredicate = z
|
|
.string()
|
|
.url()
|
|
.refine(refineURLPredicate(['http:', 'https:', 'attachment:']), {
|
|
message: 'Invalid protocol for icon URL. Must be http:, https:, or attachment:',
|
|
});
|
|
|
|
const URLPredicate = z
|
|
.string()
|
|
.url()
|
|
.refine(refineURLPredicate(['http:', 'https:']), { message: 'Invalid protocol for URL. Must be http: or https:' });
|
|
|
|
export const embedFieldPredicate = z.object({
|
|
name: namePredicate,
|
|
value: z.string().min(1).max(1_024),
|
|
inline: z.boolean().optional(),
|
|
});
|
|
|
|
export const embedAuthorPredicate = z.object({
|
|
name: namePredicate,
|
|
icon_url: iconURLPredicate.optional(),
|
|
url: URLPredicate.optional(),
|
|
});
|
|
|
|
export const embedFooterPredicate = z.object({
|
|
text: z.string().min(1).max(2_048),
|
|
icon_url: iconURLPredicate.optional(),
|
|
});
|
|
|
|
export const embedPredicate = z
|
|
.object({
|
|
title: namePredicate.optional(),
|
|
description: z.string().min(1).max(4_096).optional(),
|
|
url: URLPredicate.optional(),
|
|
timestamp: z.string().optional(),
|
|
color: z.number().int().min(0).max(0xffffff).optional(),
|
|
footer: embedFooterPredicate.optional(),
|
|
image: z.object({ url: URLPredicate }).optional(),
|
|
thumbnail: z.object({ url: URLPredicate }).optional(),
|
|
author: embedAuthorPredicate.optional(),
|
|
fields: z.array(embedFieldPredicate).max(25).optional(),
|
|
})
|
|
.refine(
|
|
(embed) => {
|
|
return (
|
|
embed.title !== undefined ||
|
|
embed.description !== undefined ||
|
|
(embed.fields !== undefined && embed.fields.length > 0) ||
|
|
embed.footer !== undefined ||
|
|
embed.author !== undefined ||
|
|
embed.image !== undefined ||
|
|
embed.thumbnail !== undefined
|
|
);
|
|
},
|
|
{
|
|
message: 'Embed must have at least a title, description, a field, a footer, an author, an image, OR a thumbnail.',
|
|
},
|
|
)
|
|
.refine(
|
|
(embed) => {
|
|
return embedLength(embed) <= 6_000;
|
|
},
|
|
{ message: 'Embeds must not exceed 6000 characters in total.' },
|
|
);
|