FUCK MY COMMAND HANDLER
This commit is contained in:
parent
c3490572d0
commit
e5ed7298af
@ -167,10 +167,6 @@ class CommandHandler extends Observer {
|
||||
let currentArgument = null;
|
||||
for(let i=0; i<args.length; i++) {
|
||||
const word = args[i];
|
||||
if(debug) {
|
||||
console.log("parsing word", word)
|
||||
console.log("parsing word value", currentArgument?.value);
|
||||
}
|
||||
if(!word) continue;
|
||||
const [one,two,...chars] = word.split('');
|
||||
if(one === '-' && two !== '-') {
|
||||
@ -236,9 +232,8 @@ class CommandHandler extends Observer {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const value = match[1] || match[3];
|
||||
if(debug) console.log("type parsing", currentArgument.name, value)
|
||||
const error = await this._handleTypeParsing(currentArgument, value, guild);
|
||||
const value = match[1] || match[3] || null;
|
||||
const error = await this._handleTypeParsing(currentArgument, value, guild); //CULPRIT
|
||||
if(value) {
|
||||
if(error) {
|
||||
if(currentArgument.required) {
|
||||
@ -260,12 +255,10 @@ class CommandHandler extends Observer {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if(debug) console.log("whattttttttttttttt");
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if(currentArgument) {
|
||||
if(debug) console.log(word);
|
||||
const error = await this._handleTypeParsing(currentArgument, word, guild);
|
||||
if(error) {
|
||||
if(currentArgument.default !== null) {
|
||||
@ -324,7 +317,7 @@ class CommandHandler extends Observer {
|
||||
|
||||
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];
|
||||
if(missingArgument) return {
|
||||
error: true,
|
||||
@ -346,7 +339,7 @@ class CommandHandler extends Observer {
|
||||
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".
|
||||
if(error) return { error: true };
|
||||
if(error || value === null) return { error: true };
|
||||
|
||||
if(['INTEGER', 'FLOAT'].includes(argument.type)) {
|
||||
const { min, max } = argument;
|
||||
@ -376,12 +369,11 @@ class CommandHandler extends Observer {
|
||||
};
|
||||
|
||||
const { error, value } = await parse(argument, string, guild);
|
||||
if(error || value === '') return true;
|
||||
|
||||
if(!error && (value !== undefined || value !== '')) {
|
||||
argument.infinite
|
||||
? argument.value.push(value)
|
||||
: argument.value = value;
|
||||
}
|
||||
argument.infinite
|
||||
? argument.value.push(value)
|
||||
: argument.value = value;
|
||||
|
||||
return error;
|
||||
|
||||
@ -498,7 +490,7 @@ class CommandHandler extends Observer {
|
||||
|
||||
const types = {
|
||||
STRING: (str) => {
|
||||
return { error: false, value: `${str}` };
|
||||
return { error: false, value: str };
|
||||
},
|
||||
INTEGER: (str) => {
|
||||
const int = parseInt(str);
|
||||
|
@ -43,8 +43,6 @@ class Modlogs extends Setting {
|
||||
async handle(message, args) {
|
||||
|
||||
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 || { };
|
||||
|
||||
if (parsedArguments.exclude) {
|
||||
|
@ -8,7 +8,7 @@ class Argument {
|
||||
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.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 || {
|
||||
@ -20,7 +20,7 @@ class Argument {
|
||||
|
||||
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.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!!!
|
||||
|
||||
@ -41,7 +41,7 @@ module.exports = Argument;
|
||||
|
||||
const Constants = {
|
||||
Defaults: { //these dont really mean anything, just default values. Most important one is the boolean one.
|
||||
STRING: '',
|
||||
STRING: 'wh',
|
||||
INTEGER: 0,
|
||||
FLOAT: 0,
|
||||
BOOLEAN: true
|
||||
|
Loading…
Reference in New Issue
Block a user