command handler changes

This commit is contained in:
noolaan 2020-04-11 02:10:52 -06:00
parent 8116a5a004
commit 7f88d8e09f
3 changed files with 31 additions and 21 deletions

View File

@ -9,15 +9,15 @@ class Logger {
this.logger = winston.createLogger({ this.logger = winston.createLogger({
transports: [ transports: [
new winston.transports.Console(), new winston.transports.Console(),
new winston.transports.File({ filename: `${Date.now()}.log` }), new winston.transports.File({ filename: `logs/${this.date}.log` }),
new winston.transports.File({ filename: `${Date.now()}-error.log`, level: 'error' }) new winston.transports.File({ filename: `logs/${this.date}-error.log`, level: 'error' })
] ]
}); });
} }
get date() { get date() {
return moment().format("MM/DD/YYYY hh:mm:ss"); return moment().format("MM-DD-YYYY-hh:mm:ss");
} }
} }

View File

@ -19,8 +19,6 @@ class CommandHandler extends Observer {
['message', this.handleMessage.bind(this)] ['message', this.handleMessage.bind(this)]
]; ];
this.commandPatterns = new Map();
} }
@ -123,25 +121,34 @@ class CommandHandler extends Observer {
const command = message.command; const command = message.command;
let parsedArguments = []; let parsedArguments = [];
const flags = {}; const parsedFlags = {};
const { shortFlags, longFlags, keys } = await this._createFlags(command.arguments); const { shortFlags, longFlags, keys } = await this._createFlags(command.arguments);
let currentArgument = null;
console.log(shortFlags, longFlags, keys);
message.channel.send(keys);
let currentFlag = null;
for(const word of args) { for(const word of args) {
// if(currentFlag) if(currentArgument) {
for(const key of keys) { //what
const regex = new RegExp('/[0-9]*([a-zA-Z]+)[0-9]*/g', 'g');
const match = regex.exec(word);
console.log(match);
if(!match) continue;
} }
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]; keys = [...keys, ...names];
for(const name of names) { for(const name of names) {
longFlags[name] = arg.name; longFlags[name] = arg;
if(!arg.types.includes('FLAG')) continue; if(!arg.types.includes('FLAG')) continue;
@ -171,7 +178,7 @@ class CommandHandler extends Observer {
keys.push(letter); keys.push(letter);
letters.push(letter); letters.push(letter);
shortFlags[letter] = arg.name; shortFlags[letter] = arg;
} }
} }

View File

@ -29,6 +29,9 @@ class Argument {
this.parser = options.parser || null; //Option to pass a function to verify values. 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.
} }