-
Notifications
You must be signed in to change notification settings - Fork 269
/
commandButton.js
54 lines (40 loc) · 1.26 KB
/
commandButton.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Use commands in buttons.
*/
module.exports = {
id: 'commandButton',
defaultConfig: {
regExpEvents: true
},
plugin(bot, pluginConfig) {
const {regExpEvents} = pluginConfig;
bot.on('callbackQuery', (msg, props) => {
let isAnswered = false;
let promise = Promise.resolve();
const cmd = msg.data;
if (cmd.charAt(0) == '/') {
answerCallback();
promise = bot.event(cmd, msg, props);
}
if (regExpEvents) {
for (let eventName of bot.eventList.keys()) {
if (eventName instanceof RegExp) {
const match = cmd.match(eventName);
if (match) {
answerCallback();
props.match = match;
promise = promise.then(() => bot.event(eventName, msg, props));
}
}
}
}
return promise;
function answerCallback() {
if (!isAnswered) {
bot.answerCallbackQuery(msg.id);
isAnswered = true;
}
}
});
}
};