mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 08:03:30 +01:00
fix: minimum 2 characters for custom emojis
This commit is contained in:
@@ -26,7 +26,17 @@ describe('Button Components', () => {
|
|||||||
.setCustomId('custom')
|
.setCustomId('custom')
|
||||||
.setLabel('test')
|
.setLabel('test')
|
||||||
.setDisabled(true)
|
.setDisabled(true)
|
||||||
.setEmoji({ name: 'test' });
|
.setEmoji({ name: '🩵' });
|
||||||
|
|
||||||
|
button.toJSON();
|
||||||
|
}).not.toThrowError();
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
const button = new PrimaryButtonBuilder()
|
||||||
|
.setCustomId('custom')
|
||||||
|
.setLabel('test')
|
||||||
|
.setDisabled(true)
|
||||||
|
.setEmoji({ id: '1234567890123456', name: 'test', animated: true });
|
||||||
|
|
||||||
button.toJSON();
|
button.toJSON();
|
||||||
}).not.toThrowError();
|
}).not.toThrowError();
|
||||||
@@ -37,7 +47,7 @@ describe('Button Components', () => {
|
|||||||
}).not.toThrowError();
|
}).not.toThrowError();
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
const button = new DangerButtonBuilder().setCustomId('custom').setEmoji({ name: 'ok' });
|
const button = new DangerButtonBuilder().setCustomId('custom').setEmoji({ name: '👌' });
|
||||||
button.toJSON();
|
button.toJSON();
|
||||||
}).not.toThrowError();
|
}).not.toThrowError();
|
||||||
|
|
||||||
@@ -47,7 +57,7 @@ describe('Button Components', () => {
|
|||||||
}).not.toThrowError();
|
}).not.toThrowError();
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
const button = new LinkButtonBuilder().setURL('https://discord.js.org').setEmoji({ name: 'ok' });
|
const button = new LinkButtonBuilder().setURL('https://discord.js.org').setEmoji({ name: '👌' });
|
||||||
button.toJSON();
|
button.toJSON();
|
||||||
}).not.toThrowError();
|
}).not.toThrowError();
|
||||||
|
|
||||||
@@ -66,7 +76,17 @@ describe('Button Components', () => {
|
|||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
// @ts-expect-error: Invalid emoji
|
// @ts-expect-error: Invalid emoji
|
||||||
const button = new PrimaryButtonBuilder().setEmoji('test');
|
const button = new PrimaryButtonBuilder().setEmoji('🩵');
|
||||||
|
button.toJSON();
|
||||||
|
}).toThrowError();
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
const button = new PrimaryButtonBuilder()
|
||||||
|
.setCustomId('custom')
|
||||||
|
.setLabel('test')
|
||||||
|
.setDisabled(true)
|
||||||
|
.setEmoji({ id: '1234567890123456', name: '1' });
|
||||||
|
|
||||||
button.toJSON();
|
button.toJSON();
|
||||||
}).toThrowError();
|
}).toThrowError();
|
||||||
|
|
||||||
@@ -86,7 +106,7 @@ describe('Button Components', () => {
|
|||||||
// @ts-expect-error: Invalid parameter for disabled
|
// @ts-expect-error: Invalid parameter for disabled
|
||||||
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setDisabled(0).toJSON()).toThrowError();
|
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setDisabled(0).toJSON()).toThrowError();
|
||||||
// @ts-expect-error: Invalid emoji
|
// @ts-expect-error: Invalid emoji
|
||||||
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setEmoji('foo').toJSON()).toThrowError();
|
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setEmoji('🩵').toJSON()).toThrowError();
|
||||||
|
|
||||||
expect(() =>
|
expect(() =>
|
||||||
new LinkButtonBuilder()
|
new LinkButtonBuilder()
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ describe('Select Menu Components', () => {
|
|||||||
.setLabel('test')
|
.setLabel('test')
|
||||||
.setValue('test')
|
.setValue('test')
|
||||||
.setDefault(true)
|
.setDefault(true)
|
||||||
.setEmoji({ name: 'test' })
|
.setEmoji({ name: '🩵' })
|
||||||
.setDescription('description');
|
.setDescription('description');
|
||||||
expect(() => selectMenuWithId().addOptions(option).toJSON()).not.toThrowError();
|
expect(() => selectMenuWithId().addOptions(option).toJSON()).not.toThrowError();
|
||||||
expect(() => selectMenuWithId().setOptions(option).toJSON()).not.toThrowError();
|
expect(() => selectMenuWithId().setOptions(option).toJSON()).not.toThrowError();
|
||||||
|
|||||||
@@ -5,12 +5,25 @@ import { idPredicate, customIdPredicate, snowflakePredicate } from '../Assertion
|
|||||||
export const emojiPredicate = z
|
export const emojiPredicate = z
|
||||||
.strictObject({
|
.strictObject({
|
||||||
id: snowflakePredicate.optional(),
|
id: snowflakePredicate.optional(),
|
||||||
name: z.string().min(1).max(32).optional(),
|
name: z.string().max(32).optional(),
|
||||||
animated: z.boolean().optional(),
|
animated: z.boolean().optional(),
|
||||||
})
|
})
|
||||||
.refine((data) => data.id !== undefined || data.name !== undefined, {
|
.refine((data) => data.id !== undefined || data.name !== undefined, {
|
||||||
error: "Either 'id' or 'name' must be provided",
|
error: "Either 'id' or 'name' must be provided.",
|
||||||
});
|
})
|
||||||
|
.refine(
|
||||||
|
(data) => {
|
||||||
|
if (data.id !== undefined && data.name !== undefined) {
|
||||||
|
return data.name.length >= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
error: 'Custom emoji names must be at least 2 characters.',
|
||||||
|
path: ['name'],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const buttonPredicateBase = z.strictObject({
|
const buttonPredicateBase = z.strictObject({
|
||||||
type: z.literal(ComponentType.Button),
|
type: z.literal(ComponentType.Button),
|
||||||
|
|||||||
Reference in New Issue
Block a user