forked from SilentDemonSD/WZML-X
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_settings.py
1286 lines (1134 loc) · 55.1 KB
/
bot_settings.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
#!/usr/bin/env python3
from random import choice
from pyrogram.handlers import MessageHandler, CallbackQueryHandler
from pyrogram.filters import command, regex, create
from pyrogram.enums import ChatType
from functools import partial
from collections import OrderedDict
from asyncio import create_subprocess_exec, create_subprocess_shell, sleep, gather
from aiofiles.os import remove, rename, path as aiopath
from aiofiles import open as aiopen
from os import environ, getcwd
from dotenv import load_dotenv
from time import time
from io import BytesIO
from aioshutil import rmtree as aiormtree
from bot import config_dict, user_data, DATABASE_URL, MAX_SPLIT_SIZE, list_drives_dict, categories_dict, aria2, GLOBAL_EXTENSION_FILTER, status_reply_dict_lock, Interval, aria2_options, aria2c_global, IS_PREMIUM_USER, download_dict, qbit_options, get_client, LOGGER, bot, extra_buttons, shorteners_list
from bot.helper.telegram_helper.message_utils import sendMessage, sendFile, editMessage, deleteMessage, update_all_messages
from bot.helper.telegram_helper.filters import CustomFilters
from bot.helper.telegram_helper.bot_commands import BotCommands
from bot.helper.telegram_helper.button_build import ButtonMaker
from bot.helper.ext_utils.bot_utils import setInterval, sync_to_async, new_thread
from bot.helper.ext_utils.db_handler import DbManger
from bot.helper.ext_utils.task_manager import start_from_queued
from bot.helper.ext_utils.help_messages import default_desp
from bot.helper.mirror_utils.rclone_utils.serve import rclone_serve_booter
from bot.modules.torrent_search import initiate_search_tools
from bot.modules.rss import addJob
from bot.helper.themes import AVL_THEMES
START = 0
STATE = 'view'
handler_dict = {}
default_values = {'AUTO_DELETE_MESSAGE_DURATION': 30,
'DEFAULT_UPLOAD': 'gd',
'DOWNLOAD_DIR': '/usr/src/app/downloads/',
'LEECH_SPLIT_SIZE': MAX_SPLIT_SIZE,
'RSS_DELAY': 600,
'STATUS_UPDATE_INTERVAL': 10,
'SEARCH_LIMIT': 0,
'UPSTREAM_BRANCH': 'master',
'BOT_THEME': 'minimal',
'BOT_LANG': 'en',
'IMG_PAGE': 1,
'AUTHOR_NAME': 'WZML-X',
'AUTHOR_URL': 'https://t.me/WZML_X',
'TITLE_NAME': 'WZ Mirror/Leech X',
'GD_INFO': 'Uploaded by WZML-X',
}
bool_vars = ['AS_DOCUMENT', 'BOT_PM', 'STOP_DUPLICATE', 'SET_COMMANDS', 'SAVE_MSG', 'SHOW_MEDIAINFO', 'SOURCE_LINK', 'SAFE_MODE', 'SHOW_EXTRA_CMDS',
'IS_TEAM_DRIVE', 'USE_SERVICE_ACCOUNTS', 'WEB_PINCODE', 'EQUAL_SPLITS', 'DISABLE_DRIVE_LINK', 'DELETE_LINKS', 'CLEAN_LOG_MSG', 'USER_TD_MODE',
'INCOMPLETE_TASK_NOTIFIER', 'UPGRADE_PACKAGES', 'SCREENSHOTS_MODE']
async def load_config():
BOT_TOKEN = environ.get('BOT_TOKEN', '')
if len(BOT_TOKEN) == 0:
BOT_TOKEN = config_dict['BOT_TOKEN']
TELEGRAM_API = environ.get('TELEGRAM_API', '')
if len(TELEGRAM_API) == 0:
TELEGRAM_API = config_dict['TELEGRAM_API']
else:
TELEGRAM_API = int(TELEGRAM_API)
TELEGRAM_HASH = environ.get('TELEGRAM_HASH', '')
if len(TELEGRAM_HASH) == 0:
TELEGRAM_HASH = config_dict['TELEGRAM_HASH']
BOT_MAX_TASKS = environ.get('BOT_MAX_TASKS', '')
BOT_MAX_TASKS = int(BOT_MAX_TASKS) if BOT_MAX_TASKS.isdigit() else ''
OWNER_ID = environ.get('OWNER_ID', '')
OWNER_ID = config_dict['OWNER_ID'] if len(OWNER_ID) == 0 else int(OWNER_ID)
DATABASE_URL = environ.get('DATABASE_URL', '')
if len(DATABASE_URL) == 0:
DATABASE_URL = ''
DOWNLOAD_DIR = environ.get('DOWNLOAD_DIR', '')
if len(DOWNLOAD_DIR) == 0:
DOWNLOAD_DIR = '/usr/src/app/downloads/'
elif not DOWNLOAD_DIR.endswith("/"):
DOWNLOAD_DIR = f'{DOWNLOAD_DIR}/'
GDRIVE_ID = environ.get('GDRIVE_ID', '')
if len(GDRIVE_ID) == 0:
GDRIVE_ID = ''
RCLONE_PATH = environ.get('RCLONE_PATH', '')
if len(RCLONE_PATH) == 0:
RCLONE_PATH = ''
DEFAULT_UPLOAD = environ.get('DEFAULT_UPLOAD', '')
if DEFAULT_UPLOAD != 'rc' and DEFAULT_UPLOAD != 'ddl':
DEFAULT_UPLOAD = 'gd'
RCLONE_FLAGS = environ.get('RCLONE_FLAGS', '')
if len(RCLONE_FLAGS) == 0:
RCLONE_FLAGS = ''
AUTHORIZED_CHATS = environ.get('AUTHORIZED_CHATS', '')
if len(AUTHORIZED_CHATS) != 0:
aid = AUTHORIZED_CHATS.split()
for id_ in aid:
chat_id, *topic_ids = id_.split(':')
chat_id = int(chat_id)
user_data.setdefault(chat_id, {'is_auth': True})
if topic_ids:
user_data[chat_id].setdefault('topic_ids', []).extend(map(int, topic_ids))
SUDO_USERS = environ.get('SUDO_USERS', '')
if len(SUDO_USERS) != 0:
aid = SUDO_USERS.split()
for id_ in aid:
user_data[int(id_.strip())] = {'is_sudo': True}
BLACKLIST_USERS = environ.get('BLACKLIST_USERS', '')
if len(BLACKLIST_USERS) != 0:
aid = BLACKLIST_USERS.split()
for id_ in aid:
user_data[int(id_.strip())] = {'is_blacklist': True}
EXTENSION_FILTER = environ.get('EXTENSION_FILTER', '')
if len(EXTENSION_FILTER) > 0:
fx = EXTENSION_FILTER.split()
GLOBAL_EXTENSION_FILTER.clear()
GLOBAL_EXTENSION_FILTER.extend(['aria2', '!qB'])
for x in fx:
x = x.lstrip('.')
GLOBAL_EXTENSION_FILTER.append(x.strip().lower())
MEGA_EMAIL = environ.get('MEGA_EMAIL', '')
MEGA_PASSWORD = environ.get('MEGA_PASSWORD', '')
if len(MEGA_EMAIL) == 0 or len(MEGA_PASSWORD) == 0:
MEGA_EMAIL = ''
MEGA_PASSWORD = ''
GDTOT_CRYPT = environ.get('GDTOT_CRYPT', '')
if len(GDTOT_CRYPT) == 0:
GDTOT_CRYPT = ''
JIODRIVE_TOKEN = environ.get('JIODRIVE_TOKEN', '')
if len(JIODRIVE_TOKEN) == 0:
JIODRIVE_TOKEN = ''
REAL_DEBRID_API = environ.get('REAL_DEBRID_API', '')
if len(REAL_DEBRID_API) == 0:
REAL_DEBRID_API = ''
DEBRID_LINK_API = environ.get('DEBRID_LINK_API', '')
if len(DEBRID_LINK_API) == 0:
DEBRID_LINK_API = ''
INDEX_URL = environ.get('INDEX_URL', '').rstrip("/")
if len(INDEX_URL) == 0:
INDEX_URL = ''
SEARCH_API_LINK = environ.get('SEARCH_API_LINK', '').rstrip("/")
if len(SEARCH_API_LINK) == 0:
SEARCH_API_LINK = ''
CAP_FONT = environ.get('CAP_FONT', '').lower()
if CAP_FONT.strip() not in ['', 'b', 'i', 'u', 's', 'spoiler', 'code']:
CAP_FONT = 'code'
LEECH_FILENAME_PREFIX = environ.get('LEECH_FILENAME_PREFIX', '')
if len(LEECH_FILENAME_PREFIX) == 0:
LEECH_FILENAME_PREFIX = ''
LEECH_FILENAME_SUFFIX = environ.get('LEECH_FILENAME_SUFFIX', '')
if len(LEECH_FILENAME_SUFFIX) == 0:
LEECH_FILENAME_SUFFIX = ''
LEECH_FILENAME_CAPTION = environ.get('LEECH_FILENAME_CAPTION', '')
if len(LEECH_FILENAME_CAPTION) == 0:
LEECH_FILENAME_CAPTION = ''
LEECH_FILENAME_REMNAME = environ.get('LEECH_FILENAME_REMNAME', '')
if len(LEECH_FILENAME_REMNAME) == 0:
LEECH_FILENAME_REMNAME = ''
MIRROR_FILENAME_PREFIX = environ.get('MIRROR_FILENAME_PREFIX', '')
if len(MIRROR_FILENAME_PREFIX) == 0:
MIRROR_FILENAME_PREFIX = ''
MIRROR_FILENAME_SUFFIX = environ.get('MIRROR_FILENAME_SUFFIX', '')
if len(MIRROR_FILENAME_SUFFIX) == 0:
MIRROR_FILENAME_SUFFIX = ''
MIRROR_FILENAME_REMNAME = environ.get('MIRROR_FILENAME_REMNAME', '')
if len(MIRROR_FILENAME_REMNAME) == 0:
MIRROR_FILENAME_REMNAME = ''
SEARCH_PLUGINS = environ.get('SEARCH_PLUGINS', '')
if len(SEARCH_PLUGINS) == 0:
SEARCH_PLUGINS = ''
MAX_SPLIT_SIZE = 4194304000 if IS_PREMIUM_USER else 2097152000
LEECH_SPLIT_SIZE = environ.get('LEECH_SPLIT_SIZE', '')
if len(LEECH_SPLIT_SIZE) == 0 or int(LEECH_SPLIT_SIZE) > MAX_SPLIT_SIZE:
LEECH_SPLIT_SIZE = MAX_SPLIT_SIZE
else:
LEECH_SPLIT_SIZE = int(LEECH_SPLIT_SIZE)
STATUS_UPDATE_INTERVAL = environ.get('STATUS_UPDATE_INTERVAL', '')
if len(STATUS_UPDATE_INTERVAL) == 0:
STATUS_UPDATE_INTERVAL = 10
else:
STATUS_UPDATE_INTERVAL = int(STATUS_UPDATE_INTERVAL)
if len(download_dict) != 0:
async with status_reply_dict_lock:
if Interval:
Interval[0].cancel()
Interval.clear()
Interval.append(setInterval(STATUS_UPDATE_INTERVAL, update_all_messages))
AUTO_DELETE_MESSAGE_DURATION = environ.get(
'AUTO_DELETE_MESSAGE_DURATION', '')
if len(AUTO_DELETE_MESSAGE_DURATION) == 0:
AUTO_DELETE_MESSAGE_DURATION = 30
else:
AUTO_DELETE_MESSAGE_DURATION = int(AUTO_DELETE_MESSAGE_DURATION)
YT_DLP_OPTIONS = environ.get('YT_DLP_OPTIONS', '')
if len(YT_DLP_OPTIONS) == 0:
YT_DLP_OPTIONS = ''
SEARCH_LIMIT = environ.get('SEARCH_LIMIT', '')
SEARCH_LIMIT = 0 if len(SEARCH_LIMIT) == 0 else int(SEARCH_LIMIT)
STATUS_LIMIT = environ.get('STATUS_LIMIT', '')
STATUS_LIMIT = 10 if len(STATUS_LIMIT) == 0 else int(STATUS_LIMIT)
RSS_CHAT = environ.get('RSS_CHAT', '')
RSS_CHAT = '' if len(RSS_CHAT) == 0 else int(RSS_CHAT)
RSS_DELAY = environ.get('RSS_DELAY', '')
RSS_DELAY = 900 if len(RSS_DELAY) == 0 else int(RSS_DELAY)
CMD_SUFFIX = environ.get('CMD_SUFFIX', '')
USER_SESSION_STRING = environ.get('USER_SESSION_STRING', '')
TORRENT_TIMEOUT = environ.get('TORRENT_TIMEOUT', '')
downloads = aria2.get_downloads()
if len(TORRENT_TIMEOUT) == 0:
for download in downloads:
if not download.is_complete:
try:
await sync_to_async(aria2.client.change_option, download.gid, {'bt-stop-timeout': '0'})
except Exception as e:
LOGGER.error(e)
aria2_options['bt-stop-timeout'] = '0'
if DATABASE_URL:
await DbManger().update_aria2('bt-stop-timeout', '0')
TORRENT_TIMEOUT = ''
else:
for download in downloads:
if not download.is_complete:
try:
await sync_to_async(aria2.client.change_option, download.gid, {'bt-stop-timeout': TORRENT_TIMEOUT})
except Exception as e:
LOGGER.error(e)
aria2_options['bt-stop-timeout'] = TORRENT_TIMEOUT
if DATABASE_URL:
await DbManger().update_aria2('bt-stop-timeout', TORRENT_TIMEOUT)
TORRENT_TIMEOUT = int(TORRENT_TIMEOUT)
QUEUE_ALL = environ.get('QUEUE_ALL', '')
QUEUE_ALL = '' if len(QUEUE_ALL) == 0 else int(QUEUE_ALL)
QUEUE_DOWNLOAD = environ.get('QUEUE_DOWNLOAD', '')
QUEUE_DOWNLOAD = '' if len(QUEUE_DOWNLOAD) == 0 else int(QUEUE_DOWNLOAD)
QUEUE_UPLOAD = environ.get('QUEUE_UPLOAD', '')
QUEUE_UPLOAD = '' if len(QUEUE_UPLOAD) == 0 else int(QUEUE_UPLOAD)
INCOMPLETE_TASK_NOTIFIER = environ.get('INCOMPLETE_TASK_NOTIFIER', '')
INCOMPLETE_TASK_NOTIFIER = INCOMPLETE_TASK_NOTIFIER.lower() == 'true'
if not INCOMPLETE_TASK_NOTIFIER and DATABASE_URL:
await DbManger().trunc_table('tasks')
STOP_DUPLICATE = environ.get('STOP_DUPLICATE', '')
STOP_DUPLICATE = STOP_DUPLICATE.lower() == 'true'
IS_TEAM_DRIVE = environ.get('IS_TEAM_DRIVE', '')
IS_TEAM_DRIVE = IS_TEAM_DRIVE.lower() == 'true'
USE_SERVICE_ACCOUNTS = environ.get('USE_SERVICE_ACCOUNTS', '')
USE_SERVICE_ACCOUNTS = USE_SERVICE_ACCOUNTS.lower() == 'true'
WEB_PINCODE = environ.get('WEB_PINCODE', '')
WEB_PINCODE = WEB_PINCODE.lower() == 'true'
AS_DOCUMENT = environ.get('AS_DOCUMENT', '')
AS_DOCUMENT = AS_DOCUMENT.lower() == 'true'
USER_TD_MODE = environ.get('USER_TD_MODE', '')
USER_TD_MODE = USER_TD_MODE.lower() == 'true'
USER_TD_SA = environ.get('USER_TD_SA', '')
USER_TD_SA = USER_TD_SA.lower() if len(USER_TD_SA) != 0 else ''
SHOW_MEDIAINFO = environ.get('SHOW_MEDIAINFO', '')
SHOW_MEDIAINFO = SHOW_MEDIAINFO.lower() == 'true'
SHOW_MEDIAINFO = environ.get('SHOW_MEDIAINFO', '')
SHOW_MEDIAINFO = SHOW_MEDIAINFO.lower() == 'true'
SOURCE_LINK = environ.get('SOURCE_LINK', '')
SOURCE_LINK = SOURCE_LINK.lower() == 'true'
DELETE_LINKS = environ.get('DELETE_LINKS', '')
DELETE_LINKS = DELETE_LINKS.lower() == 'true'
EQUAL_SPLITS = environ.get('EQUAL_SPLITS', '')
EQUAL_SPLITS = EQUAL_SPLITS.lower() == 'true'
MEDIA_GROUP = environ.get('MEDIA_GROUP', '')
MEDIA_GROUP = MEDIA_GROUP.lower() == 'true'
BASE_URL_PORT = environ.get('BASE_URL_PORT', '')
BASE_URL_PORT = 80 if len(BASE_URL_PORT) == 0 else int(BASE_URL_PORT)
RCLONE_SERVE_URL = environ.get('RCLONE_SERVE_URL', '')
if len(RCLONE_SERVE_URL) == 0:
RCLONE_SERVE_URL = ''
RCLONE_SERVE_PORT = environ.get('RCLONE_SERVE_PORT', '')
RCLONE_SERVE_PORT = 8080 if len(
RCLONE_SERVE_PORT) == 0 else int(RCLONE_SERVE_PORT)
RCLONE_SERVE_USER = environ.get('RCLONE_SERVE_USER', '')
if len(RCLONE_SERVE_USER) == 0:
RCLONE_SERVE_USER = ''
RCLONE_SERVE_PASS = environ.get('RCLONE_SERVE_PASS', '')
if len(RCLONE_SERVE_PASS) == 0:
RCLONE_SERVE_PASS = ''
await (await create_subprocess_exec("pkill", "-9", "-f", "gunicorn")).wait()
BASE_URL = environ.get('BASE_URL', '').rstrip("/")
if len(BASE_URL) == 0:
BASE_URL = ''
else:
await create_subprocess_shell(f"gunicorn web.wserver:app --bind 0.0.0.0:{BASE_URL_PORT} --worker-class gevent")
UPSTREAM_REPO = environ.get('UPSTREAM_REPO', '')
if len(UPSTREAM_REPO) == 0:
UPSTREAM_REPO = ''
UPGRADE_PACKAGES = environ.get('UPGRADE_PACKAGES', '')
UPGRADE_PACKAGES = UPGRADE_PACKAGES.lower() == 'true'
UPSTREAM_BRANCH = environ.get('UPSTREAM_BRANCH', '')
if len(UPSTREAM_BRANCH) == 0:
UPSTREAM_BRANCH = 'master'
STORAGE_THRESHOLD = environ.get('STORAGE_THRESHOLD', '')
STORAGE_THRESHOLD = '' if len(
STORAGE_THRESHOLD) == 0 else float(STORAGE_THRESHOLD)
TORRENT_LIMIT = environ.get('TORRENT_LIMIT', '')
TORRENT_LIMIT = '' if len(TORRENT_LIMIT) == 0 else float(TORRENT_LIMIT)
DIRECT_LIMIT = environ.get('DIRECT_LIMIT', '')
DIRECT_LIMIT = '' if len(DIRECT_LIMIT) == 0 else float(DIRECT_LIMIT)
YTDLP_LIMIT = environ.get('YTDLP_LIMIT', '')
YTDLP_LIMIT = '' if len(YTDLP_LIMIT) == 0 else float(YTDLP_LIMIT)
GDRIVE_LIMIT = environ.get('GDRIVE_LIMIT', '')
GDRIVE_LIMIT = '' if len(GDRIVE_LIMIT) == 0 else float(GDRIVE_LIMIT)
CLONE_LIMIT = environ.get('CLONE_LIMIT', '')
CLONE_LIMIT = '' if len(CLONE_LIMIT) == 0 else float(CLONE_LIMIT)
MEGA_LIMIT = environ.get('MEGA_LIMIT', '')
MEGA_LIMIT = '' if len(MEGA_LIMIT) == 0 else float(MEGA_LIMIT)
LEECH_LIMIT = environ.get('LEECH_LIMIT', '')
LEECH_LIMIT = '' if len(LEECH_LIMIT) == 0 else float(LEECH_LIMIT)
FSUB_IDS = environ.get('FSUB_IDS', '')
if len(FSUB_IDS) == 0:
FSUB_IDS = ''
LINKS_LOG_ID = environ.get('LINKS_LOG_ID', '')
LINKS_LOG_ID = '' if len(LINKS_LOG_ID) == 0 else int(LINKS_LOG_ID)
MIRROR_LOG_ID = environ.get('MIRROR_LOG_ID', '')
if len(MIRROR_LOG_ID) == 0:
MIRROR_LOG_ID = ''
LEECH_LOG_ID = environ.get('LEECH_LOG_ID', '')
if len(LEECH_LOG_ID) == 0:
LEECH_LOG_ID = ''
EXCEP_CHATS = environ.get('EXCEP_CHATS', '')
if len(EXCEP_CHATS) == 0:
EXCEP_CHATS = ''
USER_MAX_TASKS = environ.get('USER_MAX_TASKS', '')
USER_MAX_TASKS = int(USER_MAX_TASKS) if USER_MAX_TASKS.isdigit() else ''
USER_TIME_INTERVAL = environ.get('USER_TIME_INTERVAL', '')
USER_TIME_INTERVAL = int(USER_TIME_INTERVAL) if USER_TIME_INTERVAL.isdigit() else 0
PLAYLIST_LIMIT = environ.get('PLAYLIST_LIMIT', '')
PLAYLIST_LIMIT = '' if len(PLAYLIST_LIMIT) == 0 else int(PLAYLIST_LIMIT)
BOT_PM = environ.get('BOT_PM', '')
BOT_PM = BOT_PM.lower() == 'true'
DAILY_TASK_LIMIT = environ.get('DAILY_TASK_LIMIT', '')
DAILY_TASK_LIMIT = '' if len(DAILY_TASK_LIMIT) == 0 else int(DAILY_TASK_LIMIT)
DAILY_MIRROR_LIMIT = environ.get('DAILY_MIRROR_LIMIT', '')
DAILY_MIRROR_LIMIT = '' if len(DAILY_MIRROR_LIMIT) == 0 else float(DAILY_MIRROR_LIMIT)
DAILY_LEECH_LIMIT = environ.get('DAILY_LEECH_LIMIT', '')
DAILY_LEECH_LIMIT = '' if len(DAILY_LEECH_LIMIT) == 0 else float(DAILY_LEECH_LIMIT)
DISABLE_DRIVE_LINK = environ.get('DISABLE_DRIVE_LINK', '')
DISABLE_DRIVE_LINK = DISABLE_DRIVE_LINK.lower() == 'true'
BOT_THEME = environ.get('BOT_THEME', '')
if len(BOT_THEME) == 0:
BOT_THEME = 'minimal'
IMG_SEARCH = environ.get('IMG_SEARCH', '')
IMG_SEARCH = (IMG_SEARCH.replace("'", '').replace('"', '').replace('[', '').replace(']', '').replace(",", "")).split()
IMG_PAGE = environ.get('IMG_PAGE', '')
IMG_PAGE = int(IMG_PAGE) if IMG_PAGE.isdigit() else ''
IMAGES = environ.get('IMAGES', '')
IMAGES = (IMAGES.replace("'", '').replace('"', '').replace('[', '').replace(']', '').replace(",", "")).split()
AUTHOR_NAME = environ.get('AUTHOR_NAME', '')
if len(AUTHOR_NAME) == 0:
AUTHOR_NAME = 'WZML-X'
AUTHOR_URL = environ.get('AUTHOR_URL', '')
if len(AUTHOR_URL) == 0:
AUTHOR_URL = 'https://t.me/WZML_X'
TITLE_NAME = environ.get('TITLE_NAME', '')
if len(TITLE_NAME) == 0:
TITLE_NAME = 'WeebZone-X'
COVER_IMAGE = environ.get('COVER_IMAGE', '')
if len(COVER_IMAGE) == 0:
COVER_IMAGE = 'https://graph.org/file/60f9f8bcb97d27f76f5c0.jpg'
GD_INFO = environ.get('GD_INFO', '')
if len(GD_INFO) == 0:
GD_INFO = 'Uploaded by WZML-X'
SAVE_MSG = environ.get('SAVE_MSG', '')
SAVE_MSG = SAVE_MSG.lower() == 'true'
SET_COMMANDS = environ.get('SET_COMMANDS', '')
SET_COMMANDS = SET_COMMANDS.lower() == 'true'
SAFE_MODE = environ.get('SAFE_MODE', '')
SAFE_MODE = SAFE_MODE.lower() == 'true'
SCREENSHOTS_MODE = environ.get('SCREENSHOTS_MODE', '')
SCREENSHOTS_MODE = SCREENSHOTS_MODE.lower() == 'true'
CLEAN_LOG_MSG = environ.get('CLEAN_LOG_MSG', '')
CLEAN_LOG_MSG = CLEAN_LOG_MSG.lower() == 'true'
SHOW_EXTRA_CMDS = environ.get('SHOW_EXTRA_CMDS', '')
SHOW_EXTRA_CMDS = SHOW_EXTRA_CMDS.lower() == 'true'
TOKEN_TIMEOUT = environ.get('TOKEN_TIMEOUT', '')
TOKEN_TIMEOUT = int(TOKEN_TIMEOUT) if TOKEN_TIMEOUT.isdigit() else ''
LOGIN_PASS = environ.get('LOGIN_PASS', '')
if len(LOGIN_PASS) == 0:
LOGIN_PASS = None
FILELION_API = environ.get('FILELION_API', '')
if len(FILELION_API) == 0:
FILELION_API = ''
DEF_IMDB_TEMP = environ.get('IMDB_TEMPLATE', '')
if len(DEF_IMDB_TEMP) == 0:
DEF_IMDB_TEMP = '''<b>Title: </b> {title} [{year}]
<b>Also Known As:</b> {aka}
<b>Rating ⭐️:</b> <i>{rating}</i>
<b>Release Info: </b> <a href="{url_releaseinfo}">{release_date}</a>
<b>Genre: </b>{genres}
<b>IMDb URL:</b> {url}
<b>Language: </b>{languages}
<b>Country of Origin : </b> {countries}
<b>Story Line: </b><code>{plot}</code>
<a href="{url_cast}">Read More ...</a>'''
DEF_ANI_TEMP = environ.get('ANIME_TEMPLATE', '')
if len(DEF_ANI_TEMP) == 0:
DEF_ANI_TEMP = '''<b>{ro_title}</b>({na_title})
<b>Format</b>: <code>{format}</code>
<b>Status</b>: <code>{status}</code>
<b>Start Date</b>: <code>{startdate}</code>
<b>End Date</b>: <code>{enddate}</code>
<b>Season</b>: <code>{season}</code>
<b>Country</b>: {country}
<b>Episodes</b>: <code>{episodes}</code>
<b>Duration</b>: <code>{duration}</code>
<b>Average Score</b>: <code>{avgscore}</code>
<b>Genres</b>: {genres}
<b>Hashtag</b>: {hashtag}
<b>Studios</b>: {studios}
<b>Description</b>: <i>{description}</i>'''
MDL_TEMPLATE = environ.get('MDL_TEMPLATE', '')
if len(MDL_TEMPLATE) == 0:
MDL_TEMPLATE = '''<b>Title:</b> {title}
<b>Also Known As:</b> {aka}
<b>Rating ⭐️:</b> <i>{rating}</i>
<b>Release Info:</b> {aired_date}
<b>Genre:</b> {genres}
<b>MyDramaList URL:</b> {url}
<b>Language:</b> #Korean
<b>Country of Origin:</b> {country}
<b>Story Line:</b> {synopsis}
<a href='{url}'>Read More ...</a>'''
TIMEZONE = environ.get('TIMEZONE', '')
if len(TIMEZONE) == 0:
TIMEZONE = 'Asia/Kolkata'
list_drives_dict.clear()
if GDRIVE_ID:
list_drives_dict['Main'] = {"drive_id": GDRIVE_ID, "index_link": INDEX_URL}
categories_dict['Root'] = {"drive_id": GDRIVE_ID, "index_link": INDEX_URL}
if await aiopath.exists('list_drives.txt'):
async with aiopen('list_drives.txt', 'r+') as f:
lines = await f.readlines()
for line in lines:
sep = 2 if line.strip().split()[-1].startswith('http') else 1
temp = line.strip().rsplit(maxsplit=sep)
name = "Main Custom" if temp[0].casefold() == "Main" else temp[0]
list_drives_dict[name] = {'drive_id': temp[1], 'index_link': (temp[2] if sep == 2 else '')}
categories_dict.clear()
if await aiopath.exists('categories.txt'):
async with aiopen('categories.txt', 'r+') as f:
lines = await f.readlines()
for line in lines:
sep = 2 if line.strip().split()[-1].startswith('http') else 1
temp = line.strip().rsplit(maxsplit=sep)
name = "Root Custom" if temp[0].casefold() == "Root" else temp[0]
categories_dict[name] = {'drive_id': temp[1], 'index_link': (temp[2] if sep == 2 else '')}
extra_buttons.clear()
if await aiopath.exists('buttons.txt'):
async with aiopen('buttons.txt', 'r+') as f:
lines = await f.readlines()
for line in lines:
temp = line.strip().split()
if len(extra_buttons.keys()) == 4:
break
if len(temp) == 2:
extra_buttons[temp[0].replace("_", " ")] = temp[1]
shorteners_list.clear()
if await aiopath.exists('shorteners.txt'):
async with aiopen('shorteners.txt', 'r+') as f:
lines = await f.readlines()
for line in lines:
temp = line.strip().split()
if len(temp) == 2:
shorteners_list.append({'domain': temp[0],'api_key': temp[1]})
config_dict.update({'ANIME_TEMPLATE': DEF_ANI_TEMP,
'AS_DOCUMENT': AS_DOCUMENT,
'AUTHORIZED_CHATS': AUTHORIZED_CHATS,
'AUTO_DELETE_MESSAGE_DURATION': AUTO_DELETE_MESSAGE_DURATION,
'BASE_URL': BASE_URL,
'BASE_URL_PORT': BASE_URL_PORT,
'BLACKLIST_USERS': BLACKLIST_USERS,
'BOT_TOKEN': BOT_TOKEN,
'BOT_MAX_TASKS': BOT_MAX_TASKS,
'CAP_FONT': CAP_FONT,
'CMD_SUFFIX': CMD_SUFFIX,
'DATABASE_URL': DATABASE_URL,
'REAL_DEBRID_API': REAL_DEBRID_API,
'DEBRID_LINK_API': DEBRID_LINK_API,
'FILELION_API': FILELION_API,
'DELETE_LINKS': DELETE_LINKS,
'DEFAULT_UPLOAD': DEFAULT_UPLOAD,
'DOWNLOAD_DIR': DOWNLOAD_DIR,
'EXCEP_CHATS': EXCEP_CHATS,
'STORAGE_THRESHOLD': STORAGE_THRESHOLD,
'TORRENT_LIMIT': TORRENT_LIMIT,
'DIRECT_LIMIT': DIRECT_LIMIT,
'YTDLP_LIMIT': YTDLP_LIMIT,
'GDRIVE_LIMIT': GDRIVE_LIMIT,
'CLONE_LIMIT': CLONE_LIMIT,
'MEGA_LIMIT': MEGA_LIMIT,
'LEECH_LIMIT': LEECH_LIMIT,
'FSUB_IDS': FSUB_IDS,
'USER_MAX_TASKS': USER_MAX_TASKS,
'USER_TIME_INTERVAL': USER_TIME_INTERVAL,
'PLAYLIST_LIMIT': PLAYLIST_LIMIT,
'DAILY_TASK_LIMIT': DAILY_TASK_LIMIT,
'DAILY_MIRROR_LIMIT': DAILY_MIRROR_LIMIT,
'DAILY_LEECH_LIMIT': DAILY_LEECH_LIMIT,
'MIRROR_LOG_ID': MIRROR_LOG_ID,
'LEECH_LOG_ID': LEECH_LOG_ID,
'LINKS_LOG_ID': LINKS_LOG_ID,
'BOT_PM': BOT_PM,
'DISABLE_DRIVE_LINK': DISABLE_DRIVE_LINK,
'BOT_THEME': BOT_THEME,
'IMAGES': IMAGES,
'IMG_SEARCH': IMG_SEARCH,
'IMG_PAGE': IMG_PAGE,
'IMDB_TEMPLATE': DEF_IMDB_TEMP,
'AUTHOR_NAME': AUTHOR_NAME,
'AUTHOR_URL': AUTHOR_URL,
'COVER_IMAGE': COVER_IMAGE,
'TITLE_NAME': TITLE_NAME,
'GD_INFO': GD_INFO,
'GDTOT_CRYPT': GDTOT_CRYPT,
'JIODRIVE_TOKEN': JIODRIVE_TOKEN,
'EQUAL_SPLITS': EQUAL_SPLITS,
'EXTENSION_FILTER': EXTENSION_FILTER,
'GDRIVE_ID': GDRIVE_ID,
'INCOMPLETE_TASK_NOTIFIER': INCOMPLETE_TASK_NOTIFIER,
'INDEX_URL': INDEX_URL,
'IS_TEAM_DRIVE': IS_TEAM_DRIVE,
'LEECH_FILENAME_PREFIX': LEECH_FILENAME_PREFIX,
'LEECH_FILENAME_SUFFIX': LEECH_FILENAME_SUFFIX,
'LEECH_FILENAME_CAPTION': LEECH_FILENAME_CAPTION,
'LEECH_FILENAME_REMNAME': LEECH_FILENAME_REMNAME,
'MIRROR_FILENAME_PREFIX': MIRROR_FILENAME_PREFIX,
'MIRROR_FILENAME_SUFFIX': MIRROR_FILENAME_SUFFIX,
'MIRROR_FILENAME_REMNAME': MIRROR_FILENAME_REMNAME,
'LEECH_SPLIT_SIZE': LEECH_SPLIT_SIZE,
'LOGIN_PASS': LOGIN_PASS,
'TOKEN_TIMEOUT': TOKEN_TIMEOUT,
'MEDIA_GROUP': MEDIA_GROUP,
'MEGA_EMAIL': MEGA_EMAIL,
'MEGA_PASSWORD': MEGA_PASSWORD,
'MDL_TEMPLATE': MDL_TEMPLATE,
'OWNER_ID': OWNER_ID,
'QUEUE_ALL': QUEUE_ALL,
'QUEUE_DOWNLOAD': QUEUE_DOWNLOAD,
'QUEUE_UPLOAD': QUEUE_UPLOAD,
'RCLONE_FLAGS': RCLONE_FLAGS,
'RCLONE_PATH': RCLONE_PATH,
'RCLONE_SERVE_URL': RCLONE_SERVE_URL,
'RCLONE_SERVE_USER': RCLONE_SERVE_USER,
'RCLONE_SERVE_PASS': RCLONE_SERVE_PASS,
'RCLONE_SERVE_PORT': RCLONE_SERVE_PORT,
'RSS_CHAT': RSS_CHAT,
'RSS_DELAY': RSS_DELAY,
'SAVE_MSG': SAVE_MSG,
'SAFE_MODE': SAFE_MODE,
'SEARCH_API_LINK': SEARCH_API_LINK,
'SEARCH_LIMIT': SEARCH_LIMIT,
'SEARCH_PLUGINS': SEARCH_PLUGINS,
'SET_COMMANDS': SET_COMMANDS,
'SHOW_MEDIAINFO': SHOW_MEDIAINFO,
'SCREENSHOTS_MODE': SCREENSHOTS_MODE,
'CLEAN_LOG_MSG': CLEAN_LOG_MSG,
'SHOW_EXTRA_CMDS': SHOW_EXTRA_CMDS,
'SOURCE_LINK': SOURCE_LINK,
'STATUS_LIMIT': STATUS_LIMIT,
'STATUS_UPDATE_INTERVAL': STATUS_UPDATE_INTERVAL,
'STOP_DUPLICATE': STOP_DUPLICATE,
'SUDO_USERS': SUDO_USERS,
'TELEGRAM_API': TELEGRAM_API,
'TELEGRAM_HASH': TELEGRAM_HASH,
'TIMEZONE': TIMEZONE,
'TORRENT_TIMEOUT': TORRENT_TIMEOUT,
'UPSTREAM_REPO': UPSTREAM_REPO,
'UPSTREAM_BRANCH': UPSTREAM_BRANCH,
'UPGRADE_PACKAGES': UPGRADE_PACKAGES,
'USER_SESSION_STRING': USER_SESSION_STRING,
'USER_TD_MODE':USER_TD_MODE,
'USER_TD_SA': USER_TD_SA,
'USE_SERVICE_ACCOUNTS': USE_SERVICE_ACCOUNTS,
'WEB_PINCODE': WEB_PINCODE,
'YT_DLP_OPTIONS': YT_DLP_OPTIONS})
if DATABASE_URL:
await DbManger().update_config(config_dict)
await gather(initiate_search_tools(), start_from_queued(), rclone_serve_booter())
async def get_buttons(key=None, edit_type=None, edit_mode=None, mess=None):
buttons = ButtonMaker()
if key is None:
buttons.ibutton('Config Variables', "botset var")
buttons.ibutton('Private Files', "botset private")
buttons.ibutton('Qbit Settings', "botset qbit")
buttons.ibutton('Aria2c Settings', "botset aria")
buttons.ibutton('Close', "botset close")
msg = '<b><i>Bot Settings:</i></b>'
elif key == 'var':
for k in list(OrderedDict(sorted(config_dict.items())).keys())[START:10+START]:
buttons.ibutton(k, f"botset editvar {k}")
buttons.ibutton('Back', "botset back")
buttons.ibutton('Close', "botset close")
for x in range(0, len(config_dict)-1, 10):
buttons.ibutton(f'{int(x/10)+1}', f"botset start var {x}", position='footer')
msg = f'<b>Config Variables</b> | <b>Page: {int(START/10)+1}</b>'
elif key == 'private':
buttons.ibutton('Back', "botset back")
buttons.ibutton('Close', "botset close")
msg = '''<u>Send any of these private files:</u>
<code>config.env, token.pickle, accounts.zip, list_drives.txt, categories.txt, shorteners.txt, cookies.txt, terabox.txt, .netrc or any other file!</code>
<i>To delete private file send only the file name as text message with or without extension.</i>
<b>NOTE:</b> Changing .netrc will not take effect for aria2c until restart.
<b>Timeout:</b> 60 sec'''
elif key == 'aria':
for k in list(aria2_options.keys())[START:10+START]:
buttons.ibutton(k, f"botset editaria {k}")
if STATE == 'view':
buttons.ibutton('Edit', "botset edit aria")
else:
buttons.ibutton('View', "botset view aria")
buttons.ibutton('Add New key', "botset editaria newkey")
buttons.ibutton('Back', "botset back")
buttons.ibutton('Close', "botset close")
for x in range(0, len(aria2_options)-1, 10):
buttons.ibutton(f'{int(x/10)+1}', f"botset start aria {x}", position='footer')
msg = f'Aria2c Options | Page: {int(START/10)+1} | State: {STATE}'
elif key == 'qbit':
for k in list(qbit_options.keys())[START:10+START]:
buttons.ibutton(k, f"botset editqbit {k}")
if STATE == 'view':
buttons.ibutton('Edit', "botset edit qbit")
else:
buttons.ibutton('View', "botset view qbit")
buttons.ibutton('Back', "botset back")
buttons.ibutton('Close', "botset close")
for x in range(0, len(qbit_options)-1, 10):
buttons.ibutton(
f'{int(x/10)+1}', f"botset start qbit {x}", position='footer')
msg = f'Qbittorrent Options | Page: {int(START/10)+1} | State: {STATE}'
elif edit_type == 'editvar':
msg = f'<b>Variable:</b> <code>{key}</code>\n\n'
msg += f'<b>Description:</b> {default_desp.get(key, "No Description Provided")}\n\n'
if mess.chat.type == ChatType.PRIVATE:
msg += f'<b>Value:</b> <spoiler> {config_dict.get(key, "None")} </spoiler>\n\n'
else:
buttons.ibutton('View Var Value',
f"botset showvar {key}", position="header")
buttons.ibutton('Back', "botset back var", position="footer")
if key not in bool_vars:
if not edit_mode:
buttons.ibutton('Edit Value', f"botset editvar {key} edit")
else:
buttons.ibutton('Stop Edit', f"botset editvar {key}")
if key not in ['TELEGRAM_HASH', 'TELEGRAM_API', 'OWNER_ID', 'BOT_TOKEN'] and key not in bool_vars:
buttons.ibutton('Reset', f"botset resetvar {key}")
buttons.ibutton('Close', "botset close", position="footer")
if edit_mode and key in ['SUDO_USERS', 'CMD_SUFFIX', 'OWNER_ID', 'USER_SESSION_STRING', 'TELEGRAM_HASH',
'TELEGRAM_API', 'AUTHORIZED_CHATS', 'DATABASE_URL', 'BOT_TOKEN', 'DOWNLOAD_DIR']:
msg += '<b>Note:</b> Restart required for this edit to take effect!\n\n'
if edit_mode and key not in bool_vars:
msg += '<i>Send a valid value for the above Var.</i> <b>Timeout:</b> 60 sec'
if key in bool_vars:
msg += '<i>Choose a valid value for the above Var</i>'
buttons.ibutton('True', f"botset boolvar {key} on")
buttons.ibutton('False', f"botset boolvar {key} off")
elif edit_type == 'editaria':
buttons.ibutton('Back', "botset back aria")
if key != 'newkey':
buttons.ibutton('Default', f"botset resetaria {key}")
buttons.ibutton('Empty String', f"botset emptyaria {key}")
buttons.ibutton('Close', "botset close")
if key == 'newkey':
msg = 'Send a key with value. Example: https-proxy-user:value'
else:
msg = f'Send a valid value for {key}. Timeout: 60 sec'
elif edit_type == 'editqbit':
buttons.ibutton('Back', "botset back qbit")
buttons.ibutton('Empty String', f"botset emptyqbit {key}")
buttons.ibutton('Close', "botset close")
msg = f'Send a valid value for {key}. Timeout: 60 sec'
button = buttons.build_menu(1) if key is None else buttons.build_menu(2)
return msg, button
async def update_buttons(message, key=None, edit_type=None, edit_mode=None):
msg, button = await get_buttons(key, edit_type, edit_mode, message)
await editMessage(message, msg, button)
async def edit_variable(_, message, pre_message, key):
handler_dict[message.chat.id] = False
value = message.text
if key == 'RSS_DELAY':
value = int(value)
addJob(value)
elif key == 'DOWNLOAD_DIR':
if not value.endswith('/'):
value += '/'
elif key in ['LINKS_LOG_ID', 'RSS_CHAT']:
value = int(value)
elif key == 'STATUS_UPDATE_INTERVAL':
value = int(value)
if len(download_dict) != 0:
async with status_reply_dict_lock:
if Interval:
Interval[0].cancel()
Interval.clear()
Interval.append(setInterval(value, update_all_messages))
elif key == 'TORRENT_TIMEOUT':
value = int(value)
downloads = await sync_to_async(aria2.get_downloads)
for download in downloads:
if not download.is_complete:
try:
await sync_to_async(aria2.client.change_option, download.gid, {'bt-stop-timeout': f'{value}'})
except Exception as e:
LOGGER.error(e)
aria2_options['bt-stop-timeout'] = f'{value}'
elif key == 'LEECH_SPLIT_SIZE':
value = min(int(value), MAX_SPLIT_SIZE)
elif key == 'BOT_THEME':
if not value.strip() in AVL_THEMES.keys():
value = 'minimal'
elif key == 'CAP_FONT':
value = value.strip().lower()
if value not in ['b', 'i', 'u', 's', 'spoiler', 'code']:
value = 'code'
elif key == 'BASE_URL_PORT':
value = int(value)
if config_dict['BASE_URL']:
await (await create_subprocess_exec("pkill", "-9", "-f", "gunicorn")).wait()
await create_subprocess_shell(f"gunicorn web.wserver:app --bind 0.0.0.0:{value} --worker-class gevent")
elif key == 'EXTENSION_FILTER':
fx = value.split()
GLOBAL_EXTENSION_FILTER.clear()
GLOBAL_EXTENSION_FILTER.extend(['aria2', '!qB'])
for x in fx:
if x.strip().startswith('.'):
x = x.lstrip('.')
GLOBAL_EXTENSION_FILTER.append(x.strip().lower())
elif key == 'GDRIVE_ID':
list_drives_dict['Main'] = {"drive_id": value, "index_link": config_dict['INDEX_URL']}
categories_dict['Root'] = {"drive_id": value, "index_link": config_dict['INDEX_URL']}
elif key == 'INDEX_URL':
list_drives_dict['Main'] = {"drive_id": config_dict['GDRIVE_ID'], "index_link": value}
categories_dict['Root'] = {"drive_id": config_dict['GDRIVE_ID'], "index_link": value}
elif value.isdigit():
value = int(value)
config_dict[key] = value
await update_buttons(pre_message, key, 'editvar', False)
await deleteMessage(message)
if DATABASE_URL:
await DbManger().update_config({key: value})
if key in ['SEARCH_PLUGINS', 'SEARCH_API_LINK']:
await initiate_search_tools()
elif key in ['QUEUE_ALL', 'QUEUE_DOWNLOAD', 'QUEUE_UPLOAD']:
await start_from_queued()
elif key in ['RCLONE_SERVE_URL', 'RCLONE_SERVE_PORT', 'RCLONE_SERVE_USER', 'RCLONE_SERVE_PASS']:
await rclone_serve_booter()
async def edit_aria(_, message, pre_message, key):
handler_dict[message.chat.id] = False
value = message.text
if key == 'newkey':
key, value = [x.strip() for x in value.split(':', 1)]
elif value.lower() == 'true':
value = "true"
elif value.lower() == 'false':
value = "false"
if key in aria2c_global:
await sync_to_async(aria2.set_global_options, {key: value})
else:
downloads = await sync_to_async(aria2.get_downloads)
for download in downloads:
if not download.is_complete:
try:
await sync_to_async(aria2.client.change_option, download.gid, {key: value})
except Exception as e:
LOGGER.error(e)
aria2_options[key] = value
await update_buttons(pre_message, 'aria')
await deleteMessage(message)
if DATABASE_URL:
await DbManger().update_aria2(key, value)
async def edit_qbit(_, message, pre_message, key):
handler_dict[message.chat.id] = False
value = message.text
if value.lower() == 'true':
value = True
elif value.lower() == 'false':
value = False
elif key == 'max_ratio':
value = float(value)
elif value.isdigit():
value = int(value)
await sync_to_async(get_client().app_set_preferences, {key: value})
qbit_options[key] = value
await update_buttons(pre_message, 'qbit')
await deleteMessage(message)
if DATABASE_URL:
await DbManger().update_qbittorrent(key, value)
async def update_private_file(_, message, pre_message):
handler_dict[message.chat.id] = False
if not message.media and (file_name := message.text):
path = file_name
fn = file_name.rsplit('.zip', 1)[0]
if await aiopath.isfile(fn) and file_name != 'config.env':
await remove(fn)
if fn == 'accounts':
if await aiopath.exists('accounts'):
await aiormtree('accounts')
if await aiopath.exists('rclone_sa'):
await aiormtree('rclone_sa')
config_dict['USE_SERVICE_ACCOUNTS'] = False
if DATABASE_URL:
await DbManger().update_config({'USE_SERVICE_ACCOUNTS': False})
elif file_name in ['.netrc', 'netrc']:
await (await create_subprocess_exec("touch", ".netrc")).wait()
await (await create_subprocess_exec("chmod", "600", ".netrc")).wait()
await (await create_subprocess_exec("cp", ".netrc", "/root/.netrc")).wait()
elif file_name.startswith('wzml_'):
path = f"bot/helper/themes/{file_name.rsplit('.py', 1)[0]}.py"
if await aiopath.isfile(path):
await remove(path)
elif file_name in ['buttons.txt', 'buttons']:
extra_buttons.clear()
elif file_name in ['categories.txt', 'categories']:
categories_dict.clear()
if GDRIVE_ID := config_dict['GDRIVE_ID']:
categories_dict['Root'] = {"drive_id": GDRIVE_ID, "index_link": config_dict['INDEX_URL']}
elif file_name in ['list_drives.txt', 'list_drives']:
list_drives_dict.clear()
if GDRIVE_ID := config_dict['GDRIVE_ID']:
list_drives_dict['Main'] = {"drive_id": GDRIVE_ID, "index_link": config_dict['INDEX_URL']}
elif file_name in ['shorteners.txt', 'shorteners']:
shorteners_list.clear()
await deleteMessage(message)
elif doc := message.document:
file_name = doc.file_name
path = file_name
if file_name.startswith('wzml_') and file_name.endswith('.py'):
path = f'bot/helper/themes/{file_name}'
await message.download(file_name=f'{getcwd()}/{path}')
if file_name == 'accounts.zip':
if await aiopath.exists('accounts'):
await aiormtree('accounts')
if await aiopath.exists('rclone_sa'):
await aiormtree('rclone_sa')
await (await create_subprocess_exec("7z", "x", "-o.", "-aoa", "accounts.zip", "accounts/*.json")).wait()
await (await create_subprocess_exec("chmod", "-R", "777", "accounts")).wait()
elif file_name == 'list_drives.txt':
list_drives_dict.clear()
if GDRIVE_ID := config_dict['GDRIVE_ID']:
list_drives_dict['Main'] = {"drive_id": GDRIVE_ID, "index_link": config_dict['INDEX_URL']}
async with aiopen('list_drives.txt', 'r+') as f:
lines = await f.readlines()
for line in lines:
sep = 2 if line.strip().split()[-1].startswith('http') else 1
temp = line.strip().rsplit(maxsplit=sep)
name = "Main Custom" if temp[0].casefold() == "Main" else temp[0]
list_drives_dict[name] = {'drive_id': temp[1], 'index_link': (temp[2] if sep == 2 else '')}
elif file_name == 'categories.txt':
categories_dict.clear()
if GDRIVE_ID := config_dict['GDRIVE_ID']:
categories_dict['Root'] = {"drive_id": GDRIVE_ID, "index_link": config_dict['INDEX_URL']}
async with aiopen('categories.txt', 'r+') as f:
lines = await f.readlines()
for line in lines:
sep = 2 if line.strip().split()[-1].startswith('http') else 1
temp = line.strip().rsplit(maxsplit=sep)
name = "Root Custom" if temp[0].casefold() == "Root" else temp[0]
categories_dict[name] = {'drive_id': temp[1], 'index_link': (temp[2] if sep == 2 else '')}
elif file_name == 'buttons.txt':
extra_buttons.clear()
async with aiopen('buttons.txt', 'r+') as f:
lines = await f.readlines()