diff --git a/Logger.js b/Logger.js index 642bf91..5e56eaf 100644 --- a/Logger.js +++ b/Logger.js @@ -9,15 +9,15 @@ class Logger { this.logger = winston.createLogger({ transports: [ new winston.transports.Console(), - new winston.transports.File({ filename: `${Date.now()}.log` }), - new winston.transports.File({ filename: `${Date.now()}-error.log`, level: 'error' }) + new winston.transports.File({ filename: `logs/${this.date}.log` }), + new winston.transports.File({ filename: `logs/${this.date}-error.log`, level: 'error' }) ] }); } get date() { - return moment().format("MM/DD/YYYY hh:mm:ss"); + return moment().format("MM-DD-YYYY-hh:mm:ss"); } } diff --git a/structure/client/components/observers/CommandHandler.js b/structure/client/components/observers/CommandHandler.js index a4f146f..51ebf05 100644 --- a/structure/client/components/observers/CommandHandler.js +++ b/structure/client/components/observers/CommandHandler.js @@ -19,8 +19,6 @@ class CommandHandler extends Observer { ['message', this.handleMessage.bind(this)] ]; - this.commandPatterns = new Map(); - } @@ -123,25 +121,34 @@ class CommandHandler extends Observer { const command = message.command; let parsedArguments = []; - const flags = {}; + const parsedFlags = {}; const { shortFlags, longFlags, keys } = await this._createFlags(command.arguments); - - - console.log(shortFlags, longFlags, keys); - message.channel.send(keys); - - let currentFlag = null; + let currentArgument = null; for(const word of args) { - // if(currentFlag) - for(const key of keys) { - const regex = new RegExp('/[0-9]*([a-zA-Z]+)[0-9]*/g', 'g'); - const match = regex.exec(word); - console.log(match); - if(!match) continue; - + if(currentArgument) { + //what } + const [one,two,...chars] = word.split(''); + if(one === '-' && two !== '-') { //short flag maybe? + const name = [ two, ...chars ].join(''); + currentArgument = shortFlags[name]; + if(!currentArgument) continue; + } else if(one === '-' && two === '-') { //long flag maybe? + const name = chars.join(''); + currentArgument = longFlags[name]; + if(!currentArgument) continue; + } else { //verbal argument + const regex = new RegExp('([0-9]*)([a-zA-Z]+)([0-9]*)', 'g'); + let match = regex.exec(word); + if(!match) continue; + currentArgument = longFlags[match[2]]; + if(!currentArgument) continue; + const value = match[1] || match[3]; + console.log(currentArgument); + } + } } @@ -159,7 +166,7 @@ class CommandHandler extends Observer { keys = [...keys, ...names]; for(const name of names) { - longFlags[name] = arg.name; + longFlags[name] = arg; if(!arg.types.includes('FLAG')) continue; @@ -171,7 +178,7 @@ class CommandHandler extends Observer { keys.push(letter); letters.push(letter); - shortFlags[letter] = arg.name; + shortFlags[letter] = arg; } } diff --git a/structure/interfaces/Argument.js b/structure/interfaces/Argument.js index 962051a..279e0cd 100644 --- a/structure/interfaces/Argument.js +++ b/structure/interfaces/Argument.js @@ -29,6 +29,9 @@ class Argument { this.parser = options.parser || null; //Option to pass a function to verify values. + this.value = null; //The value provided to the flag; assigned in the command handler. + + }