-
Notifications
You must be signed in to change notification settings - Fork 30
/
TD.lua
2584 lines (2446 loc) · 132 KB
/
TD.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
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
local Redis = require("redis")
local FakeRedis = require("fakeredis")
local params = {
host = "127.0.0.1",
port = 6379,
password = nil,
db = Ads_id
}
-- Overwrite HGETALL
Redis.commands.hgetall =
Redis.command(
"hgetall",
{
response = function(reply, command, ...)
local new_reply = {}
for i = 1, #reply, 2 do
new_reply[reply[i]] = reply[i + 1]
end
return new_reply
end
}
)
local redis = nil
local ok =
pcall(
function()
redis = Redis.connect(params)
end
)
if not ok then
local fake_func = function()
print("\27[31mCan't connect with Redis, install/configure it!\27[39m")
end
fake_func()
fake = FakeRedis.new()
print("\27[31mRedis addr: " .. params.host .. "\27[39m")
print("\27[31mRedis port: " .. params.port .. "\27[39m")
redis =
setmetatable(
{fakeredis = true},
{
__index = function(a, b)
if b ~= "data" and fake[b] then
fake_func(b)
end
return fake[b] or fake_func
end
}
)
end
serpent = require("serpent")
function dl_cb(arg, data)
vardump(data)
end
function vardump(value, depth, key)
local linePrefix = ""
local spaces = ""
if key ~= nil then
linePrefix = "[" .. key .. "] = "
end
if depth == nil then
depth = 0
else
depth = depth + 1
for i = 1, depth do
spaces = spaces .. " "
end
end
if type(value) == "table" then
mTable = getmetatable(value)
if mTable == nil then
print(spaces .. linePrefix .. "(table) ")
else
print(spaces .. "(metatable) ")
value = mTable
end
for tableKey, tableValue in pairs(value) do
vardump(tableValue, depth, tableKey)
end
elseif type(value) == "function" or type(value) == "thread" or type(value) == "userdata" or value == nil then
print(spaces .. tostring(value))
else
print(spaces .. linePrefix .. "(" .. type(value) .. ") " .. tostring(value))
end
end
function ok_cb(extra, success, result)
end
function oldtg(data)
if data.message then
local msg = {}
msg.to = {}
msg.from = {}
msg.replied = {}
msg.to.id = data.message.chat_id
msg.from.id = data.message.sender_user_id
if data.message.content._ == "messageText" then
text = data.message.content.text
if #data.message.content.entities ~= 0 then
for k, v in ipairs(data.message.content.entities) do
if v.url_ then
text = text .. " url: " .. v.url_
end
end
end
end
if data.message.content.caption then
text = data.message.content.caption
end
msg.date = data.message.date
msg.id = data.message.id
msg.unread = false
if data.message.reply_to_message_id == 0 then
msg.reply_id = false
else
msg.reply_id = data.message.reply_to_message_id
end
if data.message.content._ == "messagePhoto" then
msg.photo = true
if data.message.content.photo.sizes[3] then
msg.file_id = data.message.content.photo.sizes[3].photo.persistent_id
else
msg.file_id = data.message.content.photo.sizes[0].photo.persistent_id
end
else
msg.photo = false
end
if data.message.content._ == "messageSticker" then
msg.sticker = true
msg.file_id = data.message.content.sticker.sticker.persistent_id
else
msg.sticker = false
end
if data.message.content._ == "messageAudio" then
msg.audio = true
msg.file_id = data.message.content.audio.audio.persistent_id
else
msg.audio = false
end
if data.message.content._ == "messageVoice" then
msg.voice = true
msg.file_id = data.message.content.voice.voice.persistent_id
else
msg.voice = false
end
if data.message.content._ == "messageAnimation" then
msg.gif = true
msg.file_id = data.message.content.animation.animation.persistent_id
else
msg.gif = false
end
if data.message.content._ == "messageVideo" then
msg.video = true
msg.file_id = data.message.content.video.video.persistent_id
else
msg.video = false
end
if data.message.content._ == "messageDocument" then
msg.document = true
msg.file_id = data.message.content.document.document.persistent_id
else
msg.document = false
end
if data.message.content._ == "MessageGame" then
msg.game = true
else
msg.game = false
end
if data.message.forward_info then
msg.forward = true
msg.forward = {}
msg.forward.from_id = data.message.forward_info.sender_user_id
msg.forward.msg_id = data.message.forward_info.data
else
msg.forward = false
end
if data.message.content._ then
msg.action = data.message.content._
end
if
data.message.content._ == "messageChatAddMembers" or data.message.content._ == "messageChatDeleteMember" or
data.message.content._ == "messageChatChangeTitle" or
data.message.content._ == "messageChatChangePhoto" or
data.message.content._ == "messageChatJoinByLink" or
data.message.content._ == "messageGameScore"
then
msg.service = true
else
msg.service = false
end
local new_members = data.message.content.members
if new_members then
msg.added = {}
for i = 0, #new_members, 1 do
k = i + 1
msg.added[k] = {}
msg.added[k].id = new_members[i].id
if new_members[i].username then
msg.added[k].username = new_members[i].username
else
msg.added[k].username = false
end
msg.added[k].first_name = new_members[i].first_name
if new_members[i].last_name then
msg.added[k].last_name = new_members[i].last_name
else
msg.added[k].last_name = false
end
end
end
return msg
end
return data
end
function serialize_to_file(data, file, uglify)
file = io.open(file, "w+")
local serialized
if not uglify then
serialized =
serpent.block(
data,
{
comment = false,
name = "_"
}
)
else
serialized = serpent.dump(data)
end
file:write(serialized)
file:close()
end
-- Returns a table with matches or nil
function get_receiver(msg)
return msg.to.id
end
function getChatId(chat_id)
local chat = {}
local chat_id = tostring(chat_id)
if chat_id:match("^-100") then
local channel_id = chat_id:gsub("-100", "")
chat = {ID = channel_id, type = "channel"}
else
local group_id = chat_id:gsub("-", "")
chat = {ID = group_id, type = "group"}
end
return chat
end
function is_number(name_id)
if tonumber(name_id) then
return true
else
return false
end
end
function no_markdown(text, replace)
if text then
text = tostring(text)
if replace then
text = text:gsub("`", replace)
text = text:gsub("*", replace)
text = text:gsub("_", replace)
return text
end
text = text:gsub("`", "")
text = text:gsub("*", "")
text = text:gsub("_", "")
return text
end
return false
end
function send_large_msg(chat_id, text)
local text_len = string.len(text)
local text_max = 4096
local times = text_len / text_max
local text = text
for i = 1, times, 1 do
local text = string.sub(text, 1, 4096)
local rest = string.sub(text, 4096, text_len)
local destination = chat_id
local num_msg = math.ceil(text_len / text_max)
if num_msg <= 1 then
send_msg(destination, text, "md")
else
text = rest
end
end
end
function scandir(directory)
local i, t, popen = 0, {}, io.popen
for filename in popen('ls -a "' .. directory .. '"'):lines() do
i = i + 1
t[i] = filename
end
return t
end
function get_multimatch_byspace(str, regex, cut)
list = {}
for wrd in str:gmatch("%S+") do
if (regex and wrd:match(regex)) then
table.insert(list, wrd:sub(wrd:find(regex) + cut))
elseif (not regex) then
table.insert(list, wrd)
end
end
if (#list > 0) then
return list
end
return false
end
function trim(text)
local chars_tmp = {}
local chars_m = {}
local final_str = ""
local text_arr = {}
local ok = false
local i
for i = 1, #text do
table.insert(chars_tmp, text:sub(i, i))
end
i = 1
while (chars_tmp[i]) do
if tostring(chars_tmp[i]):match("%S") then
table.insert(chars_m, chars_tmp[i])
ok = true
elseif ok == true then
table.insert(chars_m, chars_tmp[i])
end
i = i + 1
end
i = #chars_m
ok = false
while (chars_m[i]) do
if tostring(chars_m[i]):match("%S") then
table.insert(text_arr, chars_m[i])
ok = true
elseif ok == true then
table.insert(text_arr, chars_m[i])
end
i = i - 1
end
for i = #text_arr, 1, -1 do
final_str = final_str .. text_arr[i]
end
return final_str
end
function underline(text, underline_spaces)
local chars = {}
local text_str = ""
local symbol = trim(" ̲")
for i = 1, #text do
table.insert(chars, text:sub(i, i))
end
for i = 1, #chars do
space = chars[i] == " "
if (not space) then
text_str = text_str .. chars[i] .. symbol
elseif (underline_spaces) then
text_str = text_str .. chars[i] .. symbol
else
text_str = text_str .. chars[i]
end
end
return text_str
end
function up_underline(text, underline_spaces)
local chars = {}
local text_str = ""
local symbol = trim(" ̅ ")
for i = 1, #text do
table.insert(chars, text:sub(i, i))
end
for i = 1, #chars do
space = chars[i] == " "
if (not space) then
text_str = text_str .. chars[i] .. symbol
elseif (underline_spaces) then
text_str = text_str .. chars[i] .. symbol
else
text_str = text_str .. chars[i]
end
end
return text_str
end
function strike_out(text, underline_spaces)
local chars = {}
local text_str = ""
local symbol = trim(" ̶")
for i = 1, #text do
table.insert(chars, text:sub(i, i))
end
for i = 1, #chars do
space = chars[i] == " "
if (not space) then
text_str = text_str .. chars[i] .. symbol
elseif (underline_spaces) then
text_str = text_str .. chars[i] .. symbol
else
text_str = text_str .. chars[i]
end
end
return text_str
end
redis:del("tg:" .. Ads_id .. ":delay")
function get_bot()
function bot_info(i, tg)
redis:set("tg:" .. Ads_id .. ":id", tg.id)
if tg.first_name then
redis:set("tg:" .. Ads_id .. ":fname", tg.first_name)
end
if tg.last_name then
redis:set("tg:" .. Ads_id .. ":lname", tg.last_name)
end
redis:set("tg:" .. Ads_id .. ":num", tg.phone_number)
return tg.id
end
assert(tdbot_function({_ = "getMe"}, bot_info, nil))
end
sudo = 887321898
function reload(chat_id, msg_id)
dofile("./TD.lua")
send(chat_id, msg_id, "✅")
end
function is_sudo(msg)
if
redis:sismember("tg:" .. Ads_id .. ":sudo", msg.sender_user_id) or
msg.sender_user_id == tonumber(redis:get("tg:" .. Ads_id .. ":id"))
then
return true
else
return false
end
end
function process_join(i, tg)
if tg.code == 429 then
local message = tostring(tg.message)
local Time = message:match("%d+") + 55
redis:setex("tg:" .. Ads_id .. ":maxjoin", tonumber(Time), true)
else
redis:srem("tg:" .. Ads_id .. ":goodlinks", i.link)
redis:sadd("tg:" .. Ads_id .. ":savedlinks", i.link)
end
end
function process_link(i, tg)
if (tg.is_group or tg.is_supergroup_channel) then
if redis:get("tg:" .. Ads_id .. ":maxgpmmbr") then
if tg.member_count >= tonumber(redis:get("tg:" .. Ads_id .. ":maxgpmmbr")) then
redis:srem("tg:" .. Ads_id .. ":waitelinks", i.link)
redis:sadd("tg:" .. Ads_id .. ":goodlinks", i.link)
else
redis:srem("tg:" .. Ads_id .. ":waitelinks", i.link)
redis:sadd("tg:" .. Ads_id .. ":savedlinks", i.link)
end
else
redis:srem("tg:" .. Ads_id .. ":waitelinks", i.link)
redis:sadd("tg:" .. Ads_id .. ":goodlinks", i.link)
end
elseif tg.code == 429 then
local message = tostring(tg.message)
local Time = message:match("%d+") + 50
redis:setex("tg:" .. Ads_id .. ":maxlink", tonumber(Time), true)
else
redis:srem("tg:" .. Ads_id .. ":waitelinks", i.link)
end
end
function find_link(text)
if text:match("https://telegram.me/%S+") or text:match("https://telegram.dog/%S+") or
text:match("https://tlgrm.me/%S+") or
text:match("https://telesco.pe/%S+") or
text:match("https://t.me/%S+")
then
local text = text:gsub("t.me", "telegram.me")
local text = text:gsub("telesco.pe", "telegram.me")
local text = text:gsub("telegram.dog", "telegram.me")
local text = text:gsub("tlgrm.me", "telegram.me")
for link in text:gmatch("(https://telegram.me/%S+)") do
if not redis:sismember("tg:" .. Ads_id .. ":alllinks", link) then
redis:sadd("tg:" .. Ads_id .. ":waitelinks", link)
redis:sadd("tg:" .. Ads_id .. ":alllinks", link)
end
end
end
end
function forwarding(i, tg)
if tg._ == "error" then
s = i.s
if tg.code == 429 then
os.execute("sleep " .. tonumber(i.delay))
send(
i.chat_id,
0,
" restrict in operation " .. tostring(tg.message):match("%d+") .. " up to next seconds\n" .. i.n .. "\\" .. s
)
return
end
else
s = tonumber(i.s) + 1
end
if i.n >= i.all then
os.execute("sleep " .. tonumber(i.delay))
send(i.chat_id, 0, "Success sent\n" .. i.all .. "\\" .. s)
return
end
assert(
tdbot_function(
{
_ = "forwardMessages",
chat_id = tonumber(i.list[tonumber(i.n) + 1]),
from_chat_id = tonumber(i.chat_id),
message_ids = {[0] = tonumber(i.msg_id)},
disable_notification = 1,
from_background = 1
},
forwarding,
{
list = i.list,
max_i = i.max_i,
delay = i.delay,
n = tonumber(i.n) + 1,
all = i.all,
chat_id = i.chat_id,
msg_id = i.msg_id,
s = s
}
)
)
if tonumber(i.n) % tonumber(i.max_i) == 0 then
os.execute("sleep " .. tonumber(i.delay))
end
end
function sending(i, tg)
if tg and tg._ and tg._ == "error" then
s = i.s
else
s = tonumber(i.s) + 1
end
if i.n >= i.all then
os.execute("sleep " .. tonumber(i.delay))
send(i.chat_id, 0, "Success sent\n" .. i.all .. "\\" .. s)
return
end
assert(
tdbot_function(
{
_ = "sendMessage",
chat_id = tonumber(i.list[tonumber(i.n) + 1]),
reply_to_message_id = 0,
disable_notification = 0,
from_background = 1,
reply_markup = nil,
input_message_content = {
_ = "inputMessageText",
text = tostring(i.text),
disable_web_page_preview = true,
clear_draft = false,
entities = {},
parse_mode = nil
}
},
sending,
{
list = i.list,
max_i = i.max_i,
delay = i.delay,
n = tonumber(i.n) + 1,
all = i.all,
chat_id = i.chat_id,
text = i.text,
s = s
}
)
)
if tonumber(i.n) % tonumber(i.max_i) == 0 then
os.execute("sleep " .. tonumber(i.delay))
end
end
function adding(i, tg)
if tg and tg._ and tg._ == "error" then
s = i.s
if tg.code == 429 then
os.execute("sleep " .. tonumber(i.delay))
redis:del("tg:" .. Ads_id .. ":delay")
send(
i.chat_id,
0,
" restrict in operation " .. tostring(tg.message):match("%d+") .. " up to next seconds\n" .. i.n .. "\\" .. s
)
return
end
else
s = tonumber(i.s) + 1
end
if i.n >= i.all then
os.execute("sleep " .. tonumber(i.delay))
send(i.chat_id, 0, "Success added \n" .. i.all .. "\\" .. s)
return
end
assert(
tdbot_function(
{
_ = "searchPublicChat",
username = i.user_id
},
function(I, tg)
if tg.id then
tdbot_function(
{
_ = "addChatMember",
chat_id = tonumber(I.list[tonumber(I.n)]),
user_id = tonumber(tg.id),
forward_limit = 0
},
adding,
{
list = I.list,
max_i = I.max_i,
delay = I.delay,
n = tonumber(I.n),
all = I.all,
chat_id = I.chat_id,
user_id = I.user_id,
s = I.s
}
)
end
if tonumber(I.n) % tonumber(I.max_i) == 0 then
os.execute("sleep " .. tonumber(I.delay))
end
end,
{
list = i.list,
max_i = i.max_i,
delay = i.delay,
n = tonumber(i.n) + 1,
all = i.all,
chat_id = i.chat_id,
user_id = i.user_id,
s = s
}
)
)
end
function check_join(i, tg)
local bot_id = redis:get("tg:" .. Ads_id .. ":id") or get_bot()
if tg._ == "group" then
if (tg.everyone_is_administrator == false) then
assert(
tdbot_function(
{
_ = "changeChatMemberStatus",
chat_id = tonumber("-" .. tg.id),
user_id = tonumber(bot_id),
status = {_ = "chatMemberStatusLeft"}
},
cb or dl_cb,
nil
)
)
rem(tg.id)
end
elseif tg._ == "channel" then
if (tg.anyone_can_invite == false) then
assert(
tdbot_function(
{
_ = "changeChatMemberStatus",
chat_id = tonumber("-100" .. tg.id),
user_id = tonumber(bot_id),
status = {_ = "chatMemberStatusLeft"}
},
cb or dl_cb,
nil
)
)
rem(tg.id)
end
end
end
function add(id)
local Id = tostring(id)
if not redis:sismember("tg:" .. Ads_id .. ":all", id) then
if Id:match("^(%d+)$") then
redis:sadd("tg:" .. Ads_id .. ":users", id)
redis:sadd("tg:" .. Ads_id .. ":all", id)
elseif Id:match("^-100") then
redis:sadd("tg:" .. Ads_id .. ":supergroups", id)
redis:sadd("tg:" .. Ads_id .. ":all", id)
if redis:get("tg:" .. Ads_id .. ":openjoin") then
assert(
tdbot_function(
{
_ = "getChannel",
channel_id = tostring(Id:gsub("-100", ""))
},
check_join,
nil
)
)
end
else
redis:sadd("tg:" .. Ads_id .. ":groups", id)
redis:sadd("tg:" .. Ads_id .. ":all", id)
if redis:get("tg:" .. Ads_id .. ":openjoin") then
assert(
tdbot_function(
{
_ = "getGroup",
group_id = tostring(Id:gsub("-", ""))
},
check_join,
nil
)
)
end
end
end
return true
end
function rem(id)
local Id = tostring(id)
if redis:sismember("tg:" .. Ads_id .. ":all", id) then
if Id:match("^(%d+)$") then
redis:srem("tg:" .. Ads_id .. ":users", id)
redis:srem("tg:" .. Ads_id .. ":all", id)
elseif Id:match("^-100") then
redis:srem("tg:" .. Ads_id .. ":supergroups", id)
redis:srem("tg:" .. Ads_id .. ":all", id)
else
redis:srem("tg:" .. Ads_id .. ":groups", id)
redis:srem("tg:" .. Ads_id .. ":all", id)
end
end
return true
end
function mark_as_read(chat_id, message_ids)
tdbot_function(
{
_ = "ViewMessages",
chat_id = chat_id,
message_ids = message_ids
},
dl_cb,
extra
)
end
function get_msg_info(chat_id, message_id, cb_function, extra)
tdbot_function(
{
_ = "getMessage",
chat_id = chat_id,
message_id = message_id
},
cb_function,
extra
)
end
function getChats(offset_order, offset_chat_id, limit, cb, cmd)
if not limit or limit > 20 then
limit = 20
end
tdbot_function(
{
_ = "getChats",
offset_order = offset_order or 9223372036854775807,
offset_chat_id = offset_chat_id or 0,
limit = limit
},
cb or dl_cb,
cmd
)
end
function getMe(cb, cmd)
tdbot_function(
{
_ = "getMe"
},
cb or dl_cb,
cmd
)
end
function getMeCb(extra, result)
our_id = result.id
print("Our id: " .. our_id)
file = io.open("./data/config.lua", "r")
config = ""
repeat
line = file:read("*l")
if line then
line = string.gsub(line, "0", our_id)
config = config .. "\n" .. line
end
until not line
file:close()
file = io.open("./data/config.lua", "w")
file:write(config)
file:close()
end
function openChat(chat_id, cb, cmd)
tdbot_function(
{
_ = "openChat",
chat_id = chat_id
},
cb or dl_cb,
cmd
)
end
function getChat(chat_id, cb, cmd)
tdbot_function(
{
_ = "getChat",
chat_id = chat_id
},
cb or dl_cb,
cmd
)
end
function getChannelMembers(channel_id, offset, filter, limit, cb_function, cb_extra)
if not limit or limit > 200 then
limit = 200
end
tdbot_function(
{
_ = "getChannelMembers",
channel_id = getChatId(channel_id)._,
filter = {
_ = "channelMembersFilter" .. filter
},
offset = offset,
limit = limit
},
cb_function or cb_function,
cb_extra
)
end
function getInputFile(file)
if file:match("/") then
infile = {_ = "InputFileLocal", path = file}
elseif file:match("^%d+$") then
infile = {_ = "InputFileId", id = file}
else
infile = {_ = "InputFilePersistentId", persistent_id = file}
end
return infile
end
function chat_history(chat_id, from_message_id, offset, limit, cb_function, cb_extra)
if not limit or limit > 100 then
limit = 100
end
tdbot_function(
{
_ = "getChatHistory",
chat_id = chat_id,
from_message_id = from_message_id,
offset = offset or 0,
limit = limit
},
cb_function,
cb_extra
)
end
if not redis:get("tg:" .. Ads_id .. ":start") then
redis:sadd("tg:" .. Ads_id .. ":strt", "settings")
else
redis:sadd("tg:" .. Ads_id .. ":lod", "settings")
end
function send(chat_id, msg_id, text)
assert(
tdbot_function(
{
_ = "sendMessage",
chat_id = chat_id,
reply_to_message_id = 0,
disable_notification = 0,
from_background = 1,
reply_markup = nil,
input_message_content = {
_ = "inputMessageText",
text = text,
disable_web_page_preview = 1,
clear_draft = 0,
parse_mode = nil,
entities = {}
}
},
dl_cb,
nil
)
)
end
function bot_init(msg)
local receiver = msg.to.id
local text = text or "[other]"
if msg.from then
redis:sadd("chat:" .. receiver .. ":members", msg.from.id)
end
if msg then
mark_as_read(receiver, {[0] = msg.id})
end
end
function chat_info(msg)
tdbot_function(
{
_ = "getChat",
chat_id = msg.to.id
},
chat_info_cb,
msg
)
end
function chat_info_cb(msg, data)
msg.to.title = data.title
bot_init(msg)
end
function user_reply_callback(msg, message)
msg = reply_data(msg, message)
chat_info(msg)
end
function reply_callback(msg, message)
msg.replied.id = message.sender_user_id
tdbot_function(
{
_ = "getUser",
user_id = msg.replied.id