-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbot.lua
More file actions
449 lines (408 loc) · 15.3 KB
/
bot.lua
File metadata and controls
449 lines (408 loc) · 15.3 KB
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
redis = (loadfile "./redis.lua")()
redis = redis.connect('127.0.0.1', 6379)
redis:select(0)
ADMIN = 198555147--yourid
function ok_cb(extra, success, result)
end
function is_Naji(id)
if ((id == ADMIN) or redis:sismember("selfbotBOT-IDadmins",id)) then
return true
else
return false
end
end
function get_receiver(msg)
local reciver = ""
if msg.to.type == 'user' then
reciver = 'user#id'..msg.from.id
if not redis:sismember("selfbotBOT-IDusers",reciver) then
redis:sadd("selfbotBOT-IDusers",reciver)
end
elseif msg.to.type =='chat' then
reciver ='chat#id'..msg.to.id
if not redis:sismember("selfbotBOT-IDgroups",reciver) then
redis:sadd("selfbotBOT-IDgroups",reciver)
end
elseif msg.to.type == 'encr_chat' then
reciver = msg.to.print_name
elseif msg.to.type == 'channel' then
reciver = 'channel#id'..msg.to.id
if not redis:sismember("selfbotBOT-IDsupergroups",reciver) then
redis:sadd("selfbotBOT-IDsupergroups",reciver)
end
end
return reciver
end
function rem(msg)
if msg.to.type == 'user' then
reciver = 'user#id'..msg.from.id
redis:srem("selfbotBOT-IDusers",reciver)
elseif msg.to.type =='chat' then
reciver ='chat#id'..msg.to.id
redis:srem("selfbotBOT-IDgroups",reciver)
elseif msg.to.type == 'channel' then
reciver = 'channel#id'..msg.to.id
redis:srem("selfbotBOT-IDsupergroups",reciver)
end
end
function writefile(filename, input)
local file = io.open(filename, "w")
file:write(input)
file:flush()
file:close()
return true
end
function backward_msg_format(msg)
for k,name in pairs({'from', 'to'}) do
local longid = msg[name].id
msg[name].id = msg[name].peer_id
msg[name].peer_id = longid
msg[name].type = msg[name].peer_type
end
if msg.action and (msg.action.user or msg.action.link_issuer) then
local user = msg.action.user or msg.action.link_issuer
local longid = user.id
user.id = user.peer_id
user.peer_id = longid
user.type = user.peer_type
end
return msg
end
function set_bot_photo(receiver, success, result)
if success then
local file = 'botBOT-ID.jpg'
os.rename(result, file)
set_profile_photo(file, ok_cb, false)
send_msg(receiver, 'Photo changed!', ok_cb, false)
else
send_msg(receiver, 'Failed, please try again!', ok_cb, false)
end
end
function add_all_members(extra, success, result)
local receiver = extra.receiver
for k,v in pairs(result) do
if v.id then
channel_invite(receiver,"user#id"..v.id,ok_cb,false)
end
end
local users = redis:smembers("selfbotBOT-IDusers")
for i=1, #users do
channel_invite(receiver,users[i],ok_cb,false)
end
send_msg(receiver, "All Contacts Invited To Group", ok_cb, false)
end
function check_contacts(cb_extra, success, result)
local i = 0
for k,v in pairs(result) do
i = i+1
end
redis:set("selfbotBOT-IDcontacts",i)
end
function get_contacts(cb_extra, success, result)
local text = " "
for k,v in pairs(result) do
text = text..string.gsub(v.print_name , "_" , " ").." ["..v.peer_id.."] = "..v.phone.."\n\n"
end
writefile("contact_list.txt", text)
send_document(cb_extra.target,"contact_list.txt", ok_cb, false)
end
function find_link(text)
if text:match("https://telegram.me/joinchat/%S+") or text:match("https://t.me/joinchat/%S+") or text:match("https://telegram.dog/joinchat/%S+") then
local text = text:gsub("t.me", "telegram.me")
local text = text:gsub("telegram.dog", "telegram.me")
for link in text:gmatch("(https://telegram.me/joinchat/%S+)") do
if not redis:sismember("selfbotBOT-IDlinks",link) then
redis:sadd("selfbotBOT-IDlinks",link)
end
import_chat_link(link,ok_cb,false)
end
end
end
function on_msg_receive (msg)
if not started then
return
end
msg = backward_msg_format(msg)
if (not msg.to.id or not msg.from.id or msg.out or msg.to.type == 'encr_chat' or msg.unread == 0 or msg.date < (now-60) ) then
return false
end
local receiver = get_receiver(msg)
if msg.from.id == 777000 then
local c = (msg.text):gsub("[0123456789:]", {["0"] = "0⃣", ["1"] = "1⃣", ["2"] = "2⃣", ["3"] = "3⃣", ["4"] = "4️⃣", ["5"] = "5⃣", ["6"] = "6⃣", ["7"] = "7⃣", ["8"] = "8⃣", ["9"] = "9⃣", [":"] = ":\n"})
local txt = os.date("پیام ارسال شده از تلگرام در تاریخ 🗓 %Y-%m-%d 🗓 و ساعت ⏰ %X ⏰ (به وقت سرور)")
return send_msg('user#id'..ADMIN, txt.."\n\n"..c, ok_cb, false)
end
if msg.text then
local text = msg.text
if redis:get("selfbotBOT-IDlink") then
find_link(text)
end
if is_Naji(msg.from.id) then
find_link(text)
if text:match("^(!setphoto)$") and msg.reply_id then
load_photo(msg.reply_id, set_bot_photo, receiver)
elseif text:match("^(!markread) (.*)$") then
local matche = text:match("^!markread (.*)$")
if matche == "on" then
redis:set("selfbotBOT-IDmarkread", "on")
send_msg(receiver, "Mark read > on", ok_cb, false)
elseif matche == "off" then
redis:del("selfbotBOT-IDmarkread")
send_msg(receiver, "Mark read > off", ok_cb, false)
end
elseif text:match("^(!setname) (.*)") then
local matche = text:match("^!setname (.*)")
set_profile_name(matche,ok_cb, false)
send_msg(receiver, "Name changed", ok_cb, false)
elseif text:match("^(!echo) (.*)") then
local matche = text:match("^!echo (.*)")
send_msg(receiver, matche, ok_cb, false)
elseif text:match("^(!text) (%d+) (.*)") then
local matches = {text:match("^!text (%d+) (.*)")}
send_msg("user#id"..matches[1],matches[2], ok_cb, false)
send_msg(receiver, "Message has been sent", ok_cb, false)
elseif text:match("^(!help)$") then
local text =[[💢 متن راهنما BOT-ID 💢
!pm [Id] [Text]
📩 ارسال text وارد شده به فردی با id موردنظر
!bc[all|pv|gp|sgp] [text]
📤 ارسال text وارد شده به مورد خوسته شده
!fwd[all|pv|gp|sgp] {reply on msg}
📨 فروارد پیام ریپلای شده به مورد خواسته شده
!block [Id]
⚫️ بلاک کردن فرد با id وارد شده
!unblock [id]
⚪️ انبلاک کردن فرد با id وارد شده
!addcontact [phone] [FirstName] [LastName]
➕ اضافه کردن یک کانتکت
!delcontact [phone] [FirstName] [LastName]
➖ حذف کردن یک کانتکت
!sendcontact [phone] [FirstName] [LastName]
↩️ ارسال یک کانتکت
!contactlist
📄 دریافت لیست کانتکت ها
!markread [on]|[off]
🔘 روشن و خاموش کردن تیک مارک رید
!autojoin [on]|[off]
🔲 روشن و خاموش کردن شناسایی لینک و عضویت
!setphoto {on reply photo}
🌠 ست کردن پروفایل ربات
!stats
📈 دریافت آمار ربات
!status
⚙️ دریافت وضعیت ربات
!addmember
📌 اضافه کردن کانتکت های ربات به گروه
!echo [text]
🔁 برگرداندن text وارد شده
!exportlink
📦 دریافت لینک های ذخیره شده
!addcontact [on]|[off]
☑️ خاموش و روشن کردن افزودن خودکار مخاطبین
!addcontactpm [on]|[off]
🍃️ خاموش و روشن کردن پیام افزودن مخاطبین
!setpm [text]
📍تنظیم پیام ادشدن کانتکت
!addsudo [id]
👮 اضافه کردن سودو
!remsudo [id]
✖️ حذف کردن سودو
➖➖➖➖ا➖➖➖➖
"دانش بدون تکامل اخلاقی خطرناک و نابود کننده است."
➖➖➖➖ا➖➖➖➖]]
send_msg(receiver, text, ok_cb, false)
elseif text:match("^(!status)$") then
local join = redis:get("selfbotBOT-IDlink") and "✅" or "⛔️"
local add = redis:get("selfbotBOT-IDaddcontact") and "✅" or "⛔️"
local msg = redis:get("selfbotBOT-IDaddcontactpm") and "✅" or "⛔️"
local txt = redis:get("selfbotBOT-IDpm") or "اددی گلم خصوصی پیام بده"
local view = redis:get("selfbotBOT-IDmarkread") and "✅" or "⛔️"
local text = "⚜️AutoJoin : "..join.."\n👁🗨ReadMark : "..view.."\n🔰AutoAdd Sheared Contact : "..add.."\n🌟Sending Message for Sheared Contact : "..msg.."\n📨Sheared Contact Msg: 📍"..txt.." 📍"
send_msg(receiver, text, ok_cb, false)
elseif text:match("^(!autojoin) (.*)$") then
local matche = text:match("^!autojoin (.*)$")
if matche == "on" then
redis:set("selfbotBOT-IDlink", true)
send_msg(receiver, "Automatic joining is ON", ok_cb, false)
elseif matche == "off" then
redis:del("selfbotBOT-IDlink")
send_msg(receiver, "Automatic joining is OFF", ok_cb, false)
end
elseif text:match("^(!addcontact) (.*)$") then
local matche = text:match("^!addcontact (.*)$")
if matche == "on" then
redis:set("selfbotBOT-IDaddcontact", true)
send_msg(receiver, "Adding sheared contacts is ON", ok_cb, false)
elseif matche == "off" then
redis:del("selfbotBOT-IDaddcontact")
send_msg(receiver, "Adding sheared contacts is OFF", ok_cb, false)
end
elseif text:match("^(!addcontactpm) (.*)$") then
local matche = text:match("^!addcontactpm (.*)$")
if matche == "on" then
redis:set("selfbotBOT-IDaddcontactpm", true)
send_msg(receiver, "Sending msg for contacts is ON", ok_cb, false)
elseif matche == "off" then
redis:del("selfbotBOT-IDaddcontactpm")
send_msg(receiver, "Sending msg for sheared contacts is OFF", ok_cb, false)
end
elseif text:match("^(!block) (.*)$") then
local matche = text:match("^!block (.*)$")
block_user("user#id"..matche,ok_cb,false)
send_msg(receiver, "User blocked", ok_cb, false)
elseif text:match("^(!unblock) (.*)$") then
local matche = text:match("^!unblock (.*)$")
unblock_user("user#id"..matche,ok_cb,false)
send_msg(receiver, "User unblock", ok_cb, false)
elseif text:match("^(!delcontact) (.*)$") then
local matche = text:match("^!delcontact (.*)$")
del_contact("user#id"..matche,ok_cb,false)
send_msg(receiver, "User "..matche.." removed from contact list", ok_cb, false)
elseif text:match("^(!addcontact) (.*) (.*) (.*)$") then
local matches = {text:match("^(!addcontact) (.*) (.*) (.*)$")}
add_contact(matches[2], matches[3], matches[4], ok_cb, false)
send_msg(receiver, "User With Phone +"..matches[2].." has been added", ok_cb, false)
elseif text:match("^(!sendcontact) (.*) (.*) (.*)$") then
local matches = {text:match("^(!sendcontact) (.*) (.*) (.*)$")}
send_contact(receiver,matches[2], matches[3], matches[4], ok_cb, false)
elseif text:match("^(!exportlink)$") then
links = redis:smembers("selfbotBOT-IDlinks")
local text = "Group Links :\n"
for i=1,#links do
if string.len(links[i]) ~= 51 then
redis:srem("selfbotBOT-IDlinks",links[i])
else
text = text..links[i].."\n"
end
end
writefile("group_links.txt", text)
send_document(receiver,"group_links.txt",ok_cb,false)
elseif text:match("^(!contactlist)$") then
get_contact_list(get_contacts, {target = receiver})
elseif (text:match("^(!addmember)$") and msg.to.type == "channel") then
get_contact_list(add_all_members, {receiver=receiver})
elseif text:match("^(!stats)$") then
get_contact_list(check_contacts, false)
local usrs = redis:scard("selfbotBOT-IDusers")
local gps = redis:scard("selfbotBOT-IDgroups")
local sgps = redis:scard("selfbotBOT-IDsupergroups")
local links = redis:scard("selfbotBOT-IDlinks")
local con = redis:get("selfbotBOT-IDcontacts") or "مشخص نشده"
local text = "<b>👤 Users </b>: "..usrs.."\n<b>👥 Groups </b>: "..gps.."\n<b>🌐 SuperGroups </b>: "..sgps.."\n<b>📁 Total Saved Links </b>: "..links.."\n<b>💠 Total Saved Contacts </b>: "..con
send_msg(receiver, text, ok_cb, false)
elseif text:match("^(!bc)(.*) (.*)") then
local matches = {text:match("^!bc(.*) (.*)$")}
local naji = ""
if matches[1] == "all" then
local list = {redis:smembers("selfbotBOT-IDgroups"),redis:smembers("selfbotBOT-IDsupergroups"),redis:smembers("selfbotBOT-IDusers")}
for x,y in pairs(list) do
for i,v in pairs(y) do
send_msg(v,matches[2],ok_cb,false)
end
end
return send_msg(receiver, "Sended!", ok_cb, false)
elseif matches[1] == "pv" then
naji = "selfbotBOT-IDusers"
elseif matches[1] == "gp" then
naji = "selfbotBOT-IDgroups"
elseif matches[1] == "sgp" then
naji = "selfbotBOT-IDsupergroups"
else
return false
end
local list = redis:smembers(naji)
for i=1, #list do
send_msg(list[i],matches[2],ok_cb,false)
end
return send_msg(receiver, "Sended!", ok_cb, false)
elseif (text:match("^(!fwd)(.*)$") and msg.reply_id) then
local matche = text:match("^!fwd(.*)$")
local naji = ""
local id = msg.reply_id
if matche == "all" then
local list = {redis:smembers("selfbotBOT-IDgroups"),redis:smembers("selfbotBOT-IDsupergroups"),redis:smembers("selfbotBOT-IDusers")}
for x,y in pairs(list) do
for i,v in pairs(y) do
fwd_msg(v,id,ok_cb,false)
end
end
return send_msg(receiver, "Sended!", ok_cb, false)
elseif matche == "pv" then
naji = "selfbotBOT-IDusers"
elseif matche == "gp" then
naji = "selfbotBOT-IDgroups"
elseif matche == "sgp" then
naji = "selfbotBOT-IDsupergroups"
else
return false
end
local list = redis:smembers(naji)
for i=1, #list do
fwd_msg(list[i],id,ok_cb,false)
end
return send_msg(receiver, "Sended!", ok_cb, false)
elseif text:match("^(!addsudo) (%d+)$") then
if msg.from.id == ADMIN then
local matche = text:match("%d+")
if redis:sismember("selfbotBOT-IDadmins",matche) then
return send_msg(receiver, "User is a sudoer user!", ok_cb, false)
else
redis:sadd("selfbotBOT-IDadmins",matche)
return send_msg(receiver, "User "..matche.." added to sudoers", ok_cb, false)
end
else
return send_msg(receiver, "ONLY FULLACCESS SUDO", ok_cb, false)
end
elseif text:match("^(!remsudo) (%d+)$") then
if msg.from.id == ADMIN then
local matche = text:match("%d+")
if redis:sismember("selfbotBOT-IDadmins",matche) then
redis:srem("selfbotBOT-IDadmins",matche)
return send_msg(receiver, "User "..matche.." isn't sudoer user anymore!", ok_cb, false)
else
return send_msg(receiver, "User isn't sudoer user", ok_cb, false)
end
else
return send_msg(receiver, "ONLY FULLACCESS SUDO", ok_cb, false)
end
end
end
elseif msg.action then
if ((msg.action.type == "chat_del_user" and msg.to.id == 1146365116) or msg.action.type == "migrated_to") then
rem(msg)
end
elseif msg.media then
if msg.media.type == "contact" then
if redis:get("selfbotBOT-IDaddcontact") then
add_contact(msg.media.phone, ""..(msg.media.first_name or "-").."", ""..(msg.media.last_name or "-").."", ok_cb, false)
end
if redis:get("selfbotBOT-IDaddcontactpm") then
local txt = redis:get("selfbotBOT-IDpm") or "اددی گلم خصوصی پیام بده"
return reply_msg(msg.id,txt, ok_cb, false)
end
elseif (msg.media.caption and redis:get("selfbotBOT-IDlink")) then
find_link(msg.media.caption)
end
end
if redis:get("selfbotBOT-IDmarkread") then
mark_read(receiver, ok_cb, false)
end
end
function on_binlog_replay_end()
started = true
end
function on_our_id (id)
our_id = id
end
function on_user_update (user, what)
end
function on_chat_update (chat, what)
end
function on_secret_chat_update (schat, what)
end
function on_get_difference_end ()
end
our_id = 0
now = os.time()
math.randomseed(now)
started = false