2020-06-02 12:09:28 +02:00
const Constants = {
Defaults : { //these dont really mean anything, just default values. Most important one is the boolean one.
STRING : 'this shouldnt be here' ,
INTEGER : 0 ,
FLOAT : 0 ,
BOOLEAN : true
} ,
Types : [
'STRING' ,
'INTEGER' ,
'FLOAT' ,
'BOOLEAN' ,
'MEMBER' ,
'CHANNEL' ,
'TEXTCHANNEL' ,
2020-06-04 19:59:09 +02:00
'VOICECHANNEL' ,
2020-08-09 21:53:09 +02:00
'TIME' ,
'DATE'
2020-06-02 12:09:28 +02:00
] ,
ArgumentTypes : [
'FLAG' ,
'VERBAL'
]
} ;
2020-04-09 23:08:28 +02:00
class Argument {
constructor ( client , options = { } ) {
this . client = client ;
this . name = options . name ;
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.
2020-05-23 09:11:05 +02:00
this . type = options . type && Constants . Types . includes ( options . type ) ? options . type : 'BOOLEAN' ; //What type the argument is ['STRING', 'INTEGER', 'FLOAT', 'BOOLEAN'].
2020-04-09 23:08:28 +02:00
this . types = options . types || [ 'FLAG' , 'VERBAL' ] ; //['FLAG'], ['VERBAL'], or ['FLAG', 'VERBAL']. Declares if argument can be used verbally-only, flag-only, or both.
2020-07-28 05:00:24 +02:00
this . archivable = options . archivable === undefined ? true : Boolean ( options . archivable ) ; //Displays argument in showUsage or not.
2020-04-09 23:08:28 +02:00
//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
2020-06-02 12:09:28 +02:00
this . ignoreInvalid = Boolean ( options . ignoreInvalid ) ;
2020-05-23 09:11:05 +02:00
this . default = options . default === null ? Constants . Defaults [ options . type ] : options . default ;
2020-04-09 23:08:28 +02:00
this . infinite = Boolean ( options . infinite ) ; //Accepts infinite amount of arguments e.g. -u @nolan @navy. If false, will only detect one user.
2020-04-11 12:00:53 +02:00
// Will turn value into an array instead of a string!!!
2020-04-09 23:08:28 +02:00
2020-05-08 08:50:54 +02:00
this . options = options . options || [ ] ;
2020-04-09 23:08:28 +02:00
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.
2020-04-11 12:00:53 +02:00
this . value = this . infinite ? [ ] : null ; //The value provided to the flag; assigned in the command handler.
2020-05-25 13:13:34 +02:00
this . _flag = false ; //used internally
}
2020-06-02 12:09:28 +02:00
setDefault ( guild ) {
let def = this . default ;
if ( typeof this . default === 'function' ) {
def = this . default ( guild ) ;
}
2020-05-25 13:13:34 +02:00
return this . infinite //eslint-disable-line no-return-assign
2020-06-02 12:09:28 +02:00
? this . value = [ def ]
: this . value = def ;
2020-05-25 13:13:34 +02:00
}
2020-04-11 10:10:52 +02:00
2020-05-25 13:13:34 +02:00
get empty ( ) {
return this . infinite
? this . value . length === 0
2020-07-04 12:23:10 +02:00
: this . value === null || this . value === undefined ;
2020-04-09 23:08:28 +02:00
}
}
2020-06-02 12:09:28 +02:00
module . exports = Argument ;