-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbirthdays.js
More file actions
28 lines (26 loc) · 940 Bytes
/
Copy pathbirthdays.js
File metadata and controls
28 lines (26 loc) · 940 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
const { VK } = require('vk-io');
const { getToken, executeTrigger, second, ms } = require('./utils');
const { handleOutgoingMessage, queue } = require('./outgoing-messages');
const { trigger: sendBirthDayCongratulationsTrigger } = require('./triggers/send-birthday-congratulations');
const token = getToken();
const vk = new VK({ token });
let finished = false;
executeTrigger(sendBirthDayCongratulationsTrigger, { vk }).then(() => {
finished = true
}).catch((e) => {
finished = true;
console.error(e);
});
const messagesHandlerInterval = setInterval(handleOutgoingMessage, (1 * second) / ms);
const finalizerInterval = setInterval(async () => {
if (finished && queue.length === 0) {
if (finalizerInterval) {
clearInterval(finalizerInterval);
}
setTimeout(() => {
if (messagesHandlerInterval) {
clearInterval(messagesHandlerInterval);
}
}, (5 * second) / ms);
}
}, (2 * second) / ms);