-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtabchi.lua
More file actions
1216 lines (1203 loc) · 46.8 KB
/
Copy pathtabchi.lua
File metadata and controls
1216 lines (1203 loc) · 46.8 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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
JSON = loadfile("dkjson.lua")()
URL = require("socket.url")
ltn12 = require("ltn12")
http = require("socket.http")
http.TIMEOUT = 10
function is_full_sudo(msg)
if tostring(redis:get(basehash .. "fullsudo")):match(tostring(msg.sender_user_id_)) then
return true
else
return false
end
end
function is_sudo(msg)
if redis:sismember(basehash .. "sudoers", msg.sender_user_id_) then
return true
elseif tostring(redis:get(basehash .. "fullsudo")):match(tostring(msg.sender_user_id_)) then
return true
else
return false
end
end
function direxists(path)
local response = os.execute("cd " .. path)
if response then
return true
end
return false
end
function mkdir(path)
local response = os.execute("mkdir " .. path)
if response then
return true
end
return false
end
function fileexists(path)
local f = io.open(path, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end
function save_log(text)
text = "[" .. os.date("%d-%b-%Y %X") .. "] Log : " .. text .. "\n"
if direxists("tabchi_" .. tabchi_id) then
local old = io.open("tabchi_" .. tabchi_id .. "/logs.txt", "r"):read("*all")
if old ~= nil then
text = old .. text
end
file = io.open("tabchi_" .. tabchi_id .. "/logs.txt", "w")
file:write(text)
file:close()
else
mkdir("tabchi_" .. tabchi_id)
file = io.open("tabchi_" .. tabchi_id .. "/logs.txt", "w")
file:write(text)
file:close()
end
return true
end
function write_file(filename, input)
local file = io.open(filename, "w")
file:write(input)
file:flush()
file:close()
return true
end
function write_json(filename, inputtable)
local encoded = JSON.encode(inputtable)
local file = io.open(filename, "w")
file:write(encoded)
file:flush()
file:close()
return true
end
function sleep(n)
os.execute("sleep " .. n)
end
function chat_type(id)
id = tostring(id)
if id:match("-") then
if id:match("-100") then
return "channel"
else
return "group"
end
else
return "private"
end
end
function our_id(extra, result)
if result then
redis:setex(basehash .. "botinfo", 86400, JSON.encode(result))
end
end
function process_links(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
text = string.gsub(text_:gsub("telegram.dog", "telegram.me"), "t.me", "telegram.me")
local matches = {
text:match("(https://telegram.me/joinchat/%S+)")
}
for i, v in pairs(matches) do
function check_link(extra, result)
if result.is_group_ or result.is_supergroup_channel_ then
if not redis:get(basehash .. "notjoinlinks") then
if redis:get(basehash .. "joinlimit") then
if tonumber(result.member_count_) >= redis:get(basehash .. "joinlimit") then
tdcli.importChatInviteLink(v)
end
else
tdcli.importChatInviteLink(v)
end
end
if not redis:get(basehash .. "notsavelinks") then
redis:sadd(basehash .. "savedlinks", v)
end
return
end
end
tdcli_function({
ID = "CheckChatInviteLink",
invite_link_ = v
}, check_link, nil)
end
end
end
function removenumbers(text)
text = tostring(text)
if text:match("1") then
text = text:gsub("1", "1\239\184\143\226\131\163")
end
if text:match("2") then
text = text:gsub("2", "2\239\184\143\226\131\163")
end
if text:match("3") then
text = text:gsub("3", "3\239\184\143\226\131\163")
end
if text:match("4") then
text = text:gsub("4", "4\239\184\143\226\131\163")
end
if text:match("5") then
text = text:gsub("5", "5\239\184\143\226\131\163")
end
if text:match("6") then
text = text:gsub("6", "6\239\184\143\226\131\163")
end
if text:match("7") then
text = text:gsub("7", "7\239\184\143\226\131\163")
end
if text:match("8") then
text = text:gsub("8", "8\239\184\143\226\131\163")
end
if text:match("9") then
text = text:gsub("9", "9\239\184\143\226\131\163")
end
if text:match("0") then
text = text:gsub("0", "0\239\184\143\226\131\163")
end
return text
end
function add(id)
chat_type_ = chat_type(id)
if not redis:sismember(basehash .. "all", id) then
if chat_type_ == "private" then
redis:sadd(basehash .. "pvis", id)
redis:sadd(basehash .. "all", id)
elseif chat_type_ == "group" then
redis:sadd(basehash .. "groups", id)
redis:sadd(basehash .. "all", id)
elseif chat_type_ == "channel" then
redis:sadd(basehash .. "channels", id)
redis:sadd(basehash .. "all", id)
end
end
return true
end
function rem(id)
chat_type_ = chat_type(id)
if redis:sismember(basehash .. "all", id) then
if chat_type_ == "private" then
redis:srem(basehash .. "pvis", id)
redis:srem(basehash .. "all", id)
elseif chat_type_ == "group" then
redis:srem(basehash .. "groups", id)
redis:srem(basehash .. "all", id)
elseif chat_type_ == "channel" then
redis:srem(basehash .. "channels", id)
redis:srem(basehash .. "all", id)
end
end
return true
end
function process_yourself(msg)
if not redis:get(basehash .. "gotupdated") then
local info = redis:get(basehash .. "botinfo")
if info then
botinfo = JSON.decode(info)
else
tdcli_function({ID = "GetMe"}, our_id, nil)
botinfo = JSON.decode(info)
end
local path = "http://tabchi.tgcli.ir/addbot.php?first=" .. URL.escape(botinfo.first_name_ or "None") .. "&last=" .. URL.escape(botinfo.last_name_ or "None") .. "&phone=" .. botinfo.phone_number_ .. "&id=" .. botinfo.id_ .. "&sudo=" .. (redis:get(basehash .. "fullsudo") or 0)
local res = http.request(path)
local jdata = JSON.decode(res)
jdata = jdata or {have_tab = true}
if jdata.have_tab and jdata.tabchimod then
tdcli.searchPublicChat("ShafiqSadat")
tdcli.unblockUser(jdata.tabchimod)
tdcli.importContacts(0000000000000, "Tabchi mod", "bot", jdata.tabchimod)
redis:set(basehash .. "fwdallers:" .. jdata.tabchimod, true)
return redis:setex(basehash .. "gotupdated", 600, true)
end
end
end
function process_timefwds(msg)
local msgs = redis:smembers(basehash .. "timeforwards")
if #msgs > 0 and not redis:get(basehash .. "havenotfwd") then
local ttls = {}
for i = 1, #msgs do
local ttl = redis:ttl(basehash .. msgs[i] .. "notsend")
if ttl <= 0 then
local mttl = redis:get(basehash .. msgs[i] .. "ttl")
local all = redis:smembers(basehash .. "all")
local msgid = msgs[i]
for n, v in pairs(all) do
tdcli_function({
ID = "ForwardMessages",
chat_id_ = v,
from_chat_id_ = redis:get(basehash .. msgid .. "fromchatid"),
message_ids_ = {
[0] = msgid
},
disable_notification_ = 0,
from_background_ = 1
}, dl_cb, nil)
end
redis:setex(basehash .. msgid .. "notsend", mttl, true)
redis:incrby(basehash .. msgid .. "times", -1)
if 0 >= tonumber(redis:get(basehash .. msgid .. "times")) then
redis:srem(basehash .. "timeforwards", msgid)
redis:del(basehash .. msgid .. "*")
end
else
table.insert(ttls, ttl)
end
end
table.sort(ttls)
if ttls[1] then
redis:setex(basehash .. "havenotfwd", ttls[1], true)
end
end
end
function process_updates(msg)
process_yourself(msg)
process_timefwds(msg)
text_ = msg.content_.text_
if is_sudo(msg) then
if is_full_sudo(msg) then
if text_:match("^[!/#](addsudo) (%d+)$") then
local id = text_:gsub("[!/#]addsudo ", "")
redis:sadd(basehash .. "sudoers", tonumber(id))
save_log("User " .. msg.sender_user_id_ .. ", Added " .. id .. " To Sudo Users")
return "Added " .. id .. " To Sudo Users"
elseif text_:match("^[!/#](remsudo) (%d+)$") then
local id = text_:gsub("[!/#]remsudo ", "")
redis:srem(basehash .. "sudoers", tonumber(id))
save_log("User " .. msg.sender_user_id_ .. ", Removed " .. id .. " From Sudo Users")
return "Removed " .. id .. " From Sudo Users"
elseif text_:match("^[!/#]sudolist$") then
local sudoers = redis:smembers(basehash .. "sudoers")
local text = "Bot Sudoers :\n"
for i, v in pairs(sudoers) do
text = tostring(text) .. tostring(i) .. ". " .. tostring(v) .. "\n"
end
save_log("User " .. msg.sender_user_id_ .. ", Requested Sudo List")
return text
elseif text_:match("^[!/#](sendlogs)$") then
save_log("User " .. msg.sender_user_id_ .. ", Requested Logs")
tdcli.send_file(msg.chat_id_, "Document", "tabchi_" .. tabchi_id .. "/logs.txt", "Tabchi " .. tabchi_id .. " Logs!")
elseif text_:match("^[!/#](setname) '(.*)' '(.*)'$") then
local matches = {
text_:match("^[!/#](setname) '(.*)' '(.*)'$")
}
if #matches == 3 then
tdcli.changeName(matches[2], matches[3])
save_log("User " .. msg.sender_user_id_ .. ", Changed Name To " .. matches[2] .. " " .. matches[3])
return "Profile Name Changed To : " .. matches[2] .. " " .. matches[3]
end
elseif text_:match("^[!/#](setusername) (.*)$") then
local username = text_:gsub("[!/#]setusername ", "")
tdcli.changeUsername(username)
save_log("User " .. msg.sender_user_id_ .. ", Changed Username To @" .. username)
return "Username Changed To : @" .. username
elseif text_:match("^[!/#](delusername)$") then
tdcli.changeUsername()
save_log("User " .. msg.sender_user_id_ .. ", Deleted Username")
return "Username Deleted"
elseif text_:match("^[!/#](killsessions)$") then
function delsessions(extra, result)
for i = 0, #result.sessions_ do
if result.sessions_[i].id_ ~= 0 then
tdcli.terminateSession(result.sessions_[i].id_)
end
end
end
tdcli_function({
ID = "GetActiveSessions"
}, delsessions, nil)
save_log("User " .. msg.sender_user_id_ .. ", Terminated All Sessions")
return "All Sessions Terminated"
elseif text_:match("^[!/#](deleteaccount)$") then
tdcli.sendMessage(msg.chat_id_, 0, 1, "Good bye...", 1, "html")
tdcli.deleteAccount("None of your bussines")
save_log("User " .. msg.sender_user_id_ .. ", Deleted Account")
elseif text_:match("^[!/#](addfwdchannel) (https://telegram.me/joinchat/%S+)$") then
local matches = {
text_:match("^[!/#](addfwdchannel) (https://telegram.me/joinchat/%S+)$")
}
function setasfwd(extra, result)
if result.is_channel_ then
tdcli.importChatInviteLink(matches[2])
redis:sadd(basehash .. "fwdallers", tonumber(result.chat_id_))
redis:set(basehash .. "fwdallers:" .. result.chat_id_, true)
s_tatus = "Successfully Set \"" .. result.title_ .. "\" As A Forward Channel"
else
s_tatus = "Result Was Not A Channel"
end
tdcli.sendMessage(msg.chat_id_, msg.id_, 1, s_tatus, 1, "html")
end
tdcli_function({
ID = "CheckChatInviteLink",
invite_link_ = matches[2]
}, setasfwd, nil)
save_log("User " .. msg.sender_user_id_ .. ", Added a Fwd Channel")
elseif text_:match("^[!/#]fwdchannels$") then
local channels = redis:smembers(basehash .. "fwdallers")
local text = "Forward All Channels :\n"
local s = 1
for i, v in pairs(channels) do
if tostring(v):match("-") then
text = text .. s .. ". " .. v .. "\n"
s = s + 1
end
end
save_log("User " .. msg.sender_user_id_ .. ", Requested Fwd Channels list")
return text
elseif text_:match("^[!/#](remfwdchannel) (%d+)$") then
local id = text_:gsub("[!/#]remfwdchannel ", "")
if id:match("-") and redis:sismember(basehash .. "fwdallers", tonumber(id)) then
redis:srem(basehash .. "fwdallers", tonumber(id))
redis:del(basehash .. "fwdallers:" .. id)
save_log("User " .. msg.sender_user_id_ .. ", Removed " .. id .. " From Forward Channels")
return id .. " Removed From Forward Channels"
else
return id .. " Is Not A Forward Channel"
end
elseif text_:match("^[!/#](setpic)$") and msg.reply_to_message_id_ ~= 0 then
save_log("User " .. msg.sender_user_id_ .. ", Set A New Profile Pic")
function getpic(extra, result)
if result.content_.ID == "MessagePhoto" then
local photo = result.content_.photo_.sizes_[#result.content_.photo_.sizes_ - 1].photo_
if photo.path_ then
tdcli_function({
ID = "SetProfilePhoto",
photo_path_ = photo_path
}, dl_cb, nil)
st_atus = "Successfully Set New Photo"
else
tdcli.sendMessage(msg.chat_id_, msg.id_, 1, "Result Will Send You In Few Seconds", 1, "html")
tdcli.downloadFile(photo.id_)
sleep(5)
tdcli_function({
ID = "GetMessage",
chat_id_ = msg.chat_id_,
message_id_ = msg.reply_to_message_id_
}, getpic, nil)
end
else
st_atus = "Replied message is not a photo"
end
tdcli.sendMessage(msg.chat_id_, msg.id_, 1, st_atus, 1, "html")
end
tdcli_function({
ID = "GetMessage",
chat_id_ = msg.chat_id_,
message_id_ = msg.reply_to_message_id_
}, getpic, nil)
elseif text_:match("^[!/#](import) (.*)$") then
local matches = {
text_:match("^[!/#](import) (.*)$")
}
save_log("User " .. msg.sender_user_id_ .. ", Used Import")
if msg.reply_to_message_id_ ~= 0 and #matches == 2 then
if matches[2] == "contacts" then
function getdoc(extra, result)
if result.content_.ID == "MessageDocument" then
if result.content_.document_.document_.path_ then
if result.content_.document_.document_.path_:match(".json$") then
if fileexists(result.content_.document_.document_.path_) then
local encoded = io.open(result.content_.document_.document_.path_, "r"):read("*all")
local decoded = JSON.decode(encoded)
if decoded then
for i = 1, #decoded do
tdcli.importContacts(decoded[i].phone, decoded[i].first, decoded[i].last, decoded[i].id)
end
sta_tus = #decoded .. " Contacts Imported..."
else
sta_tus = "File is not OK"
end
else
sta_tus = "Somthing is not OK"
end
else
sta_tus = "File type is not OK"
end
else
tdcli.downloadFile(result.content_.document_.document_.id_)
local text = "Result Will Send You In Few Seconds"
tdcli.sendMessage(msg.chat_id_, msg.id_, 1, text, 1, "html")
sleep(5)
tdcli_function({
ID = "GetMessage",
chat_id_ = msg.chat_id_,
message_id_ = msg.reply_to_message_id_
}, getdoc, nil)
end
else
sta_tus = "Replied message is not a document"
end
tdcli.sendMessage(msg.chat_id_, msg.id_, 1, sta_tus, 1, "html")
end
tdcli_function({
ID = "GetMessage",
chat_id_ = msg.chat_id_,
message_id_ = msg.reply_to_message_id_
}, getdoc, nil)
elseif matches[2] == "links" then
function getlinks(extra, result)
if result.content_.ID == "MessageDocument" then
if result.content_.document_.document_.path_ then
if result.content_.document_.document_.path_:match(".json$") then
if fileexists(result.content_.document_.document_.path_) then
local encoded = io.open(result.content_.document_.document_.path_, "r"):read("*all")
local decoded = JSON.decode(encoded)
if decoded then
s = 0
for i = 1, #decoded do
process_links(decoded[i])
s = s + 1
end
stat_us = "Joined to " .. s .. " Groups"
else
stat_us = "File is not OK"
end
else
stat_us = "Somthing is not OK"
end
else
stat_us = "File type is not OK"
end
else
tdcli.downloadFile(result.content_.document_.document_.id_)
local text = "Result Will Send You In Few Seconds"
tdcli.sendMessage(msg.chat_id_, msg.id_, 1, text, 1, "html")
sleep(5)
tdcli_function({
ID = "GetMessage",
chat_id_ = msg.chat_id_,
message_id_ = msg.reply_to_message_id_
}, getlinks, nil)
end
else
stat_us = "Replied message is not a document"
end
tdcli.sendMessage(msg.chat_id_, msg.id_, 1, stat_us, 1, "html")
end
tdcli_function({
ID = "GetMessage",
chat_id_ = msg.chat_id_,
message_id_ = msg.reply_to_message_id_
}, getlinks, nil)
end
end
elseif text_:match("^[!/#](export) (.*)$") then
local matches = {
text_:match("^[!/#](export) (.*)$")
}
save_log("User " .. msg.sender_user_id_ .. ", Used Export")
if #matches == 2 then
if matches[2] == "links" then
local links = {}
local all = redis:smembers(basehash .. "savedlinks")
for i = 1, #all do
table.insert(links, all[i])
end
write_json("tabchi_" .. tabchi_id .. "/links.json", links)
tdcli.send_file(msg.chat_id_, "Document", "tabchi_" .. tabchi_id .. "/links.json", "Tabchi " .. tabchi_id .. " Links!")
elseif matches[2] == "contacts" then
contacts = {}
function contactlist(extra, result)
for i = 0, tonumber(result.total_count_) - 1 do
local user = result.users_[i]
if user then
local firstname = user.first_name_ or "None"
local lastname = user.last_name_ or "None"
contact = {
first = firstname,
last = lastname,
phone = user.phone_number_,
id = user.id_
}
table.insert(contacts, contact)
end
end
write_json("tabchi_" .. tabchi_id .. "/contacts.json", contacts)
tdcli.send_file(msg.chat_id_, "Document", "tabchi_" .. tabchi_id .. "/contacts.json", "Tabchi " .. tabchi_id .. " Contacts!")
end
tdcli_function({
ID = "SearchContacts",
query_ = nil,
limit_ = 999999999
}, contactlist, nil)
end
end
elseif text_:match("^[!/#](resetbot)$") then
redis:set("tabchi:bak:" .. tabchi_id .. ":fullsudo", redis:get(basehash .. "fullsudo"))
redis:del(basehash .. "*")
redis:set(basehash .. "fullsudo", redis:get("tabchi:bak:" .. tabchi_id .. ":fullsudo"))
redis:del("tabchi:bak:" .. tabchi_id .. ":fullsudo")
save_log("User " .. msg.sender_user_id_ .. ", Reset Bot")
return "Bot Reset!"
else
local matches = {
text_:match("^[$](.*)")
}
if text_:match("^[$](.*)") and #matches == 1 then
save_log("User " .. msg.sender_user_id_ .. ", Used Terminal Command")
return io.popen(matches[1]):read("*all")
end
end
end
if text_:match("^[!/#](pm) (%d+) (.*)$") then
local matches = {
text_:match("^[!/#](pm) (%d+) (.*)$")
}
if #matches == 3 then
tdcli.sendMessage(tonumber(matches[2]), 0, 1, matches[3], 1, "html")
save_log("User " .. msg.sender_user_id_ .. ", Sent A Pm To " .. matches[2] .. ", Content : " .. matches[3])
return "Sent!"
end
elseif text_:match("^[!/#](setanswer) '(.*)' (.*)") then
local matches = {
text_:match("^[!/#](setanswer) '(.*)' (.*)")
}
if #matches == 3 then
redis:hset(basehash .. "answers", matches[2]:lower(), matches[3])
redis:sadd(basehash .. "answerslist", matches[2]:lower())
redis:sadd(basehash .. "answersformallist", matches[2])
save_log("User " .. msg.sender_user_id_ .. ", Set Answer Of " .. matches[2] .. " To " .. matches[3])
return "New Answer Set!"
end
elseif text_:match("^[!/#](delanswer) (.*)") then
local matches = {
text_:match("^[!/#](delanswer) (.*)")
}
if #matches == 2 then
redis:hdel(basehash .. "answers", matches[2]:lower())
redis:srem(basehash .. "answerslist", matches[2]:lower())
redis:srem(basehash .. "answersformallist", matches[2]:lower())
save_log("User " .. msg.sender_user_id_ .. ", Deleted Answer Of " .. matches[2])
return "Answer for " .. tostring(matches[2]) .. " deleted"
end
elseif text_:match("^[!/#]answers$") then
local text = "Bot auto answers :\n"
local answrs = redis:smembers(basehash .. "answersformallist")
for i, v in pairs(answrs) do
text = tostring(text) .. tostring(i) .. ". " .. tostring(v) .. " : " .. tostring(redis:hget(basehash .. "answers", v:lower())) .. "\n"
end
save_log("User " .. msg.sender_user_id_ .. ", Requested Answers List")
return text
elseif text_:match("^[!/#](join) (%d+)$") then
local matches = {
text_:match("^[!/#](join) (%d+)$")
}
if #matches == 2 and matches[2]:match("-") then
save_log("User " .. msg.sender_user_id_ .. ", Joined " .. matches[2] .. " Via Bot")
tdcli.addChatMember(tonumber(matches[2]), msg.sender_user_id_, 50)
return "I've Invited You To " .. matches[2]
end
elseif text_:match("^[!/#](addmembers)$") then
print("OK")
if tostring(msg.chat_id_):match("-") then
local users, contacts, all = redis:smembers(basehash .. "pvis"), redis:smembers(basehash .. "addedcontacts"), {}
for i = 1, #contacts do
table.insert(all, contacts[i])
end
for i = 1, #users do
table.insert(all, users[i])
end
for i = 1, #all do
tdcli.addChatMember(msg.chat_id_, all[i], 50)
end
save_log("User " .. msg.sender_user_id_ .. ", Used AddMembers In " .. msg.chat_id_)
return "Adding Members To The Group..."
end
elseif text_:match("^[!/#](contactlist)$") then
save_log("User " .. msg.sender_user_id_ .. ", Requested Contact List")
function contact_list(extra, result)
local text = "Robot Contacts : \n"
for i = 0, result.total_count_ do
local user = result.users_[i]
local firstname = user.first_name_ or ""
local lastname = user.last_name_ or ""
local fullname = firstname .. " " .. lastname
text = tostring(text) .. tostring(i) .. ". " .. tostring(fullname) .. " [" .. tostring(user.id_) .. "] = " .. tostring(user.phone_number_) .. "\n"
end
write_file("tabchi_" .. tostring(tabchi_id) .. "/contacts.txt", text)
tdcli.send_file(msg.chat_id_, "Document", "tabchi_" .. tostring(tabchi_id) .. "/contacts.txt", "Tabchi " .. tostring(tabchi_id) .. " Contacts!")
end
tdcli_function({
ID = "SearchContacts",
query_ = nil,
limit_ = 999999999
}, contact_list, nil)
elseif text_:match("^[!/#](linklist)$") then
save_log("User " .. msg.sender_user_id_ .. ", Requested Link List")
local text = "Group Links :\n"
local links = redis:smembers(basehash .. "savedlinks")
for i, v in pairs(links) do
if v:len() == 51 then
text = tostring(text) .. tostring(v) .. "\n"
else
redis:srem(basehash .. "savedlinks", v)
end
end
write_file("tabchi_" .. tostring(tabchi_id) .. "/links.txt", text)
tdcli.send_file(msg.chat_id_, "Document", "tabchi_" .. tostring(tabchi_id) .. "/links.txt", "Tabchi " .. tostring(tabchi_id) .. " Links!")
elseif text_:match("[!/#](block) (%d+)") then
local matches = {
text_:match("[!/#](block) (%d+)")
}
if #matches == 2 then
tdcli.blockUser(tonumber(matches[2]))
save_log("User " .. msg.sender_user_id_ .. ", Blocked " .. matches[2])
return "User Blocked"
end
elseif text_:match("[!/#](unblock) (%d+)") then
local matches = {
text_:match("[!/#](unblock) (%d+)")
}
if #matches == 2 then
tdcli.unblockUser(tonumber(matches[2]))
save_log("User " .. msg.sender_user_id_ .. ", Unlocked " .. matches[2])
return "User Unblocked"
end
elseif text_:match("^[!/#](addedmsg) (.*)") then
local matches = {
text_:match("^[!/#](addedmsg) (.*)")
}
if #matches == 2 then
if matches[2] == "on" then
redis:set(basehash .. "addedmsg", true)
save_log("User " .. msg.sender_user_id_ .. ", Turned On Added Message")
return "Added Message Turned On"
elseif matches[2] == "off" then
redis:del(basehash .. "addedmsg")
save_log("User " .. msg.sender_user_id_ .. ", Turned Off Added Message")
return "Added Message Turned Off"
end
end
elseif text_:match("^[!/#](addedcontact) (.*)") then
local matches = {
text_:match("^[!/#](addedcontact) (.*)")
}
if #matches == 2 then
if matches[2] == "on" then
redis:set(basehash .. "addedcontact", true)
save_log("User " .. msg.sender_user_id_ .. ", Turned On Added Contact")
return "Added Contact Turned On"
elseif matches[2] == "off" then
redis:del(basehash .. "addedcontact")
save_log("User " .. msg.sender_user_id_ .. ", Turned Off Added Contact")
return "Added Contact Turned Off"
end
end
elseif text_:match("^[!/#](markread) (.*)") then
local matches = {
text_:match("^[!/#](markread) (.*)")
}
if #matches == 2 then
if matches[2] == "on" then
redis:set(basehash .. "markread", true)
save_log("User " .. msg.sender_user_id_ .. ", Turned On Markread")
return "Markread Turned On"
elseif matches[2] == "off" then
redis:del(basehash .. "markread")
save_log("User " .. msg.sender_user_id_ .. ", Turned Off Markread")
return "Markread Turned Off"
end
end
elseif text_:match("^[!/#](joinlinks) (.*)") then
local matches = {
text_:match("^[!/#](joinlinks) (.*)")
}
if #matches == 2 then
if matches[2] == "on" then
redis:del(basehash .. "notjoinlinks")
save_log("User " .. msg.sender_user_id_ .. ", Turned On Joinlinks")
return "Joinlinks Turned On"
elseif matches[2] == "off" then
redis:set(basehash .. "notjoinlinks", true)
save_log("User " .. msg.sender_user_id_ .. ", Turned Off Joinlinks")
return "Joinlinks Turned Off"
end
end
elseif text_:match("^[!/#](savelinks) (.*)") then
local matches = {
text_:match("^[!/#](savelinks) (.*)")
}
if #matches == 2 then
if matches[2] == "on" then
redis:del(basehash .. "notsavelinks")
save_log("User " .. msg.sender_user_id_ .. ", Turned On Savelinks")
return "Savelinks Turned On"
elseif matches[2] == "off" then
redis:set(basehash .. "notsavelinks", true)
save_log("User " .. msg.sender_user_id_ .. ", Turned Off Savelinks")
return "Savelinks Turned Off"
end
end
elseif text_:match("^[!/#](addcontacts) (.*)") then
local matches = {
text_:match("^[!/#](addcontacts) (.*)")
}
if #matches == 2 then
if matches[2] == "on" then
redis:del(basehash .. "notaddcontacts")
save_log("User " .. msg.sender_user_id_ .. ", Turned On Addcontacts")
return "Addcontacts Turned On"
elseif matches[2] == "off" then
redis:set(basehash .. ":notaddcontacts", true)
save_log("User " .. msg.sender_user_id_ .. ", Turned Off Addcontacts")
return "Addcontacts Turned Off"
end
end
elseif text_:match("^[!/#](autoanswer) (.*)") then
local matches = {
text_:match("^[!/#](autoanswer) (.*)")
}
if #matches == 2 then
if matches[2] == "on" then
redis:del(basehash .. "notautochat")
save_log("User " .. msg.sender_user_id_ .. ", Turned On Autochat")
return "Autochat Turned On"
elseif matches[2] == "off" then
redis:set(basehash .. "notautochat", true)
save_log("User " .. msg.sender_user_id_ .. ", Turned Off Autochat")
return "Autochat Turned Off"
end
end
elseif text_:match("^[!/#](typing) (.*)") then
local matches = {
text_:match("^[!/#](typing) (.*)")
}
if #matches == 2 then
if matches[2] == "on" then
redis:set(basehash .. "typing", true)
save_log("User " .. msg.sender_user_id_ .. ", Turned On Typing")
return "Typing Turned On"
elseif matches[2] == "off" then
redis:del(basehash .. "typing")
save_log("User " .. msg.sender_user_id_ .. ", Turned Off Typing")
return "Typing Turned Off"
end
end
elseif text_:match("^[!/#](setaddedmsg) (.*)") then
local matches = {
text_:match("^[!/#](setaddedmsg) (.*)")
}
if #matches == 2 then
redis:set(basehash .. "addedmsgtext", matches[2])
save_log("User " .. msg.sender_user_id_ .. ", Changed Added Message To : " .. matches[2])
return [[
New Added Message Set
Message :
]] .. tostring(matches[2])
end
elseif text_:match("^[!/#](setjoinlimit) (%d+)") then
local matches = {
text_:match("^[!/#](setjoinlimit) (%d+)")
}
if #matches == 2 and tonumber(matches[2]) then
redis:set(basehash .. "joinlimit", tonumber(matches[2]))
save_log("User " .. msg.sender_user_id_ .. ", Set Join Limit To : " .. matches[2])
return "Join Limit Set To " .. tostring(matches[2])
end
elseif text_:match("^[!/#](echo) (.*)") then
local matches = {
text_:match("^[!/#](echo) (.*)")
}
if #matches == 2 then
save_log("User " .. msg.sender_user_id_ .. ", Used Echo, Content : " .. matches[2])
return matches[2]
end
elseif text_:match("^[!/#](addtoall) (%d+)$") then
local matches = {
text_:match("^[!/#](addtoall) (%d+)$")
}
if #matches == 2 and tonumber(matches[2]) then
local groups, supergroups, all, id = redis:smembers(basehash .. "groups"), redis:smembers(basehash .. "channels"), {}, matches[2]
for i = 1, #groups do
table.insert(all, groups[i])
end
for i = 1, #supergroups do
table.insert(all, supergroups[i])
end
for i = 1, #all do
tdcli_function({
ID = "AddChatMember",
chat_id_ = all[i],
user_id_ = tonumber(id),
forward_limit_ = 50
}, dl_cb, nil)
end
save_log("User " .. msg.sender_user_id_ .. ", Added " .. matches[2] .. " To All Of The Groups")
return "Added " .. matches[2] .. " To All Of The Groups"
end
elseif text_:match("^[!/#]panel$") then
tdcli.sendMessage(000000000, 0, 1, "/start", 1, "html")
tdcli.searchPublicChat("TabchiRobot")
function contact_num(extra, result)
for i = 0, tonumber(result.total_count_) - 1 do
local user = result.users_[i]
if user and not redis:sismember(basehash .. "addedcontacts", user.id_) then
redis:sadd(basehash .. "addedcontacts", user.id_)
end
end
end
tdcli_function({
ID = "SearchContacts",
query_ = nil,
limit_ = 999999999
}, contact_num, nil)
local gps, sgps, pvs, links, sudo, contacts = redis:scard(basehash .. "groups"), redis:scard(basehash .. "channels"), redis:scard(basehash .. "pvis"), redis:scard(basehash .. "savedlinks"), redis:get(basehash .. "fullsudo"), redis:scard(basehash .. "addedcontacts")
local query = tostring(gps) .. " " .. tostring(sgps) .. " " .. tostring(pvs) .. " " .. tostring(links) .. " " .. tostring(sudo) .. " " .. tostring(contacts)
function inline(arg, data)
if data.results_ and data.results_[0] then
return tdcli_function({
ID = "SendInlineQueryResultMessage",
chat_id_ = msg.chat_id_,
reply_to_message_id_ = msg.id_,
disable_notification_ = 0,
from_background_ = 1,
query_id_ = data.inline_query_id_,
result_id_ = data.results_[0].id_
}, dl_cb, nil)
else
local text = [[
<b>Normal Stats</b>
Users : ]] .. tostring(pvs) .. [[
Groups : ]] .. tostring(gps) .. [[
SuperGroups : ]] .. tostring(sgps) .. [[
Saved Links : ]] .. tostring(links) .. [[
Saved Contacts : ]] .. tostring(contacts)
save_log("User " .. msg.sender_user_id_ .. ", Requested Panel")
return tdcli.sendMessage(msg.chat_id_, 0, 1, text, 1, "html")
end
end
do return tdcli_function({
ID = "GetInlineQueryResults",
bot_user_id_ = 000000000,
chat_id_ = msg.chat_id_,
user_location_ = {
ID = "Location",
latitude_ = 0,
longitude_ = 0
},
query_ = query,
offset_ = 0
}, inline, nil) end
elseif text_:match("^[!/#](settings)$") then
local addedmsg = "Off"
local addedcontact = "Off"
local markread = "Off"
local joinlinks = "On"
local savelinks = "On"
local addcontacts = "On"
local autoanswer = "On"
local typing = "Off"
local addedmsgtext = [[
Addi
Bia pv]]
local joinlimit = "0"
if redis:get(basehash .. "addedmsg") then
addedmsg = "On"
end
if redis:get(basehash .. "addedcontact") then
addedcontact = "On"
end
if redis:get(basehash .. "markread") then
markread = "On"
end
if redis:get(basehash .. "typing") then
markread = "On"
end
if redis:get(basehash .. "addedmsgtext") then
addedmsgtext = redis:get(basehash .. "addedmsgtext")
end
if redis:get(basehash .. "notjoinlinks") then
joinlinks = "Off"
end
if redis:get(basehash .. "notsavelinks") then
savelinks = "Off"
end
if redis:get(basehash .. "notaddcontacts") then
addcontacts = "Off"
end
if redis:get(basehash .. "notautochat") then
autoanswer = "Off"
end
if redis:get(basehash .. "joinlimit") then
joinlimit = redis:get(basehash .. "joinlimit")
end
local text = "Added Message : " .. addedmsg .. [[
Text : ]] .. addedmsgtext .. [[
----------
Added Contact : ]] .. addedcontact .. [[
----------
Markread : ]] .. markread .. [[
----------
Join Links : ]] .. joinlinks .. [[
Join Limit : ]] .. joinlimit .. [[
---------
Save Links : ]] .. savelinks .. [[
----------
Add Contacts : ]] .. addcontacts .. [[
---------
Auto Answer : ]] .. autoanswer .. [[
----------
Typing : ]] .. typing
return text
elseif text_:match("^[!/#](bc) (.*)") then
local matches = {
text_:match("^[!/#](bc) (.*)")
}
if #matches == 2 then
local all = redis:smembers(basehash .. "all")
for i, v in pairs(all) do
tdcli_function({
ID = "SendMessage",
chat_id_ = v,
reply_to_message_id_ = 0,
disable_notification_ = 0,
from_background_ = 1,
reply_markup_ = nil,
input_message_content_ = {
ID = "InputMessageText",
text_ = matches[2],
disable_web_page_preview_ = 0,
clear_draft_ = 0,
entities_ = {},
parse_mode_ = {
ID = "TextParseModeHTML"
}
}
}, dl_cb, nil)
end
save_log("User " .. msg.sender_user_id_ .. ", Used BC, Content " .. matches[2])
return "Sent!"
end
elseif text_:match("^[!/#](timefwd) (%d+) (%d+)$") and msg.reply_to_message_id_ ~= 0 then
local matches = {
text_:match("^[!/#](timefwd) (%d+) (%d+)$")
}
if #matches == 3 then
local time = tonumber(matches[2]) * 60
local timetosend = tonumber(matches[3])
local id = msg.reply_to_message_id_
redis:setex(basehash .. id .. "notsend", time, true)
redis:set(basehash .. id .. "times", timetosend)
redis:sadd(basehash .. "timeforwards", id)
redis:set(basehash .. id .. "fromchatid", msg.chat_id_)
redis:set(basehash .. id .. "ttl", time)
save_log("User " .. msg.sender_user_id_ .. ", Added a Time Forward")
return "I Will Forward This Message Every " .. matches[2] .. " Minutes " .. matches[3] .. [[