mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix: minimum 2 characters for custom emojis
This commit is contained in:
@@ -26,7 +26,17 @@ describe('Button Components', () => {
|
||||
.setCustomId('custom')
|
||||
.setLabel('test')
|
||||
.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();
|
||||
}).not.toThrowError();
|
||||
@@ -37,7 +47,7 @@ describe('Button Components', () => {
|
||||
}).not.toThrowError();
|
||||
|
||||
expect(() => {
|
||||
const button = new DangerButtonBuilder().setCustomId('custom').setEmoji({ name: 'ok' });
|
||||
const button = new DangerButtonBuilder().setCustomId('custom').setEmoji({ name: '👌' });
|
||||
button.toJSON();
|
||||
}).not.toThrowError();
|
||||
|
||||
@@ -47,7 +57,7 @@ describe('Button Components', () => {
|
||||
}).not.toThrowError();
|
||||
|
||||
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();
|
||||
}).not.toThrowError();
|
||||
|
||||
@@ -66,7 +76,17 @@ describe('Button Components', () => {
|
||||
|
||||
expect(() => {
|
||||
// @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();
|
||||
}).toThrowError();
|
||||
|
||||
@@ -86,7 +106,7 @@ describe('Button Components', () => {
|
||||
// @ts-expect-error: Invalid parameter for disabled
|
||||
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setDisabled(0).toJSON()).toThrowError();
|
||||
// @ts-expect-error: Invalid emoji
|
||||
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setEmoji('foo').toJSON()).toThrowError();
|
||||
expect(() => new PrimaryButtonBuilder().setCustomId('hi').setEmoji('🩵').toJSON()).toThrowError();
|
||||
|
||||
expect(() =>
|
||||
new LinkButtonBuilder()
|
||||
|
||||
@@ -80,7 +80,7 @@ describe('Select Menu Components', () => {
|
||||
.setLabel('test')
|
||||
.setValue('test')
|
||||
.setDefault(true)
|
||||
.setEmoji({ name: 'test' })
|
||||
.setEmoji({ name: '🩵' })
|
||||
.setDescription('description');
|
||||
expect(() => selectMenuWithId().addOptions(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
|
||||
.strictObject({
|
||||
id: snowflakePredicate.optional(),
|
||||
name: z.string().min(1).max(32).optional(),
|
||||
name: z.string().max(32).optional(),
|
||||
animated: z.boolean().optional(),
|
||||
})
|
||||
.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({
|
||||
type: z.literal(ComponentType.Button),
|
||||
|
||||
Reference in New Issue
Block a user