Fixed handling of non-command messages - fixes #17

Added if's when the regex for command detection returns null and notify
the caller via either a failed promise or a null return.
master
Peery 7 years ago committed by lub
parent 56f9b0aa7b
commit 6791398588

@ -60,6 +60,10 @@ function suggestFix(msg, projects){
const shortcuts = msg.match(msgRegex);
const expansion = {};
if(shortcuts === null){
return null;
}
expansion.project = findShortcut(shortcuts[1], projects);
if(expansion.project) {
expansion.project = expansion.project.toLowerCase();
@ -110,6 +114,10 @@ commands.expandCommand = (msg, projects) => {
const shortcuts = msg.match(msgRegex);
const expansion = {};
if(shortcuts === null){
reject('No regex match.');
return;
}
expansion.project = findShortcut(shortcuts[1], projects);
if(expansion.project) {
expansion.project = expansion.project.toLowerCase();

@ -50,13 +50,14 @@ matrixClient.on('Room.timeline', function(event, room, resetTimeline) {
subcommand.exec(args, room, event);
}, (fail) => { // command not found
let tmp = commands.suggestFix(body, commands.projects);
if(tmp !== null){ //when the regex matches nothing
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);
}
});
});