diff --git a/bot/core/handlers.py b/bot/core/handlers.py index dfc82213b..ab457f068 100644 --- a/bot/core/handlers.py +++ b/bot/core/handlers.py @@ -16,26 +16,66 @@ def add_handlers(): command_filters = { "authorize": (authorize, BotCommands.AuthorizeCommand, CustomFilters.sudo), - "unauthorize": (unauthorize, BotCommands.UnAuthorizeCommand, CustomFilters.sudo), + "unauthorize": ( + unauthorize, + BotCommands.UnAuthorizeCommand, + CustomFilters.sudo, + ), "add_sudo": (add_sudo, BotCommands.AddSudoCommand, CustomFilters.sudo), "remove_sudo": (remove_sudo, BotCommands.RmSudoCommand, CustomFilters.sudo), - "send_bot_settings": (send_bot_settings, BotCommands.BotSetCommand, CustomFilters.sudo), + "send_bot_settings": ( + send_bot_settings, + BotCommands.BotSetCommand, + CustomFilters.sudo, + ), "cancel": (cancel, BotCommands.CancelTaskCommand, CustomFilters.authorized), - "cancel_all_buttons": (cancel_all_buttons, BotCommands.CancelAllCommand, CustomFilters.authorized), - "clone_node": (clone_node, BotCommands.CloneCommand, CustomFilters.authorized), + "cancel_all_buttons": ( + cancel_all_buttons, + BotCommands.CancelAllCommand, + CustomFilters.authorized, + ), + "clone_node": ( + clone_node, + BotCommands.CloneCommand, + CustomFilters.authorized, + ), "aioexecute": (aioexecute, BotCommands.AExecCommand, CustomFilters.owner), "execute": (execute, BotCommands.ExecCommand, CustomFilters.owner), "clear": (clear, BotCommands.ClearLocalsCommand, CustomFilters.owner), "select": (select, BotCommands.SelectCommand, CustomFilters.authorized), - "remove_from_queue": (remove_from_queue, BotCommands.ForceStartCommand, CustomFilters.authorized), - "count_node": (count_node, BotCommands.CountCommand, CustomFilters.authorized), - "delete_file": (delete_file, BotCommands.DeleteCommand, CustomFilters.authorized), - "gdrive_search": (gdrive_search, BotCommands.ListCommand, CustomFilters.authorized), + "remove_from_queue": ( + remove_from_queue, + BotCommands.ForceStartCommand, + CustomFilters.authorized, + ), + "count_node": ( + count_node, + BotCommands.CountCommand, + CustomFilters.authorized, + ), + "delete_file": ( + delete_file, + BotCommands.DeleteCommand, + CustomFilters.authorized, + ), + "gdrive_search": ( + gdrive_search, + BotCommands.ListCommand, + CustomFilters.authorized, + ), "mirror": (mirror, BotCommands.MirrorCommand, CustomFilters.authorized), - "qb_mirror": (qb_mirror, BotCommands.QbMirrorCommand, CustomFilters.authorized), + "qb_mirror": ( + qb_mirror, + BotCommands.QbMirrorCommand, + CustomFilters.authorized, + ), "leech": (leech, BotCommands.LeechCommand, CustomFilters.authorized), "qb_leech": (qb_leech, BotCommands.QbLeechCommand, CustomFilters.authorized), - "get_rss_menu": (get_rss_menu, BotCommands.RssCommand, CustomFilters.authorized), + "get_rss_menu": ( + get_rss_menu, + BotCommands.RssCommand, + CustomFilters.authorized, + ), "run_shell": (run_shell, BotCommands.ShellCommand, CustomFilters.owner), "start": (start, BotCommands.StartCommand, None), "log": (log, BotCommands.LogCommand, CustomFilters.sudo), @@ -43,21 +83,46 @@ def add_handlers(): "ping": (ping, BotCommands.PingCommand, CustomFilters.authorized), "bot_help": (bot_help, BotCommands.HelpCommand, CustomFilters.authorized), "bot_stats": (bot_stats, BotCommands.StatsCommand, CustomFilters.authorized), - "task_status": (task_status, BotCommands.StatusCommand, CustomFilters.authorized), - "torrent_search": (torrent_search, BotCommands.SearchCommand, CustomFilters.authorized), - "get_users_settings": (get_users_settings, BotCommands.UsersCommand, CustomFilters.sudo), - "send_user_settings": (send_user_settings, BotCommands.UserSetCommand, CustomFilters.authorized), + "task_status": ( + task_status, + BotCommands.StatusCommand, + CustomFilters.authorized, + ), + "torrent_search": ( + torrent_search, + BotCommands.SearchCommand, + CustomFilters.authorized, + ), + "get_users_settings": ( + get_users_settings, + BotCommands.UsersCommand, + CustomFilters.sudo, + ), + "send_user_settings": ( + send_user_settings, + BotCommands.UserSetCommand, + CustomFilters.authorized, + ), "ytdl": (ytdl, BotCommands.YtdlCommand, CustomFilters.authorized), - "ytdl_leech": (ytdl_leech, BotCommands.YtdlLeechCommand, CustomFilters.authorized), - "restart_sessions": (restart_sessions, BotCommands.RestartSessionsCommand, CustomFilters.sudo), + "ytdl_leech": ( + ytdl_leech, + BotCommands.YtdlLeechCommand, + CustomFilters.authorized, + ), + "restart_sessions": ( + restart_sessions, + BotCommands.RestartSessionsCommand, + CustomFilters.sudo, + ), } - for handler_name, (handler_func, command_name, custom_filter) in command_filters.items(): + for handler_func, command_name, custom_filter in command_filters.values(): TgClient.bot.add_handler( MessageHandler( handler_func, - filters=command(command_name, case_sensitive=True) & (custom_filter or CustomFilters.authorized), - ) + filters=command(command_name, case_sensitive=True) + & (custom_filter or CustomFilters.authorized), + ), ) regex_filters = { @@ -75,11 +140,14 @@ def add_handlers(): } for regex_filter, handler_func in regex_filters.items(): - TgClient.bot.add_handler(CallbackQueryHandler(handler_func, filters=regex(regex_filter))) + TgClient.bot.add_handler( + CallbackQueryHandler(handler_func, filters=regex(regex_filter)) + ) TgClient.bot.add_handler( EditedMessageHandler( run_shell, - filters=command(BotCommands.ShellCommand, case_sensitive=True) & CustomFilters.owner, - ) - ) \ No newline at end of file + filters=command(BotCommands.ShellCommand, case_sensitive=True) + & CustomFilters.owner, + ), + ) diff --git a/bot/helper/aeon_utils/access_check.py b/bot/helper/aeon_utils/access_check.py index 53e4d8547..54dad2289 100644 --- a/bot/helper/aeon_utils/access_check.py +++ b/bot/helper/aeon_utils/access_check.py @@ -9,13 +9,13 @@ bot_name, user_data, ) +from bot.core.aeon_client import TgClient from bot.core.config_manager import Config from bot.helper.aeon_utils.shorteners import short from bot.helper.ext_utils.db_handler import database from bot.helper.ext_utils.help_messages import nsfw_keywords from bot.helper.ext_utils.status_utils import get_readable_time from bot.helper.telegram_helper.button_build import ButtonMaker -from bot.core.aeon_client import TgClient async def error_check(message): diff --git a/bot/modules/clone.py b/bot/modules/clone.py index d2534c57e..fc31b4ae6 100644 --- a/bot/modules/clone.py +++ b/bot/modules/clone.py @@ -5,6 +5,7 @@ from aiofiles.os import remove from bot import LOGGER, bot_loop, task_dict, task_dict_lock +from bot.helper.aeon_utils.access_check import error_check from bot.helper.ext_utils.bot_utils import ( COMMAND_USAGE, arg_parser, @@ -23,7 +24,6 @@ from bot.helper.mirror_leech_utils.download_utils.direct_link_generator import ( direct_link_generator, ) -from bot.helper.aeon_utils.access_check import error_check from bot.helper.mirror_leech_utils.gdrive_utils.clone import GoogleDriveClone from bot.helper.mirror_leech_utils.gdrive_utils.count import GoogleDriveCount from bot.helper.mirror_leech_utils.rclone_utils.transfer import RcloneTransferHelper @@ -107,7 +107,7 @@ async def new_event(self): if is_bulk: await self.init_bulk(input_list, bulk_start, bulk_end, Clone) - return + return None await self.get_tag(text) @@ -122,14 +122,15 @@ async def new_event(self): COMMAND_USAGE["clone"][0], COMMAND_USAGE["clone"][1], ) - return + return None LOGGER.info(self.link) try: await self.before_start() except Exception as e: await send_message(self.message, e) - return + return None await self._proceed_to_clone(sync) + return None async def _proceed_to_clone(self, sync): if is_share_link(self.link): diff --git a/bot/modules/mirror_leech.py b/bot/modules/mirror_leech.py index c5a4bf849..0561cbb00 100644 --- a/bot/modules/mirror_leech.py +++ b/bot/modules/mirror_leech.py @@ -1,17 +1,18 @@ +from asyncio import create_task from base64 import b64encode from re import match as re_match from aiofiles.os import path as aiopath -from asyncio import create_task + from bot import LOGGER, bot_loop, task_dict_lock from bot.core.config_manager import Config +from bot.helper.aeon_utils.access_check import error_check from bot.helper.ext_utils.bot_utils import ( COMMAND_USAGE, arg_parser, get_content_type, sync_to_async, ) -from bot.helper.aeon_utils.access_check import error_check from bot.helper.ext_utils.exceptions import DirectDownloadLinkException from bot.helper.ext_utils.links_utils import ( is_gdrive_id, @@ -44,10 +45,10 @@ TelegramDownloadHelper, ) from bot.helper.telegram_helper.message_utils import ( - get_tg_link_message, - send_message, delete_links, five_minute_del, + get_tg_link_message, + send_message, ) @@ -214,7 +215,7 @@ async def new_event(self): self.same_dir[fd_name]["total"] -= 1 else: await self.init_bulk(input_list, bulk_start, bulk_end, Mirror) - return + return None if len(self.bulk) != 0: del self.bulk[0] @@ -352,28 +353,38 @@ async def new_event(self): return await five_minute_del(x) if file_ is not None: - create_task(TelegramDownloadHelper(self).add_download( - reply_to, - f"{path}/", - session, - )) - elif isinstance(self.link, dict): + create_task( + TelegramDownloadHelper(self).add_download( + reply_to, + f"{path}/", + session, + ) + ) + return None + if isinstance(self.link, dict): create_task(add_direct_download(self, path)) - elif self.is_qbit: + return None + if self.is_qbit: create_task(add_qb_torrent(self, path, ratio, seed_time)) - elif is_rclone_path(self.link): + return None + if is_rclone_path(self.link): create_task(add_rclone_download(self, f"{path}/")) - elif is_mega_link(self.link): + return None + if is_mega_link(self.link): create_task(add_mega_download(self, f"{path}/")) - elif is_gdrive_link(self.link) or is_gdrive_id(self.link): + return None + if is_gdrive_link(self.link) or is_gdrive_id(self.link): create_task(add_gd_download(self, path)) - else: - ussr = args["-au"] - pssw = args["-ap"] - if ussr or pssw: - auth = f"{ussr}:{pssw}" - headers += f" authorization: Basic {b64encode(auth.encode()).decode('ascii')}" - create_task(add_aria2c_download(self, path, headers, ratio, seed_time)) + return None + ussr = args["-au"] + pssw = args["-ap"] + if ussr or pssw: + auth = f"{ussr}:{pssw}" + headers += ( + f" authorization: Basic {b64encode(auth.encode()).decode('ascii')}" + ) + create_task(add_aria2c_download(self, path, headers, ratio, seed_time)) + return None async def mirror(client, message): diff --git a/bot/modules/ytdlp.py b/bot/modules/ytdlp.py index 06ae0ce31..9004c3f41 100644 --- a/bot/modules/ytdlp.py +++ b/bot/modules/ytdlp.py @@ -9,6 +9,7 @@ from bot import LOGGER, bot_loop, task_dict_lock from bot.core.config_manager import Config +from bot.helper.aeon_utils.access_check import error_check from bot.helper.ext_utils.bot_utils import ( COMMAND_USAGE, arg_parser, @@ -20,18 +21,17 @@ get_readable_file_size, get_readable_time, ) -from bot.helper.aeon_utils.access_check import error_check from bot.helper.listeners.task_listener import TaskListener from bot.helper.mirror_leech_utils.download_utils.yt_dlp_download import ( YoutubeDLHelper, ) from bot.helper.telegram_helper.button_build import ButtonMaker from bot.helper.telegram_helper.message_utils import ( + delete_links, delete_message, edit_message, - send_message, - delete_links, five_minute_del, + send_message, ) @@ -414,7 +414,7 @@ async def new_event(self): self.same_dir[fd_name]["total"] -= 1 else: await self.init_bulk(input_list, bulk_start, bulk_end, YtDlp) - return + return None if len(self.bulk) != 0: del self.bulk[0] @@ -435,7 +435,7 @@ async def new_event(self): COMMAND_USAGE["yt"][1], ) await self.remove_from_same_dir() - return + return None if "mdisk.me" in self.link: self.name, self.link = await _mdisk(self.link, self.name) @@ -445,7 +445,7 @@ async def new_event(self): except Exception as e: await send_message(self.message, e) await self.remove_from_same_dir() - return + return None options = {"usenetrc": True, "cookiefile": "cookies.txt"} if opt: @@ -481,7 +481,7 @@ async def new_event(self): msg = str(e).replace("<", " ").replace(">", " ") await send_message(self.message, f"{self.tag} {msg}") await self.remove_from_same_dir() - return + return None finally: await self.run_multi(input_list, YtDlp) @@ -489,12 +489,13 @@ async def new_event(self): qual = await YtSelection(self).get_quality(result) if qual is None: await self.remove_from_same_dir() - return + return None LOGGER.info(f"Downloading with YT-DLP: {self.link}") playlist = "entries" in result ydl = YoutubeDLHelper(self) await ydl.add_download(path, qual, playlist, opt) + return None async def ytdl(client, message):