62 lines
2.5 KiB
JavaScript
62 lines
2.5 KiB
JavaScript
const { Util } = require('../../util');
|
|
|
|
class Argument {
|
|
|
|
constructor(client, options = {}) {
|
|
|
|
this.client = client;
|
|
|
|
this.name = options.name;
|
|
this.description = options.description;
|
|
this.aliases = options.aliases || []; //Aliases will work for both verbal and flag types. Careful for multiple aliases starting with different letters: more flags, more confusing.
|
|
|
|
this.type = (options.type && Constants.Types.includes(options.type) ? options.type : 'BOOLEAN'); //What type the argument is ['STRING', 'INTEGER', 'FLOAT', 'BOOLEAN'].
|
|
|
|
this.types = options.types || ['FLAG', 'VERBAL']; //['FLAG'], ['VERBAL'], or ['FLAG', 'VERBAL']. Declares if argument can be used verbally-only, flag-only, or both.
|
|
this.prompts = options.prompts || {
|
|
MISSING: `Argument **${this.name}** is missing and is required.`,
|
|
INVALID: `Argument **${this.name}** must be a \`${this.type}\` value.`
|
|
} //Default prompts to be replied to the user if an argument is missing or invalid.
|
|
|
|
//NOTE: Instead of telling the person the argument is missing and is required, ask them and continue the command execution afterwards. More work to do.
|
|
|
|
this.required = options.type === 'BOOLEAN' ? false : Boolean(options.required); //If the argument must be required for the command to work. Booleans
|
|
this.default = options.default || Constants.Defaults[options.type];
|
|
this.infinite = Boolean(options.infinite); //Accepts infinite amount of arguments e.g. -u @nolan @navy. If false, will only detect one user.
|
|
// Will turn value into an array instead of a string!!!
|
|
|
|
this.min = typeof options.min === 'number' ? options.min : null; //Min/max will only be used for INTEGER/FLOAT types.
|
|
this.max = typeof options.max === 'number' ? options.max : null;
|
|
|
|
this.parser = options.parser || null; //Option to pass a function to verify values.
|
|
|
|
this.value = this.infinite ? [] : null; //The value provided to the flag; assigned in the command handler.
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
module.exports = Argument;
|
|
|
|
const Constants = {
|
|
Defaults: { //these dont really mean anything, just default values. Most important one is the boolean one.
|
|
STRING: 'okay',
|
|
INTEGER: 5,
|
|
FLOAT: 2.5,
|
|
BOOLEAN: true
|
|
},
|
|
Types: [
|
|
'STRING',
|
|
'INTEGER',
|
|
'FLOAT',
|
|
'BOOLEAN',
|
|
'MEMBER',
|
|
'CHANNEL'
|
|
],
|
|
ArgumentTypes: [
|
|
'FLAG',
|
|
'VERBAL'
|
|
]
|
|
}; |