forked from Konard/vk-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reject-deactivated-friend-requests.js
38 lines (33 loc) · 1.31 KB
/
reject-deactivated-friend-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
31
32
33
34
35
36
37
38
const { VK } = require('vk-io');
const { readTextSync, sleep } = require('./utils');
const token = readTextSync('token').trim();
const vk = new VK({ token });
const rejectDeactivatedFriendRequests = async () => {
try {
const maxFriendRequestsCount = 1000;
const requests = await vk.api.friends.getRequests({ count: maxFriendRequestsCount, sort: 1 });
for (let userId of requests.items) {
try {
const response = await vk.api.users.get({
user_ids: [userId],
fields: ['deactivated']
});
await sleep(5000);
const deactivationStatus = response?.[0]?.deactivated;
if (deactivationStatus === 'banned' || deactivationStatus === 'deleted') {
await vk.api.friends.delete({ user_id: userId });
console.log(`Rejected friend request from banned user: ${userId}`);
await sleep(10000);
} else if(deactivationStatus) {
console.log(`User ${userId} deactivation status: ${deactivationStatus}`);
}
} catch (error) {
console.error(`Error processing user ${userId}: ${error.message}`);
}
}
console.log('All banned friend requests have been rejected.');
} catch (error) {
console.error(`Error rejecting banned friend requests: ${error.message}`);
}
};
rejectDeactivatedFriendRequests();