|
|
|
@ -78,6 +78,42 @@ const findShortcut = (shortcut, objects) => {
|
|
|
|
|
return expansion;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const expandCommand = (msg, projects) => {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const regex = /^!([a-zA-Z0-9]+) ([a-zA-Z0-9]+) ([a-zA-Z0-9]+) ?(.*)$/;
|
|
|
|
|
const shortcuts = msg.match(regex);
|
|
|
|
|
|
|
|
|
|
const expansion = {};
|
|
|
|
|
|
|
|
|
|
expansion.project = findShortcut(shortcuts[1], projects);
|
|
|
|
|
if(expansion.project) {
|
|
|
|
|
expansion.project = expansion.project.toLowerCase();
|
|
|
|
|
} else {
|
|
|
|
|
reject('could not resolve project: ' + shortcuts[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expansion.service = findShortcut(shortcuts[2], projects[expansion.project]);
|
|
|
|
|
if(expansion.service) {
|
|
|
|
|
expansion.service = expansion.service.toLowerCase();
|
|
|
|
|
} else {
|
|
|
|
|
reject('could not resolve service: ' + shortcuts[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expansion.subcommand = findShortcut(shortcuts[3], projects[expansion.project][expansion.service]);
|
|
|
|
|
if(expansion.subcommand) {
|
|
|
|
|
expansion.subcommand = expansion.subcommand.toLowerCase();
|
|
|
|
|
} else {
|
|
|
|
|
reject('could not resolve subcommand: ' + shortcuts[4]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if args are given, write them in command
|
|
|
|
|
if(shortcuts[4]) expansion.args = shortcuts[4];
|
|
|
|
|
|
|
|
|
|
resolve(expansion);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commands.projects = {}
|
|
|
|
|
fs.readdirSync('./projects').forEach((file) => {
|
|
|
|
|
let project = file.match(/^([a-z]*)\.js$/);
|
|
|
|
@ -90,6 +126,7 @@ fs.readdirSync('./projects').forEach((file) => {
|
|
|
|
|
commands.projects[project] = require('./projects/' + file);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* //Test code
|
|
|
|
|
const commands = {};
|
|
|
|
|
commands['homeserver'] = {};
|
|
|
|
@ -110,3 +147,12 @@ commands['imninja']['register'].exec = (args) => {
|
|
|
|
|
console.log(fetchCommand("inminja", commands)); // -> imninja
|
|
|
|
|
console.log(fetchCommand("34C21", commands, 4)); // -> {}*/
|
|
|
|
|
//console.log(getEditDistance("saturday", "sunday")); //should be 3
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
expandCommand('!lubi infra reb saeifsaef', commands.projects)
|
|
|
|
|
.then((success) => {
|
|
|
|
|
console.log(success);
|
|
|
|
|
}, (fail) => {
|
|
|
|
|
console.log(fail);
|
|
|
|
|
});
|
|
|
|
|
*/
|