Implemented error suggestions

If no known command is given. It replies with a list of most likely commands.
develop
Peery 7 years ago
parent 915074fa73
commit 5d18c804c5

@ -2,6 +2,7 @@ const fs = require('fs');
const remoteExec = require('./remoteExec.js');
const sdk = require('matrix-js-sdk');
const yaml = require('js-yaml');
const commandUtil = require('./commands.js');
global.config = yaml.safeLoad(fs.readFileSync('config.yaml'));
const matrixClient = sdk.createClient({
@ -24,7 +25,6 @@ process.on('unhandledRejection', (reason) => {
console.log('Reason: ' + reason);
});
const commands = {};
commands['rebuild'] = {};
@ -61,7 +61,9 @@ matrixClient.on('Room.timeline', function(event, room, resetTimeline) {
}
project = project[1];
if(commands[project] !== undefined) {
let command = commands[project];
if(command !== undefined) {
const command = commands[project];
const args = body.match(command.regex);
@ -71,6 +73,14 @@ matrixClient.on('Room.timeline', function(event, room, resetTimeline) {
}
command.exec(args, room, event);
}else{ //command not found
let tmp = commandUtil.fetchCommand(project, commands);
let suggestions = "";
for(let i = 0; i < tmp.length; i++){
suggestions += "\n"+tmp[i];
}
matrixClient.sendNotice(room.roomId, 'Unrecognized command.\n' +
'Did you mean:'+suggestions);
}
});