forked from Konard/vk-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgreet-friends.js
29 lines (27 loc) · 1002 Bytes
/
greet-friends.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
const { VK } = require('vk-io');
const { executeTrigger } = require('./utils');
const { trigger: greetingTrigger } = require('./triggers/greeting');
const { randomInRange, handleOutgoingMessage, enqueueMessage, queue } = require('./outgoing-messages');
const fs = require('fs');
const token = fs.readFileSync('token', 'utf-8').trim();
const vk = new VK({ token });
const { trigger } = require('./triggers/greet-friends');
const maxGreetings = Number(process.argv[2]) || 0;
if (maxGreetings > 0) {
let finished = false;
executeTrigger(trigger, { vk, options: { maxGreetings } }).then(() => {
finished = true
}).catch((e) => {
finished = true;
console.error(e);
});
const messagesHandlerInterval = setInterval(handleOutgoingMessage, 1000);
const finalizerInterval = setInterval(() => {
if (finished && queue.length == 0) {
setTimeout(() => {
clearInterval(messagesHandlerInterval);
}, 10000);
clearInterval(finalizerInterval);
}
}, 1000);
}