forked from fengnz/fengdoorbot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAutomated.js
52 lines (43 loc) · 1.89 KB
/
Automated.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// 可以使用谷歌代码触发器每隔一段时间调用这个函数清除没有验证的过期用户
function removePendingUsers() {
var find = {
"status": "pending",
};
var findString = JSON.stringify(find);
var members = mongo.get(Const.memberColl, "filter=" + findString);
for (var i = 0; i < members.length; i++) {
var member = members[i];
//based on the gap between now and member join date, we decided whether need to add the kick payload
var pending_time = Date.now() / 1000 - member.date;
if (pending_time > member.timeout && member.timeout != 0) {
// The user will be kicked and ban for 1 minute
var kickPayload = {
"method": "kickChatMember",
"chat_id": member.chat.id,
"user_id": member.user.id,
"until_date": Date.now() / 1000 + 60,
};
var res = postTelegram(kickPayload);
if (res.ok) {
var data = { status: "kicked" };
var setData = { "$set": data };
mongo.setOne(Const.memberColl + "/" + member._id.$oid, setData);
if (member.message) {
var deleteAskVerifyPayload = {
"method": "deleteMessage",
"message_id": member.message.message_id,
"chat_id": member.chat.id,
};
postTelegram(deleteAskVerifyPayload);
}
} else {
var data = { status: "error" };
if (res.description) {
data.error_description = res.description;
}
var setData = { "$set": data };
mongo.setOne(Const.memberColl + "/" + member._id.$oid, setData);
}
}
}
}