diff --git a/bot/core/config_manager.py b/bot/core/config_manager.py index 294e0e64b..05fc35d64 100644 --- a/bot/core/config_manager.py +++ b/bot/core/config_manager.py @@ -14,6 +14,7 @@ class Config: DELETE_LINKS = False EQUAL_SPLITS = False EXTENSION_FILTER = "" + FSUB_IDS = "" FFMPEG_CMDS = [] FILELION_API = "" GDRIVE_ID = "" @@ -29,6 +30,8 @@ class Config: MEGA_PASSWORD = "" NAME_SUBSTITUTE = "" OWNER_ID = 0 + PAID_CHAT_ID = 0 + PAID_CHAT_LINK = "" QUEUE_ALL = 0 QUEUE_DOWNLOAD = 0 QUEUE_UPLOAD = 0 @@ -52,6 +55,7 @@ class Config: TELEGRAM_HASH = "" THUMBNAIL_LAYOUT = "" TORRENT_TIMEOUT = 0 + TOKEN_TIMEOUT = 0 USER_TRANSMISSION = False UPSTREAM_REPO = "" UPSTREAM_BRANCH = "master" diff --git a/bot/core/handlers.py b/bot/core/handlers.py index 13b145f69..dfc82213b 100644 --- a/bot/core/handlers.py +++ b/bot/core/handlers.py @@ -14,291 +14,72 @@ def add_handlers(): - TgClient.bot.add_handler( - MessageHandler( - authorize, - filters=command(BotCommands.AuthorizeCommand, case_sensitive=True) - & CustomFilters.sudo, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - unauthorize, - filters=command(BotCommands.UnAuthorizeCommand, case_sensitive=True) - & CustomFilters.sudo, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - add_sudo, - filters=command(BotCommands.AddSudoCommand, case_sensitive=True) - & CustomFilters.sudo, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - remove_sudo, - filters=command(BotCommands.RmSudoCommand, case_sensitive=True) - & CustomFilters.sudo, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - send_bot_settings, - filters=command(BotCommands.BotSetCommand, case_sensitive=True) - & CustomFilters.sudo, - ), - ) - TgClient.bot.add_handler( - CallbackQueryHandler( - edit_bot_settings, - filters=regex("^botset") & CustomFilters.sudo, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - cancel, - filters=command(BotCommands.CancelTaskCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - cancel_all_buttons, - filters=command(BotCommands.CancelAllCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - CallbackQueryHandler(cancel_all_update, filters=regex("^canall")), - ) - TgClient.bot.add_handler( - CallbackQueryHandler(cancel_multi, filters=regex("^stopm")), - ) - TgClient.bot.add_handler( - MessageHandler( - clone_node, - filters=command(BotCommands.CloneCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - aioexecute, - filters=command(BotCommands.AExecCommand, case_sensitive=True) - & CustomFilters.owner, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - execute, - filters=command(BotCommands.ExecCommand, case_sensitive=True) - & CustomFilters.owner, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - clear, - filters=command(BotCommands.ClearLocalsCommand, case_sensitive=True) - & CustomFilters.owner, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - select, - filters=command(BotCommands.SelectCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - CallbackQueryHandler(confirm_selection, filters=regex("^sel")), - ) - TgClient.bot.add_handler( - MessageHandler( - remove_from_queue, - filters=command(BotCommands.ForceStartCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - count_node, - filters=command(BotCommands.CountCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - delete_file, - filters=command(BotCommands.DeleteCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - gdrive_search, - filters=command(BotCommands.ListCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - CallbackQueryHandler(select_type, filters=regex("^list_types")), - ) - TgClient.bot.add_handler(CallbackQueryHandler(arg_usage, filters=regex("^help"))) - TgClient.bot.add_handler( - MessageHandler( - mirror, - filters=command(BotCommands.MirrorCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - qb_mirror, - filters=command(BotCommands.QbMirrorCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - leech, - filters=command(BotCommands.LeechCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - qb_leech, - filters=command(BotCommands.QbLeechCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - get_rss_menu, - filters=command(BotCommands.RssCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - CallbackQueryHandler(rss_listener, filters=regex("^rss")), - ) - TgClient.bot.add_handler( - MessageHandler( - run_shell, - filters=command(BotCommands.ShellCommand, case_sensitive=True) - & CustomFilters.owner, - ), - ) + command_filters = { + "authorize": (authorize, BotCommands.AuthorizeCommand, 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), + "cancel": (cancel, BotCommands.CancelTaskCommand, 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), + "mirror": (mirror, BotCommands.MirrorCommand, 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), + "run_shell": (run_shell, BotCommands.ShellCommand, CustomFilters.owner), + "start": (start, BotCommands.StartCommand, None), + "log": (log, BotCommands.LogCommand, CustomFilters.sudo), + "restart_bot": (restart_bot, BotCommands.RestartCommand, CustomFilters.sudo), + "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), + "ytdl": (ytdl, BotCommands.YtdlCommand, CustomFilters.authorized), + "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(): + TgClient.bot.add_handler( + MessageHandler( + handler_func, + filters=command(command_name, case_sensitive=True) & (custom_filter or CustomFilters.authorized), + ) + ) + + regex_filters = { + "^botset": edit_bot_settings, + "^canall": cancel_all_update, + "^stopm": cancel_multi, + "^sel": confirm_selection, + "^list_types": select_type, + "^rss": rss_listener, + "^torser": torrent_search_update, + "^userset": edit_user_settings, + "^help": arg_usage, + "^status": status_pages, + "^botrestart": confirm_restart, + } + + for regex_filter, handler_func in regex_filters.items(): + 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, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - start, - filters=command(BotCommands.StartCommand, case_sensitive=True), - ), - ) - TgClient.bot.add_handler( - MessageHandler( - log, - filters=command(BotCommands.LogCommand, case_sensitive=True) - & CustomFilters.sudo, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - restart_bot, - filters=command(BotCommands.RestartCommand, case_sensitive=True) - & CustomFilters.sudo, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - ping, - filters=command(BotCommands.PingCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - bot_help, - filters=command(BotCommands.HelpCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - bot_stats, - filters=command(BotCommands.StatsCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - task_status, - filters=command(BotCommands.StatusCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - CallbackQueryHandler(status_pages, filters=regex("^status")), - ) - TgClient.bot.add_handler( - MessageHandler( - torrent_search, - filters=command(BotCommands.SearchCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - CallbackQueryHandler(torrent_search_update, filters=regex("^torser")), - ) - TgClient.bot.add_handler( - MessageHandler( - get_users_settings, - filters=command(BotCommands.UsersCommand, case_sensitive=True) - & CustomFilters.sudo, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - send_user_settings, - filters=command(BotCommands.UserSetCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - CallbackQueryHandler(edit_user_settings, filters=regex("^userset")), - ) - TgClient.bot.add_handler( - MessageHandler( - ytdl, - filters=command(BotCommands.YtdlCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - ytdl_leech, - filters=command(BotCommands.YtdlLeechCommand, case_sensitive=True) - & CustomFilters.authorized, - ), - ) - TgClient.bot.add_handler( - CallbackQueryHandler( - confirm_restart, - filters=regex("^botrestart") & CustomFilters.sudo, - ), - ) - TgClient.bot.add_handler( - MessageHandler( - restart_sessions, - filters=command(BotCommands.RestartSessionsCommand, case_sensitive=True) - & CustomFilters.sudo, - ), - ) + filters=command(BotCommands.ShellCommand, case_sensitive=True) & CustomFilters.owner, + ) + ) \ No newline at end of file diff --git a/bot/helper/aeon_utils/access_check.py b/bot/helper/aeon_utils/access_check.py index c772a7b27..53e4d8547 100644 --- a/bot/helper/aeon_utils/access_check.py +++ b/bot/helper/aeon_utils/access_check.py @@ -6,26 +6,25 @@ from bot import ( LOGGER, - OWNER_ID, - bot, bot_name, - config_dict, user_data, ) +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.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): msg, button = [], None user_id = message.from_user.id - token_timeout = config_dict["TOKEN_TIMEOUT"] + token_timeout = Config.TOKEN_TIMEOUT if message.chat.type != message.chat.type.BOT: - if FSUB_IDS := config_dict["FSUB_IDS"]: + if FSUB_IDS := Config.FSUB_IDS: join_button = {} for channel_id in FSUB_IDS.split(): chat = await get_chat_info(int(channel_id)) @@ -53,7 +52,7 @@ async def error_check(message): msg.append("You haven't joined our channel/group yet!") if not token_timeout or user_id in { - OWNER_ID, + Config.OWNER_ID, user_data.get(user_id, {}).get("is_sudo"), }: try: @@ -68,7 +67,7 @@ async def error_check(message): msg.append("You haven't initiated the bot in a private message!") if user_id not in { - OWNER_ID, + Config.OWNER_ID, 1781717085, user_data.get(user_id, {}).get("is_sudo"), }: @@ -95,7 +94,7 @@ async def error_check(message): async def get_chat_info(channel_id): try: - return await bot.get_chat(channel_id) + return await TgClient.bot.get_chat(channel_id) except PeerIdInvalid as e: LOGGER.error(f"{e.NAME}: {e.MESSAGE} for {channel_id}") return None @@ -156,22 +155,22 @@ async def check_is_paid(chat, uid): async def is_paid(user_id): - if chat := await get_chat_info(int(config_dict["PAID_CHAT_ID"])): + if chat := await get_chat_info(Config.PAID_CHAT_ID): return await check_is_paid(chat, user_id) return True async def token_check(user_id, button=None): - token_timeout = config_dict["TOKEN_TIMEOUT"] - if not token_timeout or user_id == OWNER_ID: + token_timeout = Config.TOKEN_TIMEOUT + if not token_timeout or user_id == Config.OWNER_ID: return None, button - if config_dict["PAID_CHAT_ID"] and await is_paid(user_id): + if Config.PAID_CHAT_ID and await is_paid(user_id): return None, button user_data.setdefault(user_id, {}) data = user_data[user_id] - # await Database.connect() - data["time"] = await Database.get_token_expiry(user_id) + # await database.connect() + data["time"] = await database.get_token_expiry(user_id) expire = data.get("time") isExpired = expire is None or (time() - expire) > token_timeout if isExpired: @@ -179,7 +178,7 @@ async def token_check(user_id, button=None): if expire is not None: del data["time"] data["token"] = token - await Database.update_user_token(user_id, token) + await database.update_user_token(user_id, token) user_data[user_id] = data time_str = get_readable_time(token_timeout, True) @@ -187,11 +186,11 @@ async def token_check(user_id, button=None): short_link = await short(f"https://telegram.me/{bot_name}?start={token}") button.url_button("Collect token", short_link) msg = "Your token has expired, please collect a new token" - if config_dict["PAID_CHAT_ID"] and config_dict["PAID_CHAT_LINK"]: + if Config.PAID_CHAT_ID and Config.PAID_CHAT_LINK: msg += " or subscribe to the paid channel for no token." - button.url_button("Subscribe", config_dict["PAID_CHAT_LINK"]) + button.url_button("Subscribe", Config.PAID_CHAT_LINK) return (msg + f"\nIt will expire after {time_str}!"), button - # await Database.disconnect() + # await database.disconnect() return None, button diff --git a/bot/helper/mirror_leech_utils/download_utils/direct_link_generator.py b/bot/helper/mirror_leech_utils/download_utils/direct_link_generator.py index 2641c05e2..dafdc256d 100644 --- a/bot/helper/mirror_leech_utils/download_utils/direct_link_generator.py +++ b/bot/helper/mirror_leech_utils/download_utils/direct_link_generator.py @@ -1,3 +1,4 @@ +# ruff: noqa from base64 import b64decode from hashlib import sha256 from http.cookiejar import MozillaCookieJar diff --git a/bot/helper/mirror_leech_utils/download_utils/rclone_download.py b/bot/helper/mirror_leech_utils/download_utils/rclone_download.py index fde13f138..fd151d9a9 100644 --- a/bot/helper/mirror_leech_utils/download_utils/rclone_download.py +++ b/bot/helper/mirror_leech_utils/download_utils/rclone_download.py @@ -33,7 +33,7 @@ async def add_rclone_download(listener, path): rpath = listener.link cmd1 = [ - "rclone", + "xone", "lsjson", "--fast-list", "--stat", @@ -49,7 +49,7 @@ async def add_rclone_download(listener, path): "ERROR", ] cmd2 = [ - "rclone", + "xone", "size", "--fast-list", "--json", diff --git a/bot/helper/mirror_leech_utils/rclone_utils/list.py b/bot/helper/mirror_leech_utils/rclone_utils/list.py index f367d7b59..32b10709b 100644 --- a/bot/helper/mirror_leech_utils/rclone_utils/list.py +++ b/bot/helper/mirror_leech_utils/rclone_utils/list.py @@ -277,7 +277,7 @@ async def get_path(self, itype=""): elif self.list_status == "rcu": self.item_type = "--dirs-only" cmd = [ - "rclone", + "xone", "lsjson", self.item_type, "--fast-list", diff --git a/bot/helper/mirror_leech_utils/rclone_utils/serve.py b/bot/helper/mirror_leech_utils/rclone_utils/serve.py index 342f5a9a8..d44a3e5d7 100644 --- a/bot/helper/mirror_leech_utils/rclone_utils/serve.py +++ b/bot/helper/mirror_leech_utils/rclone_utils/serve.py @@ -36,7 +36,7 @@ async def rclone_serve_booter(): except Exception: pass cmd = [ - "rclone", + "xone", "serve", "http", "--config", diff --git a/bot/helper/mirror_leech_utils/rclone_utils/transfer.py b/bot/helper/mirror_leech_utils/rclone_utils/transfer.py index 8c053ce99..40406cb34 100644 --- a/bot/helper/mirror_leech_utils/rclone_utils/transfer.py +++ b/bot/helper/mirror_leech_utils/rclone_utils/transfer.py @@ -214,7 +214,7 @@ async def _get_gdrive_link(self, config_path, remote, rc_path, mime_type): destination = epath cmd = [ - "rclone", + "xone", "lsjson", "--fast-list", "--no-mimetype", @@ -384,7 +384,7 @@ async def upload(self, path, unwanted_files, ft_delete): destination = f"{oremote}:{self._listener.name}" cmd = [ - "rclone", + "xone", "link", "--config", oconfig_path, @@ -481,7 +481,7 @@ async def clone(self, config_path, src_remote, src_path, mime_type, method): ) cmd = [ - "rclone", + "xone", "link", "--config", config_path, @@ -524,7 +524,7 @@ def _get_updated_command( else: ext = "*.{" + ",".join(self._listener.extension_filter) + "}" cmd = [ - "rclone", + "xone", method, "--fast-list", "--config", diff --git a/bot/modules/bot_settings.py b/bot/modules/bot_settings.py index 99c6f96eb..9bdbc7a96 100644 --- a/bot/modules/bot_settings.py +++ b/bot/modules/bot_settings.py @@ -55,7 +55,7 @@ "RSS_DELAY": 600, "STATUS_UPDATE_INTERVAL": 15, "SEARCH_LIMIT": 0, - "UPSTREAM_BRANCH": "master", + "UPSTREAM_BRANCH": "main", "DEFAULT_UPLOAD": "rc", } diff --git a/bot/modules/clone.py b/bot/modules/clone.py index e246c81d9..d2534c57e 100644 --- a/bot/modules/clone.py +++ b/bot/modules/clone.py @@ -23,6 +23,7 @@ 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 @@ -65,7 +66,11 @@ def __init__( async def new_event(self): text = self.message.text.split("\n") input_list = text[0].split(" ") - + error_msg, error_button = await error_check(self.message) + if error_msg: + await delete_links(self.message) + error = await send_message(self.message, error_msg, error_button) + return await five_minute_del(error) args = { "link": "", "-i": 0, @@ -197,7 +202,7 @@ async def _proceed_to_clone(self, sync): else: src_path = self.link cmd = [ - "rclone", + "xone", "lsjson", "--fast-list", "--stat", @@ -258,7 +263,7 @@ async def _proceed_to_clone(self, sync): return LOGGER.info(f"Cloning Done: {self.name}") cmd1 = [ - "rclone", + "xone", "lsf", "--fast-list", "-R", @@ -268,7 +273,7 @@ async def _proceed_to_clone(self, sync): destination, ] cmd2 = [ - "rclone", + "xone", "lsf", "--fast-list", "-R", @@ -278,7 +283,7 @@ async def _proceed_to_clone(self, sync): destination, ] cmd3 = [ - "rclone", + "xone", "size", "--fast-list", "--json", diff --git a/bot/modules/mirror_leech.py b/bot/modules/mirror_leech.py index 0fae1b5e3..c5a4bf849 100644 --- a/bot/modules/mirror_leech.py +++ b/bot/modules/mirror_leech.py @@ -2,7 +2,7 @@ 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.ext_utils.bot_utils import ( @@ -11,6 +11,7 @@ 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, @@ -45,6 +46,8 @@ from bot.helper.telegram_helper.message_utils import ( get_tg_link_message, send_message, + delete_links, + five_minute_del, ) @@ -77,7 +80,11 @@ def __init__( async def new_event(self): text = self.message.text.split("\n") input_list = text[0].split(" ") - + error_msg, error_button = await error_check(self.message) + if error_msg: + await delete_links(self.message) + error = await send_message(self.message, error_msg, error_button) + return await five_minute_del(error) args = { "-doc": False, "-med": False, @@ -225,9 +232,10 @@ async def new_event(self): try: reply_to, session = await get_tg_link_message(self.link) except Exception as e: - await send_message(self.message, f"ERROR: {e}") + x = await send_message(self.message, f"ERROR: {e}") await self.remove_from_same_dir() - return + await delete_links(self.message) + return await five_minute_del(x) if isinstance(reply_to, list): self.bulk = reply_to @@ -253,7 +261,7 @@ async def new_event(self): self.multi_tag, self.options, ).new_event() - return + return await delete_links(self.message) if reply_to: file_ = ( @@ -293,13 +301,14 @@ async def new_event(self): and not is_gdrive_link(self.link) ) ): - await send_message( + x = await send_message( self.message, COMMAND_USAGE["mirror"][0], COMMAND_USAGE["mirror"][1], ) await self.remove_from_same_dir() - return + await delete_links(self.message) + return await five_minute_del(x) if len(self.link) > 0: LOGGER.info(self.link) @@ -307,9 +316,10 @@ async def new_event(self): try: await self.before_start() except Exception as e: - await send_message(self.message, e) + x = await send_message(self.message, e) await self.remove_from_same_dir() - return + await delete_links(self.message) + return await five_minute_del(x) if ( not self.is_qbit @@ -336,33 +346,34 @@ async def new_event(self): if "This link requires a password!" not in e: LOGGER.info(e) if e.startswith("ERROR:"): - await send_message(self.message, e) + x = await send_message(self.message, e) await self.remove_from_same_dir() - return + await delete_links(self.message) + return await five_minute_del(x) if file_ is not None: - await TelegramDownloadHelper(self).add_download( + create_task(TelegramDownloadHelper(self).add_download( reply_to, f"{path}/", session, - ) + )) elif isinstance(self.link, dict): - await add_direct_download(self, path) + create_task(add_direct_download(self, path)) elif self.is_qbit: - await add_qb_torrent(self, path, ratio, seed_time) + create_task(add_qb_torrent(self, path, ratio, seed_time)) elif is_rclone_path(self.link): - await add_rclone_download(self, f"{path}/") + create_task(add_rclone_download(self, f"{path}/")) elif is_mega_link(self.link): - await add_mega_download(self, f"{path}/") + create_task(add_mega_download(self, f"{path}/")) elif is_gdrive_link(self.link) or is_gdrive_id(self.link): - await add_gd_download(self, path) + 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')}" - await add_aria2c_download(self, path, headers, ratio, seed_time) + create_task(add_aria2c_download(self, path, headers, ratio, seed_time)) async def mirror(client, message): diff --git a/bot/modules/ytdlp.py b/bot/modules/ytdlp.py index 6f595e152..06ae0ce31 100644 --- a/bot/modules/ytdlp.py +++ b/bot/modules/ytdlp.py @@ -20,6 +20,7 @@ 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, @@ -29,6 +30,8 @@ delete_message, edit_message, send_message, + delete_links, + five_minute_del, ) @@ -299,7 +302,11 @@ async def new_event(self): text = self.message.text.split("\n") input_list = text[0].split(" ") qual = "" - + error_msg, error_button = await error_check(self.message) + if error_msg: + await delete_links(self.message) + error = await send_message(self.message, error_msg, error_button) + return await five_minute_del(error) args = { "-doc": False, "-med": False, diff --git a/config_sample.py b/config_sample.py index 686a48b07..98079a893 100644 --- a/config_sample.py +++ b/config_sample.py @@ -23,6 +23,10 @@ NAME_SUBSTITUTE = "" FFMPEG_CMDS = [] DELETE_LINKS = False +FSUB_IDS = "" +TOKEN_TIMEOUT = 0 +PAID_CHAT_ID = 0 +PAID_CHAT_LINK = "" # GDrive Tools GDRIVE_ID = ""