From 3baa340821b8ecf8a16253bc0917a1033250d7c9 Mon Sep 17 00:00:00 2001 From: Skick Date: Sun, 20 Feb 2022 19:43:50 +0700 Subject: [PATCH] fix(builders): allow negative min/max value of number/integer option (#7484) --- .../interactions/SlashCommands/Options.test.ts | 16 ++++++++-------- .../slashCommands/options/integer.ts | 2 +- .../interactions/slashCommands/options/number.ts | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/builders/__tests__/interactions/SlashCommands/Options.test.ts b/packages/builders/__tests__/interactions/SlashCommands/Options.test.ts index 57d4a56f7e15..3a8670c6a55f 100644 --- a/packages/builders/__tests__/interactions/SlashCommands/Options.test.ts +++ b/packages/builders/__tests__/interactions/SlashCommands/Options.test.ts @@ -39,7 +39,7 @@ const getIntegerOption = () => .setName('owo') .setDescription('Testing 123') .setRequired(true) - .setMinValue(1) + .setMinValue(-1) .setMaxValue(10); const getNumberOption = () => @@ -47,7 +47,7 @@ const getNumberOption = () => .setName('owo') .setDescription('Testing 123') .setRequired(true) - .setMinValue(1) + .setMinValue(-1.23) .setMaxValue(10); const getUserOption = () => new SlashCommandUserOption().setName('owo').setDescription('Testing 123').setRequired(true); @@ -84,7 +84,7 @@ describe('Application Command toJSON() results', () => { type: ApplicationCommandOptionType.Integer, required: true, max_value: 10, - min_value: 1, + min_value: -1, }); expect(getIntegerOption().setAutocomplete(true).setChoices().toJSON()).toEqual({ @@ -93,7 +93,7 @@ describe('Application Command toJSON() results', () => { type: ApplicationCommandOptionType.Integer, required: true, max_value: 10, - min_value: 1, + min_value: -1, autocomplete: true, // @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types choices: [], @@ -107,7 +107,7 @@ describe('Application Command toJSON() results', () => { type: ApplicationCommandOptionType.Integer, required: true, max_value: 10, - min_value: 1, + min_value: -1, choices: [{ name: 'uwu', value: 1 }], }); }); @@ -128,7 +128,7 @@ describe('Application Command toJSON() results', () => { type: ApplicationCommandOptionType.Number, required: true, max_value: 10, - min_value: 1, + min_value: -1.23, }); expect(getNumberOption().setAutocomplete(true).setChoices().toJSON()).toEqual({ @@ -137,7 +137,7 @@ describe('Application Command toJSON() results', () => { type: ApplicationCommandOptionType.Number, required: true, max_value: 10, - min_value: 1, + min_value: -1.23, autocomplete: true, // @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types choices: [], @@ -149,7 +149,7 @@ describe('Application Command toJSON() results', () => { type: ApplicationCommandOptionType.Number, required: true, max_value: 10, - min_value: 1, + min_value: -1.23, choices: [{ name: 'uwu', value: 1 }], }); }); diff --git a/packages/builders/src/interactions/slashCommands/options/integer.ts b/packages/builders/src/interactions/slashCommands/options/integer.ts index 07126b6ba49b..5759a9ec1022 100644 --- a/packages/builders/src/interactions/slashCommands/options/integer.ts +++ b/packages/builders/src/interactions/slashCommands/options/integer.ts @@ -5,7 +5,7 @@ import { ApplicationCommandNumericOptionMinMaxValueMixin } from '../mixins/Appli import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase'; import { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin'; -const numberValidator = z.number().int().nonnegative(); +const numberValidator = z.number().int(); @mix(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin) export class SlashCommandIntegerOption diff --git a/packages/builders/src/interactions/slashCommands/options/number.ts b/packages/builders/src/interactions/slashCommands/options/number.ts index b88ce33f5baa..cc55ced5bbfd 100644 --- a/packages/builders/src/interactions/slashCommands/options/number.ts +++ b/packages/builders/src/interactions/slashCommands/options/number.ts @@ -5,7 +5,7 @@ import { ApplicationCommandNumericOptionMinMaxValueMixin } from '../mixins/Appli import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase'; import { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin'; -const numberValidator = z.number().nonnegative(); +const numberValidator = z.number(); @mix(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin) export class SlashCommandNumberOption