forked from infernal1200/Virus-Tg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwhitelist.lua
81 lines (75 loc) · 2.41 KB
/
whitelist.lua
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
do
local function get_message_callback (extra , success, result)
if result.service then
local action = result.action.type
if action == 'chat_add_user' or action == 'chat_del_user' or action == 'chat_rename' or action == 'chat_change_photo' then
if result.action.user then
user_id = result.action.user.peer_id
end
end
else
user_id = result.from.peer_id
end
local receiver = extra.receiver
local hash = "whitelist"
local is_whitelisted = redis:sismember(hash, user_id)
if is_whitelisted then
redis:srem(hash, user_id)
send_large_msg(receiver, "User/Bot ["..user_id.."] removed from whitelist")
else
redis:sadd(hash, user_id)
send_large_msg(receiver, "User/Bot ["..user_id.."] added to whitelist")
end
end
local function whitelist_res (extra, success, result)
local user_id = result.peer_id
local receiver = extra.receiver
local hash = "whitelist"
local is_whitelisted = redis:sismember(hash, user_id)
if is_whitelisted then
redis:srem(hash, user_id)
send_large_msg(receiver, "User/Bot ["..user_id.."] removed from whitelist")
else
redis:sadd(hash, user_id)
send_large_msg(receiver, "User/Bot ["..user_id.."] added to whitelist")
end
end
local function run (msg, matches)
if matches[1] == "whitelist" and is_admin1(msg) then
local hash = "whitelist"
local user_id = ""
if type(msg.reply_id) ~= "nil" then
local receiver = get_receiver(msg)
get_message(msg.reply_id, get_message_callback, {receiver = receiver})
elseif string.match(matches[2], '^%d+$') then
local user_id = matches[2]
local is_whitelisted = redis:sismember(hash, user_id)
if is_whitelisted then
redis:srem(hash, user_id)
return "User/Bot ["..user_id.."] removed from whitelist"
else
redis:sadd(hash, user_id)
return "User/Bot ["..user_id.."] added to whitelist"
end
elseif not string.match(matches[2], '^%d+$') then
local receiver = get_receiver(msg)
local username = matches[2]
local username = string.gsub(matches[2], '@', '')
resolve_username(username, whitelist_res, {receiver = receiver})
end
end
if matches[1] == "clean" and matches[2] == 'whitelist' and is_admin1(msg) then
local hash = 'whitelist'
redis:del(hash)
return "Whitelist Cleaned"
end
end
return {
patterns = {
"^[#!/](whitelist)$",
"^[#!/](whitelist) (.*)$",
"^[#!/](clean) (.*)$"
},
run = run
}
end