var chat_id 59 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
51
52
53
54
55
56
57
58
59
60
61
var chat_id=59;
var my_id=334636316;
var autoleave=true;
var whitelist = [
3988342,// #борнев
16143988, //#федя
27993175, //#шкиль
76260793, //#щукин
158492635,// #дима
98287420, //#vovk
53191219, //#юнир
36703934, //#kochka
23351039,// #тяпкинг
14928775,// #егорка
17835169,// #наташа
];
if (autoleave == true) {
API.messages.addChatUser({"chat_id": chat_id, "user_id" : my_id});
}
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};
}