Command handler
This commit is contained in:
17
src/commandHandler.js
Normal file
17
src/commandHandler.js
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user