forked from Konard/vk-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequests.js
30 lines (26 loc) · 1.02 KB
/
requests.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
const { VK } = require('vk-io');
const token = require('fs').readFileSync('token', 'utf-8').trim();
const vk = new VK({ token });
const requestsLimit = 10000; // Maximum number of requests you expect
const requestsSegmentSize = 1000; // Number of requests fetched per segment
async function fetchRequests(segment, offset) {
const req = await vk.api.friends.getRequests({ out: 1, count: segment, offset: offset });
return req || [];
}
async function fetchAllRequests() {
let requests = [];
for (let offset = 0; offset < requestsLimit; offset += requestsSegmentSize) {
const segment = await fetchRequests(requestsSegmentSize, offset);
requests = requests.concat(segment.items);
if (segment.items.length < requestsSegmentSize) {
// Early exit if we fetched less requests than requested: end of data.
break;
}
}
return requests;
}
fetchAllRequests().then(requests => {
console.log('Total requests: ', requests.length);
console.log('Total requests: ', requests);
//do something with all the requests
});