Compare commits

...

2 Commits

Author SHA1 Message Date
Peery 5d18c804c5 Implemented error suggestions
If no known command is given. It replies with a list of most likely commands.
7 years ago
Peery 915074fa73 Fixed export of methods in commands.js 7 years ago

@ -51,6 +51,9 @@ function fetchCommand(input, commands, threshhold){
return candidates;
}
module.exports.fetchCommand = fetchCommand;
module.exports.getEditDistance = getEditDistance;
/* //Test code
const commands = {};
commands['homeserver'] = {};

@ -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);
}
});