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.
develop
Peery 7 years ago
parent 1e93cda8de
commit df4a12fb90

@ -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);
let suggestions = "";
for(let i = 0; i < tmp.length; i++){
suggestions += "\n"+tmp[i];
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);
}
matrixClient.sendNotice(room.roomId, 'Unrecognized command.\n' +
'Did you mean:'+suggestions);
});
});