Command handler

This commit is contained in:
ahoZiorce
2018-07-01 16:35:40 +02:00
parent 8dd3ad81ae
commit 2143cb5f41

17
src/commandHandler.js Normal file
View File

@@ -0,0 +1,17 @@
let commands = {};
exports.endpoint = function endpoint (match, handler) {
commands[match] = handler;
};
exports.apply = function apply (command) {
let keys = Object.keys(commands);
for (let i = 0; i < keys.length; i++) {
let match = command.match(keys[i]);
if (match) {
commands[keys[i]](match);
return true;
}
}
return false;
};