mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-08 15:19:14 +02:00
Add argument invalidtext
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const UnionType = require('./UnionType');
|
||||
const { list } = require('../util/Util');
|
||||
|
||||
module.exports = class Argument {
|
||||
constructor(client, options) {
|
||||
@@ -37,4 +38,23 @@ module.exports = class Argument {
|
||||
if (this.emptyChecker) return this.emptyChecker(val, msg, arg);
|
||||
return this.type.isEmpty(val, msg, arg);
|
||||
}
|
||||
|
||||
get invalidText() {
|
||||
if (this.oneOf) {
|
||||
return `It must be one of the following: ${list(arg.oneOf, 'or')}`;
|
||||
} else if (this.max !== null && this.min !== null && (this.typeID === 'integer' || this.typeID === 'float')) {
|
||||
return `It must be a number from ${this.min} to ${this.max}.`;
|
||||
} else if (this.max !== null && this.min === null && (this.typeID === 'integer' || this.typeID === 'float')) {
|
||||
return `It must be a number less than or equal to ${this.max}.`;
|
||||
} else if (this.min !== null && this.max === null && (this.typeID === 'integer' || this.typeID === 'float')) {
|
||||
return `It must be a number greater than or equal to ${this.min}.`
|
||||
} else if (this.min !== null && this.max !== null && this.typeID === 'string') {
|
||||
return `It must be at least ${this.min} characters long and at most ${this.max} characters long.`;
|
||||
} else if (this.min !== null && this.max === null && this.typeID === 'string') {
|
||||
return `It must be at least ${this.min} characters long.`;
|
||||
} else if (this.max !== null && this.min === null && this.typeID === 'string') {
|
||||
return `It must be at most ${this.max} characters long.`;
|
||||
}
|
||||
return `It must be a ${this.typeID}.`;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const minimist = require('minimist');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { list } = require('../util/Util');
|
||||
const argRegex = /"([^"]*)"|(\S+)/g;
|
||||
|
||||
module.exports = class CommandDispatcher {
|
||||
@@ -50,7 +49,7 @@ module.exports = class CommandDispatcher {
|
||||
} else {
|
||||
return stripIndents`
|
||||
The "${arg.label || arg.key}" argument is required.
|
||||
${arg.oneOf ? `It must be one of the following: ${list(arg.oneOf, 'or')}` : ''}
|
||||
${arg.invalidText}
|
||||
`;
|
||||
}
|
||||
}
|
||||
@@ -61,7 +60,7 @@ module.exports = class CommandDispatcher {
|
||||
if (!valid || typeof valid === 'string') {
|
||||
return stripIndents`
|
||||
An invalid value was provided for one of the "${arg.label || arg.key}" arguments.
|
||||
${arg.oneOf ? `It must be one of the following: ${list(arg.oneOf, 'or')}` : ''}
|
||||
${arg.invalidText}
|
||||
`;
|
||||
}
|
||||
parsedArgs.push(await arg.parse(parsedArg, msg, arg));
|
||||
@@ -74,7 +73,7 @@ module.exports = class CommandDispatcher {
|
||||
if (arg.default === null) {
|
||||
return stripIndents`
|
||||
The "${arg.label || arg.key}" argument is required.
|
||||
${arg.oneOf ? `It must be one of the following: ${list(arg.oneOf, 'or')}` : ''}
|
||||
${arg.invalidText}
|
||||
`;
|
||||
} else {
|
||||
finalResult[arg.key] = typeof arg.default === 'function' ? arg.default(msg) : arg.default;
|
||||
@@ -85,7 +84,7 @@ module.exports = class CommandDispatcher {
|
||||
if (!valid || typeof valid === 'string') {
|
||||
return stripIndents`
|
||||
An invalid value was provided for the "${arg.label || arg.key}" argument.
|
||||
${arg.oneOf ? `It must be one of the following: ${list(arg.oneOf, 'or')}` : ''}
|
||||
${arg.invalidText}
|
||||
`;
|
||||
}
|
||||
finalResult[arg.key] = await arg.parse(parsedArg, msg, arg);
|
||||
|
||||
Reference in New Issue
Block a user