FUCK MY COMMAND HANDLER

This commit is contained in:
nolan 2020-05-23 03:11:05 -04:00
parent c3490572d0
commit e5ed7298af
3 changed files with 12 additions and 22 deletions

View File

@ -167,10 +167,6 @@ class CommandHandler extends Observer {
let currentArgument = null; let currentArgument = null;
for(let i=0; i<args.length; i++) { for(let i=0; i<args.length; i++) {
const word = args[i]; const word = args[i];
if(debug) {
console.log("parsing word", word)
console.log("parsing word value", currentArgument?.value);
}
if(!word) continue; if(!word) continue;
const [one,two,...chars] = word.split(''); const [one,two,...chars] = word.split('');
if(one === '-' && two !== '-') { if(one === '-' && two !== '-') {
@ -236,9 +232,8 @@ class CommandHandler extends Observer {
continue; continue;
} }
} }
const value = match[1] || match[3]; const value = match[1] || match[3] || null;
if(debug) console.log("type parsing", currentArgument.name, value) const error = await this._handleTypeParsing(currentArgument, value, guild); //CULPRIT
const error = await this._handleTypeParsing(currentArgument, value, guild);
if(value) { if(value) {
if(error) { if(error) {
if(currentArgument.required) { if(currentArgument.required) {
@ -260,12 +255,10 @@ class CommandHandler extends Observer {
continue; continue;
} }
} else { } else {
if(debug) console.log("whattttttttttttttt");
continue; continue;
} }
} else { } else {
if(currentArgument) { if(currentArgument) {
if(debug) console.log(word);
const error = await this._handleTypeParsing(currentArgument, word, guild); const error = await this._handleTypeParsing(currentArgument, word, guild);
if(error) { if(error) {
if(currentArgument.default !== null) { if(currentArgument.default !== null) {
@ -324,7 +317,7 @@ class CommandHandler extends Observer {
if(currentArgument) parsedArguments.push(currentArgument); if(currentArgument) parsedArguments.push(currentArgument);
const blah = parsedArguments.filter(a=>a.requiredArgument && !a.value); const blah = parsedArguments.filter(a=>a.requiredArgument && !a.value); //check if array, too lazy.
const missingArgument = blah[0]; const missingArgument = blah[0];
if(missingArgument) return { if(missingArgument) return {
error: true, error: true,
@ -346,7 +339,7 @@ class CommandHandler extends Observer {
const parse = async (argument, string, guild) => { const parse = async (argument, string, guild) => {
const { error, value } = await this.constructor.parseType(argument.type, string, this.client.resolver, guild); //Cannot access static functions through "this". const { error, value } = await this.constructor.parseType(argument.type, string, this.client.resolver, guild); //Cannot access static functions through "this".
if(error) return { error: true }; if(error || value === null) return { error: true };
if(['INTEGER', 'FLOAT'].includes(argument.type)) { if(['INTEGER', 'FLOAT'].includes(argument.type)) {
const { min, max } = argument; const { min, max } = argument;
@ -376,12 +369,11 @@ class CommandHandler extends Observer {
}; };
const { error, value } = await parse(argument, string, guild); const { error, value } = await parse(argument, string, guild);
if(error || value === '') return true;
if(!error && (value !== undefined || value !== '')) { argument.infinite
argument.infinite ? argument.value.push(value)
? argument.value.push(value) : argument.value = value;
: argument.value = value;
}
return error; return error;
@ -498,7 +490,7 @@ class CommandHandler extends Observer {
const types = { const types = {
STRING: (str) => { STRING: (str) => {
return { error: false, value: `${str}` }; return { error: false, value: str };
}, },
INTEGER: (str) => { INTEGER: (str) => {
const int = parseInt(str); const int = parseInt(str);

View File

@ -43,8 +43,6 @@ class Modlogs extends Setting {
async handle(message, args) { async handle(message, args) {
const { params, parsedArguments } = await this._parseArguments(args, message.guild, true); const { params, parsedArguments } = await this._parseArguments(args, message.guild, true);
console.log(params)
console.log(Object.values(parsedArguments).map(a=>`${a.name} - ${a.value}`));
let setting = message.guild._settings.modlogs || { }; let setting = message.guild._settings.modlogs || { };
if (parsedArguments.exclude) { if (parsedArguments.exclude) {

View File

@ -8,7 +8,7 @@ class Argument {
this.description = options.description; 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.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.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.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 || { this.prompts = options.prompts || {
@ -20,7 +20,7 @@ class Argument {
this.requiredValue = Boolean(options.requiredValue); 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.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.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. 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!!! // Will turn value into an array instead of a string!!!
@ -41,7 +41,7 @@ module.exports = Argument;
const Constants = { const Constants = {
Defaults: { //these dont really mean anything, just default values. Most important one is the boolean one. Defaults: { //these dont really mean anything, just default values. Most important one is the boolean one.
STRING: '', STRING: 'wh',
INTEGER: 0, INTEGER: 0,
FLOAT: 0, FLOAT: 0,
BOOLEAN: true BOOLEAN: true