forked from mullwar/telebot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregExpMessage.js
More file actions
34 lines (24 loc) · 761 Bytes
/
regExpMessage.js
File metadata and controls
34 lines (24 loc) · 761 Bytes
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
/*
Adds RegExp support to text event messages.
*/
module.exports = {
id: 'regExpMessage',
plugin(bot) {
bot.mod('text', (data) => {
const {message, props} = data;
const text = message.text;
let promise = Promise.resolve();
for (let eventType of bot.eventList.keys()) {
if (eventType instanceof RegExp) {
const match = text.match(eventType);
if (match) {
props.match = match;
promise = promise.then(() => bot.event(eventType, message, props));
}
}
}
data.promise = promise;
return data;
});
}
};