command handler changes
This commit is contained in:
parent
8116a5a004
commit
7f88d8e09f
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user