forked from soroushmirzaei/telegram-configs-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
1563 lines (1284 loc) · 86 KB
/
main.py
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
#import requirement libraries
import os
import wget
import json
from pathlib import Path
import math
import string
import random
import jdatetime
from datetime import datetime, timezone, timedelta
#import web-based libraries
import html
import requests
from bs4 import BeautifulSoup
#import regex and encoding libraries
import re
import base64
#import custom python script
from title import check_modify_config, create_country, create_country_table, create_internet_protocol
# Create the geoip-lite folder if it doesn't exist
if not os.path.exists('./geoip-lite'):
os.mkdir('./geoip-lite')
if os.path.exists('./geoip-lite/geoip-lite-country.mmdb'):
os.remove('./geoip-lite/geoip-lite-country.mmdb')
# Download the file and rename it
url = 'https://git.io/GeoLite2-Country.mmdb'
filename = 'geoip-lite-country.mmdb'
wget.download(url, filename)
# Move the file to the geoip folder
os.rename(filename, os.path.join('./geoip-lite', filename))
# Clean up unmatched file
with open("./splitted/no-match", "w") as no_match_file:
no_match_file.write("#Non-Adaptive Configurations\n")
# Load and read last date and time update
with open('./last update', 'r') as file:
last_update_datetime = file.readline()
last_update_datetime = datetime.strptime(last_update_datetime, '%Y-%m-%d %H:%M:%S.%f%z')
# Write the current date and time update
with open('./last update', 'w') as file:
current_datetime_update = datetime.now(tz = timezone(timedelta(hours = 3, minutes = 30)))
jalali_current_datetime_update = jdatetime.datetime.now(tz = timezone(timedelta(hours = 3, minutes = 30)))
file.write(f'{current_datetime_update}')
print(f"Latest Update: {last_update_datetime.strftime('%a, %d %b %Y %X %Z')}\nCurrent Update: {current_datetime_update.strftime('%a, %d %b %Y %X %Z')}")
def get_absolute_paths(start_path):
abs_paths = []
for root, dirs, files in os.walk(start_path):
for file in files:
abs_path = Path(root).joinpath(file).resolve()
abs_paths.append(str(abs_path))
return abs_paths
dirs_list = ['./security', './protocols', './networks', './layers'
'./subscribe', './splitted', './channels']
if (int(jalali_current_datetime_update.day) == 1 and int(jalali_current_datetime_update.hour) == 0) or (int(jalali_current_datetime_update.day) == 15 and int(jalali_current_datetime_update.hour) == 0):
print("The All Collected Configurations Cleared Based On Scheduled Day".title())
last_update_datetime = last_update_datetime - timedelta(days=3)
print(f"The Latest Update Time Is Set To {last_update_datetime.strftime('%a, %d %b %Y %X %Z')}".title())
for root_dir in dirs_list:
for path in get_absolute_paths(root_dir):
if not path.endswith('readme.md'):
with open(path, 'w') as file:
file.write('')
file.close
else:
continue
def json_load(path):
# Open and read the json file
with open(path, 'r') as file:
# Load json file content into list
list_content = json.load(file)
# Return list of json content
return list_content
def tg_channel_messages(channel_user):
try:
# Retrieve channels messages
response = requests.get(f"https://t.me/s/{channel_user}")
soup = BeautifulSoup(response.text, "html.parser")
# Find all telegram widget messages
div_messages = soup.find_all("div", class_="tgme_widget_message")
# Return list of all messages in channel
return div_messages
except Exception as exc:
pass
def find_matches(text_content):
# Initialize configuration type patterns
pattern_telegram_user = r'(?:@)(\w{4,})'
pattern_url = r'(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)/)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’])|(?:(?<!@)[a-z0-9]+(?:[.\-][a-z0-9]+)*[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)\b/?(?!@)))'
pattern_shadowsocks = r"(?<![\w-])(ss://[^\s<>#]+)"
pattern_trojan = r"(?<![\w-])(trojan://[^\s<>#]+)"
pattern_vmess = r"(?<![\w-])(vmess://[^\s<>#]+)"
pattern_vless = r"(?<![\w-])(vless://(?:(?!=reality)[^\s<>#])+(?=[\s<>#]))"
pattern_reality = r"(?<![\w-])(vless://[^\s<>#]+?security=reality[^\s<>#]*)"
pattern_tuic = r"(?<![\w-])(tuic://[^\s<>#]+)"
pattern_hysteria = r"(?<![\w-])(hysteria://[^\s<>#]+)"
pattern_hysteria_ver2 = r"(?<![\w-])(hy2://[^\s<>#]+)"
pattern_juicity = r"(?<![\w-])(juicity://[^\s<>#]+)"
# Find all matches of patterns in text
matches_usersname = re.findall(pattern_telegram_user, text_content, re.IGNORECASE)
matches_url = re.findall(pattern_url, text_content, re.IGNORECASE)
matches_shadowsocks = re.findall(pattern_shadowsocks, text_content, re.IGNORECASE)
matches_trojan = re.findall(pattern_trojan, text_content, re.IGNORECASE)
matches_vmess = re.findall(pattern_vmess, text_content, re.IGNORECASE)
matches_vless = re.findall(pattern_vless, text_content, re.IGNORECASE)
matches_reality = re.findall(pattern_reality, text_content, re.IGNORECASE)
matches_tuic = re.findall(pattern_tuic, text_content)
matches_hysteria = re.findall(pattern_hysteria, text_content)
matches_hysteria_ver2 = re.findall(pattern_hysteria_ver2, text_content)
matches_juicity = re.findall(pattern_juicity, text_content)
# Iterate over matches to subtract titles
for index, element in enumerate(matches_vmess):
matches_vmess[index] = re.sub(r"#[^#]+$", "", html.unescape(element))
for index, element in enumerate(matches_shadowsocks):
matches_shadowsocks[index] = (re.sub(r"#[^#]+$", "", html.unescape(element))+ f"#SHADOWSOCKS")
for index, element in enumerate(matches_trojan):
matches_trojan[index] = (re.sub(r"#[^#]+$", "", html.unescape(element))+ f"#TROJAN")
for index, element in enumerate(matches_vless):
matches_vless[index] = (re.sub(r"#[^#]+$", "", html.unescape(element))+ f"#VLESS")
for index, element in enumerate(matches_reality):
matches_reality[index] = (re.sub(r"#[^#]+$", "", html.unescape(element))+ f"#REALITY")
for index, element in enumerate(matches_tuic):
matches_tuic[index] = (re.sub(r"#[^#]+$", "", html.unescape(element))+ f"#TUIC")
for index, element in enumerate(matches_hysteria):
matches_hysteria[index] = (re.sub(r"#[^#]+$", "", html.unescape(element))+ f"#HYSTERIA")
for index, element in enumerate(matches_hysteria_ver2):
matches_hysteria_ver2[index] = (re.sub(r"#[^#]+$", "", html.unescape(element))+ f"#HYSTERIA")
for index, element in enumerate(matches_juicity):
matches_juicity[index] = (re.sub(r"#[^#]+$", "", html.unescape(element))+ f"#JUICITY")
matches_shadowsocks = [x for x in matches_shadowsocks if "…" not in x]
matches_trojan = [x for x in matches_trojan if "…" not in x]
matches_vmess = [x for x in matches_vmess if "…" not in x]
matches_vless = [x for x in matches_vless if "…" not in x]
matches_reality = [x for x in matches_reality if "…" not in x]
matches_tuic = [x for x in matches_tuic if "…" not in x]
matches_hysteria = [x for x in matches_hysteria if "…" not in x]
matches_hysteria_ver2 = [x for x in matches_hysteria_ver2 if "…" not in x]
matches_juicity = [x for x in matches_juicity if "…" not in x]
# Extend hysteria versions
matches_hysteria.extend(matches_hysteria_ver2)
return matches_usersname, matches_url, matches_shadowsocks, matches_trojan, matches_vmess, matches_vless, matches_reality, matches_tuic, matches_hysteria, matches_juicity
def tg_message_time(div_message):
# Retrieve channel message info
div_message_info = div_message.find('div', class_='tgme_widget_message_info')
# Retrieve channel message datetime
message_datetime_tag = div_message_info.find('time')
message_datetime = message_datetime_tag.get('datetime')
# Change message datetime type into object and convert into Iran datetime
datetime_object = datetime.fromisoformat(message_datetime)
datetime_object = datetime.astimezone(datetime_object, tz = timezone(timedelta(hours = 3, minutes = 30)))
# Retrieve now datetime based on Iran timezone
datetime_now = datetime.now(tz = timezone(timedelta(hours = 3, minutes = 30)))
# Return datetime object, current datetime based on Iran datetime and delta datetime
return datetime_object, datetime_now, datetime_now - datetime_object
def tg_message_text(div_message, content_extracter):
# Retrieve message text class from telegram messages widget
div_message_text = div_message.find("div", class_="tgme_widget_message_text")
text_content = div_message_text.prettify()
if content_extracter == 'url':
text_content = re.sub(r"<code>([^<>]+)</code>", r"\1",re.sub(r"\s*", "", text_content),)
elif content_extracter == 'config':
text_content = re.sub(r"<code>([^<>]+)</code>", r"\1",
re.sub(r"<a[^<>]+>([^<>]+)</a>", r"\1",re.sub(r"\s*", "", text_content),),)
# Return text content
return text_content
# Load telegram channels usernames
telegram_channels = json_load('telegram channels.json')
# Initial channels messages array
channel_messages_array = list()
removed_channel_array = list()
channel_check_messages_array = list()
# Iterate over all public telegram chanels and store twenty latest messages
for channel_user in telegram_channels:
try:
print(f'{channel_user}')
# Iterate over Telegram channels to Retrieve channel messages and extend to array
div_messages = tg_channel_messages(channel_user)
# Append destroyed Telegram channels
if len(div_messages) == 0:
removed_channel_array.append(channel_user)
# Check configuation Telegram channels
channel_check_messages_array.append((channel_user, div_messages))
for div_message in div_messages:
datetime_object, datetime_now, delta_datetime_now = tg_message_time(div_message)
if datetime_object > last_update_datetime:
print(f"\t{datetime_object.strftime('%a, %d %b %Y %X %Z')}")
channel_messages_array.append((channel_user, div_message))
except Exception as exc:
continue
# Print out total new messages counter
print(f"\nTotal New Messages From {last_update_datetime.strftime('%a, %d %b %Y %X %Z')} To {current_datetime_update.strftime('%a, %d %b %Y %X %Z')} : {len(channel_messages_array)}\n")
# Initial arrays for protocols
array_usernames = list()
array_url = list()
array_shadowsocks = list()
array_trojan = list()
array_vmess = list()
array_vless = list()
array_reality = list()
array_tuic = list()
array_hysteria = list()
array_juicity = list()
for channel_user, message in channel_messages_array:
try:
# Iterate over channel messages to extract text content
url_text_content = tg_message_text(message, 'url')
config_text_content = tg_message_text(message, 'config')
# Iterate over each message to extract configuration protocol types and subscription links
matches_username, matches_url, _ , _ , _ , _ , _ , _ , _ , _ = find_matches(url_text_content)
_ , _ , matches_shadowsocks, matches_trojan, matches_vmess, matches_vless, matches_reality, matches_tuic, matches_hysteria, matches_juicity = find_matches(config_text_content)
# Extend protocol type arrays and subscription link array
array_usernames.extend([element.lower() for element in matches_username if len(element) >= 5])
array_url.extend(matches_url)
array_shadowsocks.extend(matches_shadowsocks)
array_trojan.extend(matches_trojan)
array_vmess.extend(matches_vmess)
array_vless.extend(matches_vless)
array_reality.extend(matches_reality)
array_tuic.extend(matches_tuic)
array_hysteria.extend(matches_hysteria)
array_juicity.extend(matches_juicity)
except Exception as exc:
continue
# Initialize Telegram channels list without configuration
channel_without_config = set()
for channel_user, messages in channel_check_messages_array:
# Initialize Channel Configs Counter
total_config = 0
for message in messages:
try:
# Iterate over channel messages to extract text content
url_text_content = tg_message_text(message, 'url')
config_text_content = tg_message_text(message, 'config')
# Iterate over each message to extract configuration protocol types and subscription links
matches_username, matches_url, _ , _ , _ , _ , _ , _ , _ , _ = find_matches(url_text_content)
_ , _ , matches_shadowsocks, matches_trojan, matches_vmess, matches_vless, matches_reality, matches_tuic, matches_hysteria, matches_juicity = find_matches(config_text_content)
total_config = total_config + len(matches_shadowsocks) + len(matches_trojan) + len(matches_vmess) + len(matches_vless) + len(matches_reality) + len(matches_tuic) + len(matches_hysteria) + len(matches_juicity)
except Exception as exc:
continue
if total_config == 0:
channel_without_config.add(channel_user)
def tg_username_extract(url):
telegram_pattern = r'((http|Http|HTTP)://|(https|Https|HTTPS)://|(www|Www|WWW)\.|https://www\.|)(?P<telegram_domain>(t|T)\.(me|Me|ME)|(telegram|Telegram|TELEGRAM)\.(me|Me|ME)|(telegram|Telegram|TELEGRAM).(org|Org|ORG)|telesco.pe|(tg|Tg|TG).(dev|Dev|DEV)|(telegram|Telegram|TELEGRAM).(dog|Dog|DOG))/(?P<username>[a-zA-Z0-9_+-]+)'
matches_url = re.match(telegram_pattern, url)
return matches_url.group('username')
# Split Telegram usernames and subscription url links
tg_username_list = set()
url_subscription_links = set()
for url in array_url:
try:
tg_user = tg_username_extract(url)
if tg_user not in ['proxy', 'img', 'emoji', 'joinchat'] and '+' not in tg_user and '-' not in tg_user and len(tg_user)>=5:
tg_user = ''.join([element for element in list(tg_user) if element in string.ascii_letters + string.digits + '_'])
tg_username_list.add(tg_user.lower())
except:
url_subscription_links.add(url.split("\"")[0])
continue
for index, tg_user in enumerate(array_usernames):
tg_user = ''.join([element for element in list(tg_user) if element in string.ascii_letters + string.digits + '_'])
array_usernames[index] = tg_user
# Retrive and update channels from telegram proxies Repository
url = 'https://raw.githubusercontent.com/soroushmirzaei/telegram-proxies-collector/main/telegram channels.json'
filename = 'telegram proxies channel.json'
wget.download(url, filename)
tg_username_list.update(array_usernames)
telegram_proxies_channel = json_load('./telegram proxies channel.json')
tg_username_list.update(telegram_proxies_channel)
os.remove('./telegram proxies channel.json')
# Subtract and get new telegram channels
new_telegram_channels = tg_username_list.difference(telegram_channels)
# Initial channels messages array
new_channel_messages = list()
invalid_array_channels = json_load('invalid telegram channels.json')
invalid_array_channels = set(invalid_array_channels)
# Iterate over all public telegram chanels and store twenty latest messages
for channel_user in new_telegram_channels:
if channel_user not in invalid_array_channels:
try:
print(f'{channel_user}')
# Iterate over Telegram channels to Retrieve channel messages and extend to array
div_messages = tg_channel_messages(channel_user)
channel_messages = list()
for div_message in div_messages:
datetime_object, datetime_now, delta_datetime_now = tg_message_time(div_message)
print(f"\t{datetime_object.strftime('%a, %d %b %Y %X %Z')}")
channel_messages.append(div_message)
new_channel_messages.append((channel_user, channel_messages))
except:
continue
else:
continue
# Messages Counter
print(f"\nTotal New Messages From New Channels {last_update_datetime.strftime('%a, %d %b %Y %X %Z')} To {current_datetime_update.strftime('%a, %d %b %Y %X %Z')} : {len(new_channel_messages)}\n")
# Initial arrays for protocols
new_array_shadowsocks = list()
new_array_trojan = list()
new_array_vmess = list()
new_array_vless = list()
new_array_reality = list()
new_array_tuic = list()
new_array_hysteria = list()
new_array_juicity = list()
# Initialize array for channelswith configuration contents
new_array_channels = set()
for channel, messages in new_channel_messages:
# Set Iterator to estimate each channel configurations
total_config = 0
new_array_url = set()
new_array_usernames = set()
for message in messages:
try:
# Iterate over channel messages to extract text content
url_text_content = tg_message_text(message, 'url')
config_text_content = tg_message_text(message, 'config')
# Iterate over each message to extract configuration protocol types and subscription links
matches_username, matches_url, _ , _ , _ , _ , _ , _ , _ , _ = find_matches(url_text_content)
_ , _ , matches_shadowsocks, matches_trojan, matches_vmess, matches_vless, matches_reality, matches_tuic, matches_hysteria, matches_juicity = find_matches(config_text_content)
total_config = total_config + len(matches_shadowsocks) + len(matches_trojan) + len(matches_vmess) + len(matches_vless) + len(matches_reality) + len(matches_tuic) + len(matches_hysteria) + len(matches_juicity)
# Extend protocol type arrays and subscription link array
new_array_usernames.update([element.lower() for element in matches_username if len(element) >= 5])
new_array_url.update(matches_url)
new_array_shadowsocks.extend(matches_shadowsocks)
new_array_trojan.extend(matches_trojan)
new_array_vmess.extend(matches_vmess)
new_array_vless.extend(matches_vless)
new_array_reality.extend(matches_reality)
new_array_tuic.extend(matches_tuic)
new_array_hysteria.extend(matches_hysteria)
new_array_juicity.extend(matches_juicity)
except Exception as exc:
continue
# Append to channels that conatins configurations
if total_config != 0:
new_array_channels.add(channel)
else:
invalid_array_channels.add(channel)
# Split Telegram usernames and subscription url links
tg_username_list_new = set()
for url in new_array_url:
try:
tg_user = tg_username_extract(url)
if tg_user not in ['proxy', 'img', 'emoji', 'joinchat'] and '+' not in tg_user and '-' not in tg_user and len(tg_user)>=5:
tg_user = ''.join([element for element in list(tg_user) if element in string.ascii_letters + string.digits + '_'])
tg_username_list_new.add(tg_user.lower())
except:
url_subscription_links.add(url.split("\"")[0])
continue
new_array_usernames = list(new_array_usernames)
for index, tg_user in enumerate(new_array_usernames):
tg_user = ''.join([element for element in list(tg_user) if element in string.ascii_letters + string.digits + '_'])
new_array_usernames[index] = tg_user
# Subtract and get new telegram channels
tg_username_list_new.update([element.lower() for element in new_array_usernames])
tg_username_list_new = tg_username_list_new.difference(telegram_channels)
tg_username_list_new = tg_username_list_new.difference(new_telegram_channels)
updated_new_channel = set(list(map(lambda element : element[0], new_channel_messages)))
tg_username_list_new = tg_username_list_new.difference(updated_new_channel)
# Iterate over all public telegram chanels and store twenty latest messages
for channel_user in tg_username_list_new:
if channel_user not in invalid_array_channels:
try:
print(f'{channel_user}')
# Iterate over Telegram channels to Retrieve channel messages and extend to array
div_messages = tg_channel_messages(channel_user)
channel_messages = list()
for div_message in div_messages:
datetime_object, datetime_now, delta_datetime_now = tg_message_time(div_message)
#print(f"\t{datetime_object.strftime('%a, %d %b %Y %X %Z')}")
channel_messages.append(div_message)
#new_channel_messages.append((channel_user, channel_messages))
except:
continue
else:
continue
# Extend new configurations into list previous ones
array_shadowsocks.extend(new_array_shadowsocks)
array_trojan.extend(new_array_trojan)
array_vmess.extend(new_array_vmess)
array_vless.extend(new_array_vless)
array_reality.extend(new_array_reality)
array_tuic.extend(new_array_tuic)
array_hysteria.extend(new_array_hysteria)
array_juicity.extend(new_array_juicity)
print("New Telegram Channels Found")
for channel in new_array_channels:
print('\t{value}'.format(value = channel))
print("Destroyed Telegram Channels Found")
for channel in removed_channel_array:
print('\t{value}'.format(value = channel))
print("No Config Telegram Channels Found")
for channel in channel_without_config:
print('\t{value}'.format(value = channel))
# Extend new channels into previous channels
telegram_channels.extend(new_array_channels)
#telegram_channels = [channel for channel in telegram_channels if channel not in removed_channel_array and channel not in channel_without_config]
telegram_channels = [channel for channel in telegram_channels if channel not in removed_channel_array]
telegram_channels = list(set(telegram_channels))
telegram_channels = sorted(telegram_channels)
invalid_telegram_channels = list(set(invalid_array_channels))
invalid_telegram_channels = sorted(invalid_telegram_channels)
with open('./telegram channels.json', 'w') as telegram_channels_file:
json.dump(telegram_channels, telegram_channels_file, indent = 4)
with open('./invalid telegram channels.json', 'w') as invalid_telegram_channels_file:
json.dump(invalid_telegram_channels, invalid_telegram_channels_file, indent = 4)
def html_content(html_address):
# Retrieve subscription link content
response = requests.get(html_address, timeout = 10)
soup = BeautifulSoup(response.text, 'html.parser').text
return soup
def is_valid_base64(string_value):
try:
# Decode the string using base64
byte_decoded = base64.b64decode(string_value)
# Encode the decoded bytes back to base64 and compare to the original string
return base64.b64encode(byte_decoded).decode("utf-8") == string_value
except:
return False
def decode_string(content):
# Decode strings and append to array
if is_valid_base64(content):
content = base64.b64decode(content).decode("utf-8")
return content
def decode_vmess(vmess_config):
try:
encoded_config = re.sub(r"vmess://", "", vmess_config)
decoded_config = base64.b64decode(encoded_config).decode("utf-8")
decoded_config_dict = json.loads(decoded_config)
decoded_config_dict["ps"] = f"VMESS"
decoded_config = json.dumps(decoded_config_dict)
encoded_config = decoded_config.encode('utf-8')
encoded_config = base64.b64encode(encoded_config).decode('utf-8')
encoded_config = f"vmess://{encoded_config}"
return encoded_config
except:
return None
# Update url subscription links
url_subscription_links = list(url_subscription_links)
new_tg_username_list = set()
new_url_subscription_links = set()
for url in url_subscription_links:
try:
tg_user = tg_username_extract(url)
if tg_user not in ['proxy', 'img', 'emoji', 'joinchat']:
new_tg_username_list.add(tg_user.lower())
except:
new_url_subscription_links.add(url.split("\"")[0])
continue
# Chnage type of url subscription links into list to be hashable
new_url_subscription_links = list(new_url_subscription_links)
accept_chars = ['sub', 'subscribe', 'token', 'workers', 'worker', 'dev', 'txt', 'vmess', 'vless', 'reality', 'trojan', 'shadowsocks']
avoid_chars = ['github', 'githubusercontent', 'gist', 'git', 'google', 'play', 'apple', 'microsoft']
new_subscription_links = set()
for index, element in enumerate(new_url_subscription_links):
acc_cond = [char in element.lower() for char in accept_chars]
avoid_cond = [char in element.lower() for char in avoid_chars]
if any(acc_cond):
if not any(avoid_cond):
new_subscription_links.add(element)
# Load subscription links
subscription_links = json_load('subscription links.json')
# subscription_links.extend(new_subscription_links)
# Initial links contents array decoded content array
array_links_content = list()
array_links_content_decoded = list()
raw_array_links_content = list()
raw_array_links_content_decoded = list()
channel_array_links_content = list()
channel_array_links_content_decoded = list()
for url_link in subscription_links:
try:
# Retrieve subscription link content
links_content = html_content(url_link)
array_links_content.append((url_link, links_content))
if 'soroushmirzaei' not in url_link:
raw_array_links_content.append((url_link, links_content))
elif 'soroushmirzaei' in url_link and 'channels' in url_link:
channel_array_links_content.append((url_link, links_content))
except:
continue
# Separate encoded and unencoded strings
decoded_contents = list(map(lambda element : (element[0], decode_string(element[1])), array_links_content))
# Separate encoded and unencoded strings
raw_decoded_contents = list(map(lambda element : (element[0], decode_string(element[1])), raw_array_links_content))
# Separate encoded and unencoded strings
channel_decoded_contents = list(map(lambda element : (element[0], decode_string(element[1])), channel_array_links_content))
for url_link, content in decoded_contents:
try:
# Split each link contents into array and split by lines
link_contents = content.splitlines()
link_contents = [element for element in link_contents if element not in ['\n','\t','']]
# Iterate over link contents to subtract titles
for index, element in enumerate(link_contents):
link_contents[index] = re.sub(r"#[^#]+$", "", element)
array_links_content_decoded.append((url_link, link_contents))
except:
continue
for url_link, content in raw_decoded_contents:
try:
# Split each link contents into array and split by lines
link_contents = content.splitlines()
link_contents = [element for element in link_contents if element not in ['\n','\t','']]
# Iterate over link contents to subtract titles
for index, element in enumerate(link_contents):
link_contents[index] = re.sub(r"#[^#]+$", "", element)
raw_array_links_content_decoded.append((url_link, link_contents))
except:
continue
for url_link, content in channel_decoded_contents:
try:
# Split each link contents into array and split by lines
link_contents = content.splitlines()
link_contents = [element for element in link_contents if element not in ['\n','\t','']]
# Iterate over link contents to subtract titles
for index, element in enumerate(link_contents):
link_contents[index] = re.sub(r"#[^#]+$", "", element)
channel_array_links_content_decoded.append((url_link, link_contents))
except:
continue
new_subscription_urls = set()
matches_usernames = list()
matches_url = list()
matches_shadowsocks = list()
matches_trojan = list()
matches_vmess = list()
matches_vless = list()
matches_reality = list()
matches_tuic = list()
matches_hysteria = list()
matches_juicity = list()
raw_matches_usernames = list()
raw_matches_url = list()
raw_matches_shadowsocks = list()
raw_matches_trojan = list()
raw_matches_vmess = list()
raw_matches_vless = list()
raw_matches_reality = list()
raw_matches_tuic = list()
raw_matches_hysteria = list()
raw_matches_juicity = list()
channel_matches_usernames = list()
channel_matches_url = list()
channel_matches_shadowsocks = list()
channel_matches_trojan = list()
channel_matches_vmess = list()
channel_matches_vless = list()
channel_matches_reality = list()
channel_matches_tuic = list()
channel_matches_hysteria = list()
channel_matches_juicity = list()
for url_link, content in array_links_content_decoded:
# Merge all subscription links content and find all protocols matches base on protocol pattern
content_merged = "\n".join(content)
match_user, match_url, match_socks, match_trojan, match_vmess, match_vless, match_reality, match_tuic, match_hysteria, match_juicity = find_matches(content_merged)
if len(match_socks) + len(match_trojan) + len(match_vmess) + len(match_vless) + len(match_reality) + len(match_tuic) + len(match_hysteria) + len(match_juicity) != 0:
new_subscription_urls.add(url_link)
matches_usernames.extend(match_user)
matches_url.extend(match_url)
matches_shadowsocks.extend(match_socks)
matches_trojan.extend(match_trojan)
matches_vmess.extend(match_vmess)
matches_vless.extend(match_vless)
matches_reality.extend(match_reality)
matches_tuic.extend(match_tuic)
matches_hysteria.extend(match_hysteria)
matches_juicity.extend(match_juicity)
for url_link, content in raw_array_links_content_decoded:
# Merge all subscription links content and find all protocols matches base on protocol pattern
raw_content_merged = "\n".join(content)
match_user, match_url, match_socks, match_trojan, match_vmess, match_vless, match_reality, match_tuic, match_hysteria, match_juicity = find_matches(raw_content_merged)
raw_matches_usernames.extend(match_user)
raw_matches_url.extend(match_url)
raw_matches_shadowsocks.extend(match_socks)
raw_matches_trojan.extend(match_trojan)
raw_matches_vmess.extend(match_vmess)
raw_matches_vless.extend(match_vless)
raw_matches_reality.extend(match_reality)
raw_matches_tuic.extend(match_tuic)
raw_matches_hysteria.extend(match_hysteria)
raw_matches_juicity.extend(match_juicity)
for url_link, content in channel_array_links_content_decoded:
# Merge all subscription links content and find all protocols matches base on protocol pattern
raw_content_merged = "\n".join(content)
match_user, match_url, match_socks, match_trojan, match_vmess, match_vless, match_reality, match_tuic, match_hysteria, match_juicity = find_matches(raw_content_merged)
channel_matches_usernames.extend(match_user)
channel_matches_url.extend(match_url)
channel_matches_shadowsocks.extend(match_socks)
channel_matches_trojan.extend(match_trojan)
channel_matches_vmess.extend(match_vmess)
channel_matches_vless.extend(match_vless)
channel_matches_reality.extend(match_reality)
channel_matches_tuic.extend(match_tuic)
channel_matches_hysteria.extend(match_hysteria)
channel_matches_juicity.extend(match_juicity)
# Save New Subscription Links
# with open('./subscription links.json', 'w') as subscription_file:
# json.dump(sorted(new_subscription_urls), subscription_file, indent = 4)
def remove_duplicate_modified(array_configuration):
# Initialize list for sorted configs
country_config_dict = dict()
for config in array_configuration:
try:
if config.startswith('ss'):
pattern = r"ss://(?P<id>[^@]+)@\[?(?P<ip>[a-zA-Z0-9\.:-]+?)\]?:(?P<port>[0-9]+)/?#?(?P<title>(?<=#).*)?"
shadowsocks_match = re.match(pattern, config, flags=re.IGNORECASE)
ip = shadowsocks_match.group("ip")
port = shadowsocks_match.group("port")
id = shadowsocks_match.group("id")
non_title_config = f"SS-{ip}:{port}"
country_config_dict[non_title_config] = config
if config.startswith('trojan'):
pattern = r"trojan://(?P<id>[^@]+)@\[?(?P<ip>[a-zA-Z0-9\.:-]+?)\]?:(?P<port>[0-9]+)/?\??(?P<params>[^#]+)?#?(?P<title>(?<=#).*)?"
trojan_match = re.match(pattern, config, flags=re.IGNORECASE)
ip = trojan_match.group("ip")
port = trojan_match.group("port")
id = trojan_match.group("id")
non_title_config = f"TR-{ip}:{port}"
country_config_dict[non_title_config] = config
if config.startswith('vless'):
pattern = r"vless://(?P<id>[^@]+)@\[?(?P<ip>[a-zA-Z0-9\.:-]+?)\]?:(?P<port>[0-9]+)/?\?(?P<params>[^#]+)#?(?P<title>(?<=#).*)?"
vless_match = re.match(pattern, config, flags=re.IGNORECASE)
ip = vless_match.group("ip")
port = vless_match.group("port")
id = vless_match.group("id")
param = vless_match.group("params")
# Split configuration parameters and initialize dict for parameters
array_params_input = param.split("&")
dict_params = {}
# Iterate over parameters and split based on key value
for pair in array_params_input:
try:
key, value = pair.split("=")
key = re.sub(r"servicename", "serviceName", re.sub(r"headertype", "headerType", re.sub(r"allowinsecure", "allowInsecure", key.lower()),),)
dict_params[key.lower()] = value.lower() if type(value) == str else value
except:
pass
dict_params = {k: v for k, v in sorted(dict_params.items(), key=lambda item: item[0])}
non_title_config = f"VL-{ip}:{port}"
country_config_dict[non_title_config] = config
if config.startswith('vmess'):
vmess_pattern = r"vmess://(?P<json>[^#].*)"
vmess_match = re.match(vmess_pattern, config, flags=re.IGNORECASE)
json_string = vmess_match.group('json')
json_string = base64.b64decode(json_string).decode("utf-8", errors="ignore")
dict_params = json.loads(json_string)
dict_params = {k.lower(): v.lower() if type(v) == str else v for k, v in dict_params.items()}
ip = dict_params.get("ip")
port = dict_params.get("port")
id = dict_params.get("id")
dict_params['ps'] = ''
dict_params = {k: v for k, v in sorted(dict_params.items(), key=lambda item: item[0])}
non_title_config = f"VM-{ip}:{port}"
country_config_dict[non_title_config] = config
if config.startswith('tuic'):
pattern = r"tuic://(?P<id>[^:]+):(?P<pass>[^@]+)@\[?(?P<ip>[a-zA-Z0-9\.:-]+?)\]?:(?P<port>[0-9]+)/?\?(?P<params>[^#]+)#?(?P<title>(?<=#).*)?"
tuic_match = re.match(pattern, config, flags=re.IGNORECASE)
ip = tuic_match.group("ip")
port = tuic_match.group("port")
id = tuic_match.group("id")
password = tuic_match.group("pass")
non_title_config = f"TUIC-{ip}:{port}"
country_config_dict[non_title_config] = config
if config.startswith('hysteria'):
pattern = r"hysteria://\[?(?P<ip>[a-zA-Z0-9\.:-]+?)\]?:(?P<port>[0-9]+)/?\?(?P<params>[^#]+)#?(?P<title>(?<=#).*)?"
hysteria_match = re.match(pattern, config, flags=re.IGNORECASE)
ip = hysteria_match.group("ip")
port = hysteria_match.group("port")
non_title_config = f"HYSTERIA1-{ip}:{port}"
country_config_dict[non_title_config] = config
if config.startswith('hy2'):
pattern = r"hy2://(?P<pass>[^@]+)@\[?(?P<ip>[a-zA-Z0-9\.:-]+?)\]?:(?P<port>[0-9]+)/?\?(?P<params>[^#]+)#?(?P<title>(?<=#).*)?"
hysteria_match = re.match(pattern, config, flags=re.IGNORECASE)
ip = hysteria_match.group("ip")
port = hysteria_match.group("port")
password = hysteria_match.group("pass")
non_title_config = f"HYSTERIA2-{ip}:{port}"
country_config_dict[non_title_config] = config
except:
continue
return list(country_config_dict.values())
def remove_duplicate(shadow_array, trojan_array, vmess_array, vless_array, reality_array, tuic_array, hysteria_array, juicity_array, vmess_decode_dedup = True):
# Remove duplicate configurations of telegram channels
shadow_array = list(set(shadow_array))
trojan_array = list(set(trojan_array))
vmess_array = list(set(vmess_array))
vless_array = list(set(vless_array))
reality_array = list(set(reality_array))
tuic_array = list(set(tuic_array))
hysteria_array = list(set(hysteria_array))
juicity_array = list(set(juicity_array))
if vmess_decode_dedup:
# Decode vmess configs to change title and remove duplicate
for index, element in enumerate(vmess_array):
vmess_array[index] = decode_vmess(element)
vmess_array = [config for config in vmess_array if config != None]
vmess_array = list(set(vmess_array))
return shadow_array, trojan_array, vmess_array, vless_array, reality_array, tuic_array, hysteria_array, juicity_array
def modify_config(shadow_array, trojan_array, vmess_array, vless_array, reality_array, tuic_array, hysteria_array, check_port_connection = True):
# Checkout connectivity and modify title and protocol type address and resolve IP address
shadow_array, shadow_tls_array, shadow_non_tls_array, shadow_tcp_array, shadow_ws_array, shadow_http_array, shadow_grpc_array = check_modify_config(array_configuration = shadow_array, protocol_type = "SHADOWSOCKS", check_connection = check_port_connection)
trojan_array, trojan_tls_array, trojan_non_tls_array, trojan_tcp_array, trojan_ws_array, trojan_http_array, trojan_grpc_array = check_modify_config(array_configuration = trojan_array, protocol_type = "TROJAN", check_connection = check_port_connection)
vmess_array, vmess_tls_array, vmess_non_tls_array, vmess_tcp_array, vmess_ws_array, vmess_http_array, vmess_grpc_array = check_modify_config(array_configuration = vmess_array, protocol_type = "VMESS", check_connection = check_port_connection)
vless_array, vless_tls_array, vless_non_tls_array, vless_tcp_array, vless_ws_array, vless_http_array, vless_grpc_array = check_modify_config(array_configuration = vless_array, protocol_type = "VLESS", check_connection = check_port_connection)
reality_array, reality_tls_array, reality_non_tls_array, reality_tcp_array, reality_ws_array, reality_http_array, reality_grpc_array = check_modify_config(array_configuration = reality_array, protocol_type = "REALITY", check_connection = check_port_connection)
tuic_array, _, _, _, _, _, _ = check_modify_config(array_configuration = tuic_array, protocol_type = "TUIC", check_connection = False)
hysteria_array, _, _, _, _, _, _ = check_modify_config(array_configuration = hysteria_array, protocol_type = "HYSTERIA", check_connection = False)
# Initialize security and netowrk array
tls_array = list()
non_tls_array = list()
tcp_array = list()
ws_array = list()
http_array = list()
grpc_array = list()
for array in [shadow_tls_array, trojan_tls_array, vmess_tls_array, vless_tls_array, reality_tls_array]:
tls_array.extend(array)
for array in [shadow_non_tls_array, trojan_non_tls_array, vmess_non_tls_array, vless_non_tls_array, reality_non_tls_array]:
non_tls_array.extend(array)
for array in [shadow_tcp_array, trojan_tcp_array, vmess_tcp_array, vless_tcp_array, reality_tcp_array]:
tcp_array.extend(array)
for array in [shadow_ws_array, trojan_ws_array, vmess_ws_array, vless_ws_array, reality_ws_array]:
ws_array.extend(array)
for array in [shadow_http_array, trojan_http_array, vmess_http_array, vless_http_array, reality_http_array]:
http_array.extend(array)
for array in [shadow_grpc_array, trojan_grpc_array, vmess_grpc_array, vless_grpc_array, reality_grpc_array]:
grpc_array.extend(array)
return shadow_array, trojan_array, vmess_array, vless_array, reality_array, tuic_array, hysteria_array, tls_array, non_tls_array, tcp_array, ws_array, http_array, grpc_array
# Remove Duplicate Configurations
configs_list_array = [array_shadowsocks, array_trojan, array_vmess, array_vless, array_reality, array_tuic, array_hysteria, matches_shadowsocks, matches_trojan, matches_vmess, matches_vless, matches_reality, matches_tuic, matches_hysteria, raw_matches_shadowsocks, raw_matches_trojan, raw_matches_vmess, raw_matches_vless, raw_matches_reality, raw_matches_tuic, raw_matches_hysteria, channel_matches_shadowsocks, channel_matches_trojan, channel_matches_vmess, channel_matches_vless, channel_matches_reality, channel_matches_tuic, channel_matches_hysteria]
array_removed_duplicate_list_configurations = list()
for array in configs_list_array:
print(f"Before Removing Duplicates : {len(array)}", end = '\t')
array = remove_duplicate_modified(array)
print(f"After Removing Duplicates : {len(array)}")
array_removed_duplicate_list_configurations.append(array)
# Dedicate removed array of the list of elements
array_shadowsocks, array_trojan, array_vmess, array_vless, array_reality, array_tuic, array_hysteria, matches_shadowsocks, matches_trojan, matches_vmess, matches_vless, matches_reality, matches_tuic, matches_hysteria, raw_matches_shadowsocks, raw_matches_trojan, raw_matches_vmess, raw_matches_vless, raw_matches_reality, raw_matches_tuic, raw_matches_hysteria, channel_matches_shadowsocks, channel_matches_trojan, channel_matches_vmess, channel_matches_vless, channel_matches_reality, channel_matches_tuic, channel_matches_hysteria = array_removed_duplicate_list_configurations
# Remove duplicate configurations of telegram channels and subscription links contents
array_shadowsocks, array_trojan, array_vmess, array_vless, array_reality, array_tuic, array_hysteria, array_juicity = remove_duplicate(array_shadowsocks, array_trojan, array_vmess, array_vless, array_reality, array_tuic, array_hysteria, array_juicity)
matches_shadowsocks, matches_trojan, matches_vmess, matches_vless, matches_reality, matches_tuic, matches_hysteria, matches_juicity = remove_duplicate(matches_shadowsocks, matches_trojan, matches_vmess, matches_vless, matches_reality, matches_tuic, matches_hysteria, matches_juicity)
raw_matches_shadowsocks, raw_matches_trojan, raw_matches_vmess, raw_matches_vless, raw_matches_reality, raw_matches_tuic, raw_matches_hysteria, raw_matches_juicity = remove_duplicate(raw_matches_shadowsocks, raw_matches_trojan, raw_matches_vmess, raw_matches_vless, raw_matches_reality, raw_matches_tuic, raw_matches_hysteria, raw_matches_juicity)
channel_matches_shadowsocks, channel_matches_trojan, channel_matches_vmess, channel_matches_vless, channel_matches_reality, channel_matches_tuic, channel_matches_hysteria, channel_matches_juicity = remove_duplicate(channel_matches_shadowsocks, channel_matches_trojan, channel_matches_vmess, channel_matches_vless, channel_matches_reality, channel_matches_tuic, channel_matches_hysteria, channel_matches_juicity)
# Checkout connectivity and modify title and protocol type address and resolve IP address
array_shadowsocks, array_trojan, array_vmess, array_vless, array_reality, array_tuic, array_hysteria, array_tls, array_non_tls, array_tcp, array_ws, array_http, array_grpc = modify_config(array_shadowsocks, array_trojan, array_vmess, array_vless, array_reality, array_tuic, array_hysteria)
matches_shadowsocks, matches_trojan, matches_vmess, matches_vless, matches_reality, matches_tuic, matches_hysteria, matches_tls, matches_non_tls, matches_tcp, matches_ws, matches_http, matches_grpc = modify_config(matches_shadowsocks, matches_trojan, matches_vmess, matches_vless, matches_reality, matches_tuic, matches_hysteria)
raw_matches_shadowsocks, raw_matches_trojan, raw_matches_vmess, raw_matches_vless, raw_matches_reality, raw_matches_tuic, raw_matches_hysteria, raw_matches_tls, raw_matches_non_tls, raw_matches_tcp, raw_matches_ws, raw_matches_http, raw_matches_grpc = modify_config(raw_matches_shadowsocks, raw_matches_trojan, raw_matches_vmess, raw_matches_vless, raw_matches_reality, raw_matches_tuic, raw_matches_hysteria, check_port_connection = False)
channel_matches_shadowsocks, channel_matches_trojan, channel_matches_vmess, channel_matches_vless, channel_matches_reality, channel_matches_tuic, channel_matches_hysteria, channel_matches_tls, channel_matches_non_tls, channel_matches_tcp, channel_matches_ws, channel_matches_http, channel_matches_grpc = modify_config(channel_matches_shadowsocks, channel_matches_trojan, channel_matches_vmess, channel_matches_vless, channel_matches_reality, channel_matches_tuic, channel_matches_hysteria, check_port_connection = True)
# Extend channel subscription links contents to telegram channel contents
array_shadowsocks_channels = array_shadowsocks
array_trojan_channels = array_trojan
array_vmess_channels = array_vmess
array_vless_channels = array_vless
array_reality_channels = array_reality
array_tuic_channels = array_tuic
array_hysteria_channels = array_hysteria
array_juicity_channels = array_juicity
array_shadowsocks_channels.extend(channel_matches_shadowsocks)
array_trojan_channels.extend(channel_matches_trojan)
array_vmess_channels.extend(channel_matches_vmess)
array_vless_channels.extend(channel_matches_vless)
array_reality_channels.extend(channel_matches_reality)
array_tuic_channels.extend(channel_matches_tuic)
array_hysteria_channels.extend(channel_matches_hysteria)
array_juicity_channels.extend(channel_matches_juicity)
# Remove duplicate configurations after modifying telegram channels and subscription links contents
array_shadowsocks_channels, array_trojan_channels, array_vmess_channels, array_vless_channels, array_reality_channels, array_tuic_channels, array_hysteria_channels, array_juicity_channels = remove_duplicate(array_shadowsocks_channels, array_trojan_channels, array_vmess_channels, array_vless_channels, array_reality_channels, array_tuic_channels, array_hysteria_channels, array_juicity_channels, vmess_decode_dedup = False)
channel_matches_shadowsocks, channel_matches_trojan, channel_matches_vmess, channel_matches_vless, channel_matches_reality, channel_matches_tuic, channel_matches_hysteria, channel_matches_juicity = remove_duplicate(channel_matches_shadowsocks, channel_matches_trojan, channel_matches_vmess, channel_matches_vless, channel_matches_reality, channel_matches_tuic, channel_matches_hysteria, channel_matches_juicity, vmess_decode_dedup = False)
# Extend channel subscription links contents to telegram channel contents based on networks and security
array_tls_channels = array_tls
array_non_tls_channels = array_non_tls
array_tcp_channels = array_tcp
array_ws_channels = array_ws
array_http_channels = array_http
array_grpc_channels = array_grpc
array_tls_channels.extend(channel_matches_tls)
array_non_tls_channels.extend(channel_matches_non_tls)
array_tcp_channels.extend(channel_matches_tcp)
array_ws_channels.extend(channel_matches_ws)
array_http_channels.extend(channel_matches_http)
array_grpc_channels.extend(channel_matches_grpc)
array_tls_channels = list(set(array_tls_channels))
array_non_tls_channels = list(set(array_non_tls_channels))
array_tcp_channels = list(set(array_tcp_channels))
array_ws_channels = list(set(array_ws_channels))
array_http_channels = list(set(array_http_channels))
array_grpc_channels = list(set(array_grpc_channels))
# Extend subscription links contents to telegram channel contents
array_shadowsocks.extend(matches_shadowsocks)
array_trojan.extend(matches_trojan)
array_vmess.extend(matches_vmess)
array_vless.extend(matches_vless)
array_reality.extend(matches_reality)
array_tuic.extend(matches_tuic)
array_hysteria.extend(matches_hysteria)
array_juicity.extend(matches_juicity)
# Remove duplicate configurations after modifying telegram channels and subscription links contents
array_shadowsocks, array_trojan, array_vmess, array_vless, array_reality, array_tuic, array_hysteria, array_juicity = remove_duplicate(array_shadowsocks, array_trojan, array_vmess, array_vless, array_reality, array_tuic, array_hysteria, array_juicity, vmess_decode_dedup = False)
matches_shadowsocks, matches_trojan, matches_vmess, matches_vless, matches_reality, matches_tuic, matches_hysteria, matches_juicity = remove_duplicate(matches_shadowsocks, matches_trojan, matches_vmess, matches_vless, matches_reality, matches_tuic, matches_hysteria, matches_juicity, vmess_decode_dedup = False)
raw_matches_shadowsocks, raw_matches_trojan, raw_matches_vmess, raw_matches_vless, raw_matches_reality, raw_matches_tuic, raw_matches_hysteria, raw_matches_juicity = remove_duplicate(raw_matches_shadowsocks, raw_matches_trojan, raw_matches_vmess, raw_matches_vless, raw_matches_reality, raw_matches_tuic, raw_matches_hysteria, raw_matches_juicity, vmess_decode_dedup = False)
# Extend subscription links contents to telegram channel contents
array_tls.extend(matches_tls)
array_non_tls.extend(matches_non_tls)
array_tcp.extend(matches_tcp)
array_ws.extend(matches_ws)
array_http.extend(matches_http)
array_grpc.extend(matches_grpc)