-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
39 lines (33 loc) · 972 Bytes
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const commandList = [
{ c: ['bus'], a: require('./modules/bus.js') },
];
/**
* Executes the action indicated in the message
*/
module.exports = function router(message) {
// If it does not start from "/", ignore
if (message.text.indexOf('/') !== 0) {
console.log('- Non-command received: ', message.text);
return new Promise(() => {});
}
const args = message.text.slice(1).split(' ');
const command = args[0];
const filtered = commandList.filter(cmd => cmd.c.indexOf(command) !== -1);
let promiseFunction;
if (filtered.length === 1) {
console.log('- Command: ', command);
promiseFunction = accept => {
filtered[0].a(...args.slice(1)).then(text => accept({
chat_id: message.chat.id,
text,
options: {
parse_mode: 'Markdown',
},
}));
};
} else {
console.log('- Unknown command: ', command);
promiseFunction = () => {};
}
return new Promise(promiseFunction);
};