mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-04 22:16:08 +00:00
fix: message command choices
This commit is contained in:
parent
c6bd0f77e2
commit
6a63178846
@ -322,82 +322,30 @@ async function parseOptions(
|
|||||||
{
|
{
|
||||||
value = args[i.name];
|
value = args[i.name];
|
||||||
const option = i as SeyfertStringOption;
|
const option = i as SeyfertStringOption;
|
||||||
if (value) {
|
if (!value) break;
|
||||||
if (option.min_length) {
|
if (option.min_length) {
|
||||||
if (value.length < option.min_length) {
|
if (value.length < option.min_length) {
|
||||||
value = undefined;
|
|
||||||
errors.push({
|
|
||||||
name: i.name,
|
|
||||||
error: `The entered string has less than ${option.min_length} characters. The minimum required is ${option.min_length} characters.`,
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (option.max_length) {
|
|
||||||
if (value.length > option.max_length) {
|
|
||||||
value = undefined;
|
|
||||||
errors.push({
|
|
||||||
name: i.name,
|
|
||||||
error: `The entered string has more than ${option.max_length} characters. The maximum required is ${option.max_length} characters.`,
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (option.choices?.length) {
|
|
||||||
if (!option.choices.some(x => x.name === value)) {
|
|
||||||
value = undefined;
|
|
||||||
errors.push({
|
|
||||||
name: i.name,
|
|
||||||
error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
|
|
||||||
.map(x => x.name)
|
|
||||||
.join(', ')}.`,
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
value = option.choices.find(x => x.name === value)!.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ApplicationCommandOptionType.Number:
|
|
||||||
case ApplicationCommandOptionType.Integer:
|
|
||||||
{
|
|
||||||
value = Number(args[i.name]);
|
|
||||||
if (args[i.name] === undefined) {
|
|
||||||
value = undefined;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (Number.isNaN(value)) {
|
|
||||||
value = undefined;
|
|
||||||
errors.push({
|
|
||||||
name: i.name,
|
|
||||||
error: 'The entered choice is an invalid number.',
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
const option = i as SeyfertNumberOption | SeyfertIntegerOption;
|
|
||||||
if (option.min_value) {
|
|
||||||
if (value < option.min_value) {
|
|
||||||
value = undefined;
|
value = undefined;
|
||||||
errors.push({
|
errors.push({
|
||||||
name: i.name,
|
name: i.name,
|
||||||
error: `The entered number is less than ${option.min_value}. The minimum allowed is ${option.min_value}`,
|
error: `The entered string has less than ${option.min_length} characters. The minimum required is ${option.min_length} characters.`,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (option.max_value) {
|
if (option.max_length) {
|
||||||
if (value > option.max_value) {
|
if (value.length > option.max_length) {
|
||||||
value = undefined;
|
value = undefined;
|
||||||
errors.push({
|
errors.push({
|
||||||
name: i.name,
|
name: i.name,
|
||||||
error: `The entered number is greater than ${option.max_value}. The maximum allowed is ${option.max_value}`,
|
error: `The entered string has more than ${option.max_length} characters. The maximum required is ${option.max_length} characters.`,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (option.choices?.length) {
|
if (option.choices?.length) {
|
||||||
if (!option.choices.some(x => x.name === value)) {
|
const choice = option.choices.find(x => x.name === value);
|
||||||
|
if (!choice) {
|
||||||
value = undefined;
|
value = undefined;
|
||||||
errors.push({
|
errors.push({
|
||||||
name: i.name,
|
name: i.name,
|
||||||
@ -407,10 +355,64 @@ async function parseOptions(
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
value = option.choices.find(x => x.name === value)!.value;
|
value = choice.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ApplicationCommandOptionType.Number:
|
||||||
|
case ApplicationCommandOptionType.Integer:
|
||||||
|
{
|
||||||
|
const option = i as SeyfertNumberOption | SeyfertIntegerOption;
|
||||||
|
if (!option.choices?.length) {
|
||||||
|
value = Number(args[i.name]);
|
||||||
|
if (args[i.name] === undefined) {
|
||||||
|
value = undefined;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (Number.isNaN(value)) {
|
||||||
|
value = undefined;
|
||||||
|
errors.push({
|
||||||
|
name: i.name,
|
||||||
|
error: 'The entered choice is an invalid number.',
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (option.min_value) {
|
||||||
|
if (value < option.min_value) {
|
||||||
|
value = undefined;
|
||||||
|
errors.push({
|
||||||
|
name: i.name,
|
||||||
|
error: `The entered number is less than ${option.min_value}. The minimum allowed is ${option.min_value}`,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (option.max_value) {
|
||||||
|
if (value > option.max_value) {
|
||||||
|
value = undefined;
|
||||||
|
errors.push({
|
||||||
|
name: i.name,
|
||||||
|
error: `The entered number is greater than ${option.max_value}. The maximum allowed is ${option.max_value}`,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const choice = option.choices.find(x => x.name === args[i.name]);
|
||||||
|
if (!choice) {
|
||||||
|
value = undefined;
|
||||||
|
errors.push({
|
||||||
|
name: i.name,
|
||||||
|
error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
|
||||||
|
.map(x => x.name)
|
||||||
|
.join(', ')}.`,
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
value = choice.value;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user