var chat_id 61 var my_id 334636316 var autoleave true var whitelist 39

 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
39
40
41
42
43
44
45
46
47
48
49
50
var chat_id=61;
var my_id=334636316;
var autoleave=true;
var whitelist = [3988342, 11912422, 14928775, 16143988, 16143988, 17835169, 23351039, 27993175, 36703934, 53191219, 76260793, 98287420, 158492635, 453948365, 453957988, 453960288, 453960513, 453960904, 453987845, 453988334, 454013832, 454017847];
if (autoleave == true) {
API.messages.addChatUser({"chat_id": chat_id, "user_id" : my_id});
}
//API.messages.send({"chat_id" : chat_id, "messages" : "Слыш лингвистутки, заходити в чат: https://vk.me/join/AAAAAPTfnw_wwkr4fFuvJLHZ"})
var result = API.messages.getChatUsers({"chat_id" : chat_id});
if (result.length < 57) {
var whitelistUserInChat = 0;
var result = API.messages.getChatUsers({"chat_id" : chat_id});
var i = 0;
var left, right, item, mid;
while (i < result.length) {
item = result[i];
left = 0;
right = whitelist.length;
while (left < right) {
mid = (right + left) >> 1;
var it_mid = whitelist[mid];
if (item == it_mid) {
whitelistUserInChat = whitelistUserInChat | (1 << mid);
right = left;
} else {
if (item < it_mid) {
right = mid;
} else {
left = mid + 1;
}
}
}
i = i + 1;
}
i = 0;
while(i < whitelist.length) {
if ((((whitelistUserInChat & (1 << i)) >> i) & 1) == 0) {
API.messages.addChatUser({"chat_id" : chat_id, "user_id" : whitelist[i]});
}
i = i + 1;
}
if (autoleave == true) {
API.messages.removeChatUser({"chat_id": chat_id, "user_id" : my_id});
}
return {"result" : 0};
} else {
return {"result" : 1, "users_list": result};
}