galactic-bot/structure/interfaces/Argument.js
2020-05-23 03:11:05 -04:00

61 lines
2.6 KiB
JavaScript

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.requiredValue = Boolean(options.requiredValue);
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 === null ? Constants.Defaults[options.type] : options.default;
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.options = options.options || [];
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: 'wh',
INTEGER: 0,
FLOAT: 0,
BOOLEAN: true
},
Types: [
'STRING',
'INTEGER',
'FLOAT',
'BOOLEAN',
'MEMBER',
'CHANNEL'
],
ArgumentTypes: [
'FLAG',
'VERBAL'
]
};