mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 13:03:31 +01:00
fix: Adjust label predicates (#11318)
* fix: labels in 14 * test: add variable for at limit * docs(jsonOptionValidator): deprecate * fix: export `selectMenuStringOptionPredicate` * fix: export everything Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com> --------- Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,10 @@ const selectMenu = () => new StringSelectMenuBuilder();
|
|||||||
const selectMenuOption = () => new StringSelectMenuOptionBuilder();
|
const selectMenuOption = () => new StringSelectMenuOptionBuilder();
|
||||||
|
|
||||||
const longStr = 'a'.repeat(256);
|
const longStr = 'a'.repeat(256);
|
||||||
|
const selectMenuOptionLabelAtLimit = 'a'.repeat(100);
|
||||||
|
const selectMenuOptionLabelAboveLimit = 'a'.repeat(101);
|
||||||
|
const selectMenuOptionValueAboveLimit = 'a'.repeat(101);
|
||||||
|
const selectMenuOptionDescriptionAboveLimit = 'a'.repeat(101);
|
||||||
|
|
||||||
const selectMenuOptionData: APISelectMenuOption = {
|
const selectMenuOptionData: APISelectMenuOption = {
|
||||||
label: 'test',
|
label: 'test',
|
||||||
@@ -53,12 +57,12 @@ describe('Select Menu Components', () => {
|
|||||||
expect(() => selectMenu().setDisabled()).not.toThrowError();
|
expect(() => selectMenu().setDisabled()).not.toThrowError();
|
||||||
expect(() => selectMenu().setPlaceholder('description')).not.toThrowError();
|
expect(() => selectMenu().setPlaceholder('description')).not.toThrowError();
|
||||||
const option = selectMenuOption()
|
const option = selectMenuOption()
|
||||||
.setLabel('test')
|
.setLabel(selectMenuOptionLabelAtLimit)
|
||||||
.setValue('test')
|
.setValue('test')
|
||||||
.setDefault(true)
|
.setDefault(true)
|
||||||
.setEmoji({ name: 'test' })
|
.setEmoji({ name: 'test' })
|
||||||
.setDescription('description');
|
.setDescription('description');
|
||||||
expect(() => selectMenu().addOptions(option)).not.toThrowError();
|
expect(() => selectMenu().setCustomId('customId').addOptions(option).toJSON()).not.toThrowError();
|
||||||
expect(() => selectMenu().setOptions(option)).not.toThrowError();
|
expect(() => selectMenu().setOptions(option)).not.toThrowError();
|
||||||
expect(() => selectMenu().setOptions({ label: 'test', value: 'test' })).not.toThrowError();
|
expect(() => selectMenu().setOptions({ label: 'test', value: 'test' })).not.toThrowError();
|
||||||
expect(() => selectMenu().addOptions([option])).not.toThrowError();
|
expect(() => selectMenu().addOptions([option])).not.toThrowError();
|
||||||
@@ -156,13 +160,13 @@ describe('Select Menu Components', () => {
|
|||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
selectMenuOption()
|
selectMenuOption()
|
||||||
.setLabel(longStr)
|
.setLabel(selectMenuOptionLabelAboveLimit)
|
||||||
.setValue(longStr)
|
.setValue(selectMenuOptionValueAboveLimit)
|
||||||
// @ts-expect-error: Invalid default value
|
// @ts-expect-error: Invalid default value
|
||||||
.setDefault(-1)
|
.setDefault(-1)
|
||||||
// @ts-expect-error: Invalid emoji
|
// @ts-expect-error: Invalid emoji
|
||||||
.setEmoji({ name: 1 })
|
.setEmoji({ name: 1 })
|
||||||
.setDescription(longStr);
|
.setDescription(selectMenuOptionDescriptionAboveLimit);
|
||||||
}).toThrowError();
|
}).toThrowError();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ export const labelValueDescriptionValidator = s
|
|||||||
.lengthLessThanOrEqual(100)
|
.lengthLessThanOrEqual(100)
|
||||||
.setValidationEnabled(isValidationEnabled);
|
.setValidationEnabled(isValidationEnabled);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Replaced with selectMenuStringOptionPredicate.
|
||||||
|
*/
|
||||||
export const jsonOptionValidator = s
|
export const jsonOptionValidator = s
|
||||||
.object({
|
.object({
|
||||||
label: labelValueDescriptionValidator,
|
label: labelValueDescriptionValidator,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Result, s } from '@sapphire/shapeshift';
|
|||||||
import { ChannelType, ComponentType, SelectMenuDefaultValueType } from 'discord-api-types/v10';
|
import { ChannelType, ComponentType, SelectMenuDefaultValueType } from 'discord-api-types/v10';
|
||||||
import { isValidationEnabled } from '../../util/validation.js';
|
import { isValidationEnabled } from '../../util/validation.js';
|
||||||
import { customIdValidator, emojiValidator, idValidator } from '../Assertions.js';
|
import { customIdValidator, emojiValidator, idValidator } from '../Assertions.js';
|
||||||
import { labelValidator } from '../textInput/Assertions.js';
|
|
||||||
|
|
||||||
const selectMenuBasePredicate = s.object({
|
const selectMenuBasePredicate = s.object({
|
||||||
id: idValidator.optional(),
|
id: idValidator.optional(),
|
||||||
@@ -63,7 +62,7 @@ export const selectMenuUserPredicate = selectMenuBasePredicate
|
|||||||
|
|
||||||
export const selectMenuStringOptionPredicate = s
|
export const selectMenuStringOptionPredicate = s
|
||||||
.object({
|
.object({
|
||||||
label: labelValidator,
|
label: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100),
|
||||||
value: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100),
|
value: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100),
|
||||||
description: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).optional(),
|
description: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).optional(),
|
||||||
emoji: emojiValidator.optional(),
|
emoji: emojiValidator.optional(),
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { ComponentType } from 'discord-api-types/v10';
|
import { ComponentType } from 'discord-api-types/v10';
|
||||||
import type { APIStringSelectComponent, APISelectMenuOption } from 'discord-api-types/v10';
|
import type { APIStringSelectComponent, APISelectMenuOption } from 'discord-api-types/v10';
|
||||||
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';
|
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';
|
||||||
import { jsonOptionValidator, optionsLengthValidator, validateRequiredSelectMenuParameters } from '../Assertions.js';
|
import { optionsLengthValidator, validateRequiredSelectMenuParameters } from '../Assertions.js';
|
||||||
|
import { selectMenuStringOptionPredicate } from './Assertions.js';
|
||||||
import { BaseSelectMenuBuilder } from './BaseSelectMenu.js';
|
import { BaseSelectMenuBuilder } from './BaseSelectMenu.js';
|
||||||
import { StringSelectMenuOptionBuilder } from './StringSelectMenuOption.js';
|
import { StringSelectMenuOptionBuilder } from './StringSelectMenuOption.js';
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ export class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSele
|
|||||||
...normalizedOptions.map((normalizedOption) =>
|
...normalizedOptions.map((normalizedOption) =>
|
||||||
normalizedOption instanceof StringSelectMenuOptionBuilder
|
normalizedOption instanceof StringSelectMenuOptionBuilder
|
||||||
? normalizedOption
|
? normalizedOption
|
||||||
: new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)),
|
: new StringSelectMenuOptionBuilder(selectMenuStringOptionPredicate.parse(normalizedOption)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
return this;
|
return this;
|
||||||
@@ -120,7 +121,7 @@ export class StringSelectMenuBuilder extends BaseSelectMenuBuilder<APIStringSele
|
|||||||
...normalizedOptions.map((normalizedOption) =>
|
...normalizedOptions.map((normalizedOption) =>
|
||||||
normalizedOption instanceof StringSelectMenuOptionBuilder
|
normalizedOption instanceof StringSelectMenuOptionBuilder
|
||||||
? normalizedOption
|
? normalizedOption
|
||||||
: new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)),
|
: new StringSelectMenuOptionBuilder(selectMenuStringOptionPredicate.parse(normalizedOption)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export {
|
|||||||
*/
|
*/
|
||||||
StringSelectMenuOptionBuilder as SelectMenuOptionBuilder,
|
StringSelectMenuOptionBuilder as SelectMenuOptionBuilder,
|
||||||
} from './components/selectMenu/StringSelectMenuOption.js';
|
} from './components/selectMenu/StringSelectMenuOption.js';
|
||||||
|
export * as SelectMenuAssertions from './components/selectMenu/Assertions.js';
|
||||||
export * from './components/selectMenu/StringSelectMenuOption.js';
|
export * from './components/selectMenu/StringSelectMenuOption.js';
|
||||||
export * from './components/selectMenu/UserSelectMenu.js';
|
export * from './components/selectMenu/UserSelectMenu.js';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user