forked from infernal1200/Virus-Tg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin.lua
302 lines (290 loc) · 9.19 KB
/
admin.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
local function set_bot_photo(msg, success, result)
local receiver = get_receiver(msg)
if success then
local file = 'data/photos/bot.jpg'
print('File downloaded to:', result)
os.rename(result, file)
print('File moved to:', file)
set_profile_photo(file, ok_cb, false)
send_large_msg(receiver, 'Photo changed!', ok_cb, false)
redis:del("bot:photo")
else
print('Error downloading: '..msg.id)
send_large_msg(receiver, 'Failed, please try again!', ok_cb, false)
end
end
--Function to add log supergroup
local function logadd(msg)
local data = load_data(_config.moderation.data)
local receiver = get_receiver(msg)
local GBan_log = 'GBan_log'
if not data[tostring(GBan_log)] then
data[tostring(GBan_log)] = {}
save_data(_config.moderation.data, data)
end
data[tostring(GBan_log)][tostring(msg.to.id)] = msg.to.peer_id
save_data(_config.moderation.data, data)
local text = 'Log_SuperGroup has has been set!'
reply_msg(msg.id,text,ok_cb,false)
return
end
--Function to remove log supergroup
local function logrem(msg)
local data = load_data(_config.moderation.data)
local receiver = get_receiver(msg)
local GBan_log = 'GBan_log'
if not data[tostring(GBan_log)] then
data[tostring(GBan_log)] = nil
save_data(_config.moderation.data, data)
end
data[tostring(GBan_log)][tostring(msg.to.id)] = nil
save_data(_config.moderation.data, data)
local text = 'Log_SuperGroup has has been removed!'
reply_msg(msg.id,text,ok_cb,false)
return
end
local function parsed_url(link)
local parsed_link = URL.parse(link)
local parsed_path = URL.parse_path(parsed_link.path)
return parsed_path[2]
end
local function get_contact_list_callback (cb_extra, success, result)
local text = " "
for k,v in pairs(result) do
if v.print_name and v.id and v.phone then
text = text..string.gsub(v.print_name , "_" , " ").." ["..v.id.."] = "..v.phone.."\n"
end
end
local file = io.open("contact_list.txt", "w")
file:write(text)
file:flush()
file:close()
send_document("user#id"..cb_extra.target,"contact_list.txt", ok_cb, false)--.txt format
local file = io.open("contact_list.json", "w")
file:write(json:encode_pretty(result))
file:flush()
file:close()
send_document("user#id"..cb_extra.target,"contact_list.json", ok_cb, false)--json format
end
local function get_dialog_list_callback(cb_extra, success, result)
local text = ""
for k,v in pairsByKeys(result) do
if v.peer then
if v.peer.type == "chat" then
text = text.."group{"..v.peer.title.."}["..v.peer.id.."]("..v.peer.members_num..")"
else
if v.peer.print_name and v.peer.id then
text = text.."user{"..v.peer.print_name.."}["..v.peer.id.."]"
end
if v.peer.username then
text = text.."("..v.peer.username..")"
end
if v.peer.phone then
text = text.."'"..v.peer.phone.."'"
end
end
end
if v.message then
text = text..'\nlast msg >\nmsg id = '..v.message.id
if v.message.text then
text = text .. "\n text = "..v.message.text
end
if v.message.action then
text = text.."\n"..serpent.block(v.message.action, {comment=false})
end
if v.message.from then
if v.message.from.print_name then
text = text.."\n From > \n"..string.gsub(v.message.from.print_name, "_"," ").."["..v.message.from.id.."]"
end
if v.message.from.username then
text = text.."( "..v.message.from.username.." )"
end
if v.message.from.phone then
text = text.."' "..v.message.from.phone.." '"
end
end
end
text = text.."\n\n"
end
local file = io.open("dialog_list.txt", "w")
file:write(text)
file:flush()
file:close()
send_document("user#id"..cb_extra.target,"dialog_list.txt", ok_cb, false)--.txt format
local file = io.open("dialog_list.json", "w")
file:write(json:encode_pretty(result))
file:flush()
file:close()
send_document("user#id"..cb_extra.target,"dialog_list.json", ok_cb, false)--json format
end
-- Returns the key (index) in the config.enabled_plugins table
local function plugin_enabled( name )
for k,v in pairs(_config.enabled_plugins) do
if name == v then
return k
end
end
-- If not found
return false
end
-- Returns true if file exists in plugins folder
local function plugin_exists( name )
for k,v in pairs(plugins_names()) do
if name..'.lua' == v then
return true
end
end
return false
end
local function reload_plugins( )
plugins = {}
return load_plugins()
end
local function run(msg,matches)
local receiver = get_receiver(msg)
local group = msg.to.id
local print_name = user_print_name(msg.from):gsub("", "")
local name_log = print_name:gsub("_", " ")
if not is_admin1(msg) then
return
end
if msg.media then
if msg.media.type == 'photo' and redis:get("bot:photo") then
if redis:get("bot:photo") == 'waiting' then
load_photo(msg.id, set_bot_photo, msg)
end
end
end
if matches[1] == "setbotphoto" then
redis:set("bot:photo", "waiting")
return 'Please send me bot photo now'
end
if matches[1] == "markread" then
if matches[2] == "on" then
redis:set("bot:markread", "on")
return "Mark read > on"
end
if matches[2] == "off" then
redis:del("bot:markread")
return "Mark read > off"
end
return
end
if matches[1] == "pm" then
send_large_msg("user#id"..matches[2],matches[3])
return "Msg sent"
end
if matches[1] == "pmblock" then
if is_admin2(matches[2]) then
return "You can't block admins"
end
block_user("user#id"..matches[2],ok_cb,false)
return "User blocked"
end
if matches[1] == "pmunblock" then
unblock_user("user#id"..matches[2],ok_cb,false)
return "User unblocked"
end
if matches[1] == "import" then--join by group link
local hash = parsed_url(matches[2])
import_chat_link(hash,ok_cb,false)
end
if matches[1] == "contactlist" then
if not is_sudo(msg) then-- Sudo only
return
end
get_contact_list(get_contact_list_callback, {target = msg.from.id})
return "I've sent contact list with both json and text format to your private"
end
if matches[1] == "delcontact" then
if not is_sudo(msg) then-- Sudo only
return
end
del_contact("user#id"..matches[2],ok_cb,false)
return "User "..matches[2].." removed from contact list"
end
if matches[1] == "dialoglist" then
get_dialog_list(get_dialog_list_callback, {target = msg.from.id})
return "I've sent a group dialog list with both json and text format to your private messages"
end
if matches[1] == "whois" then
user_info("user#id"..matches[2],user_info_callback,{msg=msg})
end
if matches[1] == "sync_gbans" then
if not is_sudo(msg) then-- Sudo only
return
end
local url = "http://seedteam.org/Teleseed/Global_bans.json"
local SEED_gbans = http.request(url)
local jdat = json:decode(SEED_gbans)
for k,v in pairs(jdat) do
redis:hset('user:'..v, 'print_name', k)
banall_user(v)
print(k, v.." Globally banned")
end
end
if matches[1] == 'reload' then
receiver = get_receiver(msg)
reload_plugins(true)
post_msg(receiver, "Reloaded!", ok_cb, false)
return "Reloaded!"
end
--[[*For Debug*
if matches[1] == "vardumpmsg" and is_admin1(msg) then
local text = serpent.block(msg, {comment=false})
send_large_msg("channel#id"..msg.to.id, text)
end]]
if matches[1] == 'updateid' then
local data = load_data(_config.moderation.data)
local long_id = data[tostring(msg.to.id)]['long_id']
if not long_id then
data[tostring(msg.to.id)]['long_id'] = msg.to.peer_id
save_data(_config.moderation.data, data)
return "Updated ID"
end
end
if matches[1] == 'addlog' and not matches[2] then
if is_log_group(msg) then
return "Already a Log_SuperGroup"
end
print("Log_SuperGroup "..msg.to.title.."("..msg.to.id..") added")
savelog(msg.to.id, name_log.." ["..msg.from.id.."] added Log_SuperGroup")
logadd(msg)
end
if matches[1] == 'remlog' and not matches[2] then
if not is_log_group(msg) then
return "Not a Log_SuperGroup"
end
print("Log_SuperGroup "..msg.to.title.."("..msg.to.id..") removed")
savelog(msg.to.id, name_log.." ["..msg.from.id.."] added Log_SuperGroup")
logrem(msg)
end
return
end
local function pre_process(msg)
if not msg.text and msg.media then
msg.text = '['..msg.media.type..']'
end
return msg
end
return {
patterns = {
"^[#!/](pm) (%d+) (.*)$",
"^[#!/](import) (.*)$",
"^[#!/](pmunblock) (%d+)$",
"^[#!/](pmblock) (%d+)$",
"^[#!/](markread) (on)$",
"^[#!/](markread) (off)$",
"^[#!/](setbotphoto)$",
"^[#!/](contactlist)$",
"^[#!/](dialoglist)$",
"^[#!/](delcontact) (%d+)$",
"^[#/!](reload)$",
"^[#/!](updateid)$",
"^[#/!](addlog)$",
"^[#/!](remlog)$",
"%[(photo)%]",
},
run = run,
pre_process = pre_process
}