diff --git a/bot/__init__.py b/bot/__init__.py index 8b83bfb71209..4ccdd18e4715 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -295,6 +295,7 @@ app_version="@Z_Mirror Session", device_model="@Z_Mirror Bot", system_version="@Z_Mirror Server", + max_concurrent_transmissions=10, ).start() IS_PREMIUM_USER = user.me.is_premium # type: ignore log_info(f"Successfully logged into @{user.me.username} DC: {user.session.dc_id}.") # type: ignore @@ -1275,7 +1276,7 @@ app_version="@Z_Mirror Session", device_model="@Z_Mirror Bot", system_version="@Z_Mirror Server", - workers=99999, + max_concurrent_transmissions=10, ).start() BASE += ("oAtiUyppVYRQkuWg8DG2p") diff --git a/bot/helper/common.py b/bot/helper/common.py index 2b3fcdba7efe..29ec993db041 100644 --- a/bot/helper/common.py +++ b/bot/helper/common.py @@ -397,13 +397,8 @@ async def beforeStart(self): "gdl" ]: if ( - not self.isYtDlp - and not self.isJd - and ( - is_gdrive_id(self.link) - or is_rclone_path(self.link) - or is_gdrive_link(self.link) - ) + is_rclone_path(self.link) or + is_gdrive_link(self.link) ): await self.isTokenExists( self.link, @@ -831,7 +826,7 @@ async def run_multi(self, input_list, folder_name, obj): nextmsg.sender_chat = self.user if Intervals["stopAll"]: return - obj( + await obj( self.client, # type: ignore nextmsg, self.isQbit, @@ -886,7 +881,7 @@ async def initBulk(self, input_list, bulk_start, bulk_end, obj): nextmsg.from_user = self.user else: nextmsg.sender_chat = self.user - obj( + await obj( self.client, # type: ignore nextmsg, self.isQbit, diff --git a/bot/helper/ext_utils/bot_utils.py b/bot/helper/ext_utils/bot_utils.py index fc5257ace281..78bf22a23aac 100644 --- a/bot/helper/ext_utils/bot_utils.py +++ b/bot/helper/ext_utils/bot_utils.py @@ -411,13 +411,18 @@ def wrapper( *args, **kwargs ): - return bot_loop.create_task( + bot_loop.create_task( func( *args, **kwargs ) ) + async def dummy(): + pass + + return dummy + return wrapper diff --git a/bot/helper/listeners/qbit_listener.py b/bot/helper/listeners/qbit_listener.py index da8b19617fcb..0cbe41c3fd6c 100644 --- a/bot/helper/listeners/qbit_listener.py +++ b/bot/helper/listeners/qbit_listener.py @@ -98,7 +98,10 @@ async def _stop_duplicate(tor): ".!qB", 1 )[0] - msg, button = await stop_duplicate_check(task.listener) # type: ignore + ( + msg, + button + ) = await stop_duplicate_check(task.listener) # type: ignore if msg: _onDownloadError( msg, diff --git a/bot/helper/task_utils/rclone_utils/list.py b/bot/helper/task_utils/rclone_utils/list.py index 13ea43aae3c6..3271bee39d52 100644 --- a/bot/helper/task_utils/rclone_utils/list.py +++ b/bot/helper/task_utils/rclone_utils/list.py @@ -20,7 +20,6 @@ from bot.helper.ext_utils.bot_utils import ( cmd_exec, new_thread, - new_task, update_user_ldata, ) from bot.helper.ext_utils.db_handler import DbManager @@ -39,7 +38,6 @@ LIST_LIMIT = 6 -@new_task async def path_updates(_, query, obj): await query.answer() message = query.message diff --git a/bot/helper/telegram_helper/message_utils.py b/bot/helper/telegram_helper/message_utils.py index 1ae04156cbe0..b4585462cddc 100644 --- a/bot/helper/telegram_helper/message_utils.py +++ b/bot/helper/telegram_helper/message_utils.py @@ -4,6 +4,7 @@ ) from pyrogram.errors import ( FloodWait, + FloodPremiumWait, PeerIdInvalid, RPCError, UserNotParticipant, @@ -111,7 +112,7 @@ async def sendRss(text): disable_web_page_preview=True, disable_notification=True, ) - except FloodWait as f: + except (FloodWait, FloodPremiumWait) as f: LOGGER.warning(str(f)) await sleep(f.value * 1.2) # type: ignore return await sendRss(text) diff --git a/bot/modules/bot_settings.py b/bot/modules/bot_settings.py index 85b88a1f4fb3..da5d3b1a047e 100644 --- a/bot/modules/bot_settings.py +++ b/bot/modules/bot_settings.py @@ -12,12 +12,12 @@ wait_for, ) from dotenv import load_dotenv -from functools import partial from io import BytesIO from os import ( environ, getcwd ) + from pyrogram import filters from pyrogram.handlers import ( MessageHandler, diff --git a/bot/modules/cancel_task.py b/bot/modules/cancel_task.py index 68bd6e189638..7f5b96c7dbe7 100644 --- a/bot/modules/cancel_task.py +++ b/bot/modules/cancel_task.py @@ -16,9 +16,8 @@ OWNER_ID, task_dict, task_dict_lock, - user_data, + user_data ) -from bot.helper.ext_utils.bot_utils import new_task from bot.helper.ext_utils.status_utils import ( getTaskByGid, getAllTasks, @@ -33,7 +32,7 @@ sendMessage, auto_delete_message, deleteMessage, - editMessage, + editMessage ) @@ -183,7 +182,7 @@ def create_cancel_buttons(isSudo, userId=""): f"canall ms {(MirrorStatus.STATUS_EXTRACTING).split(' ')[0]} {userId}" ) buttons.ibutton( - "Archiving", + "ᴀʀᴄʜɪᴠɪɴɢ", f"canall ms {(MirrorStatus.STATUS_ARCHIVING).split(' ')[0]} {userId}" ) buttons.ibutton( @@ -266,7 +265,6 @@ async def cancell_all_buttons(_, message): ) -@new_task async def cancel_all_update(_, query): data = query.data.split() message = query.message diff --git a/bot/modules/clone.py b/bot/modules/clone.py index b999cba573aa..40113024df21 100644 --- a/bot/modules/clone.py +++ b/bot/modules/clone.py @@ -4,21 +4,25 @@ from pyrogram.handlers import MessageHandler from secrets import token_urlsafe -from bot import LOGGER, task_dict, task_dict_lock, bot +from bot import ( + LOGGER, + task_dict, + task_dict_lock, + bot, + bot_loop +) from bot.helper.ext_utils.bot_utils import ( - new_task, sync_to_async, - new_task, cmd_exec, arg_parser, - COMMAND_USAGE, + COMMAND_USAGE ) from bot.helper.ext_utils.exceptions import DirectDownloadLinkException from bot.helper.ext_utils.links_utils import ( is_gdrive_link, is_share_link, is_rclone_path, - is_gdrive_id, + is_gdrive_id ) from bot.helper.ext_utils.task_manager import ( limit_checker, @@ -26,7 +30,7 @@ ) from bot.helper.listeners.task_listener import TaskListener from bot.helper.task_utils.download_utils.direct_link_generator import ( - direct_link_generator, + direct_link_generator ) from bot.helper.task_utils.gdrive_utils.clone import gdClone from bot.helper.task_utils.gdrive_utils.count import gdCount @@ -40,7 +44,7 @@ delete_links, sendMessage, deleteMessage, - sendStatusMessage, + sendStatusMessage ) @@ -69,7 +73,6 @@ def __init__( super().__init__() self.isClone = True - @new_task async def newEvent(self): self.pmsg = await sendMessage( self.message, @@ -454,10 +457,11 @@ async def _proceedToClone(self, sync): async def clone(client, message): - Clone( - client, - message - ).newEvent() # type: ignore + bot_loop.create_task( + Clone( + client, + message + ).newEvent()) bot.add_handler( # type: ignore diff --git a/bot/modules/exec.py b/bot/modules/exec.py index 942b6b51273a..87e73ab93e8b 100644 --- a/bot/modules/exec.py +++ b/bot/modules/exec.py @@ -12,10 +12,7 @@ from traceback import format_exc from bot import LOGGER, bot -from bot.helper.ext_utils.bot_utils import ( - sync_to_async, - new_task -) +from bot.helper.ext_utils.bot_utils import sync_to_async from bot.helper.telegram_helper.bot_commands import BotCommands from bot.helper.telegram_helper.filters import CustomFilters from bot.helper.telegram_helper.message_utils import ( @@ -61,7 +58,6 @@ async def send(msg, message): ) -@new_task async def aioexecute(_, message): await send( await do( @@ -72,7 +68,6 @@ async def aioexecute(_, message): ) -@new_task async def execute(_, message): await send( await do( diff --git a/bot/modules/gd_count.py b/bot/modules/gd_count.py index 1c933f1c8ed0..4fb45bde718f 100644 --- a/bot/modules/gd_count.py +++ b/bot/modules/gd_count.py @@ -2,10 +2,7 @@ from pyrogram.handlers import MessageHandler from bot import bot -from bot.helper.ext_utils.bot_utils import ( - sync_to_async, - new_task -) +from bot.helper.ext_utils.bot_utils import sync_to_async from bot.helper.ext_utils.links_utils import is_gdrive_link from bot.helper.ext_utils.status_utils import get_readable_file_size from bot.helper.task_utils.gdrive_utils.count import gdCount @@ -19,7 +16,6 @@ ) -@new_task async def countNode(_, message): args = message.text.split() from_user = message.from_user diff --git a/bot/modules/gd_delete.py b/bot/modules/gd_delete.py index 2a08af5601a4..ba460768de2e 100644 --- a/bot/modules/gd_delete.py +++ b/bot/modules/gd_delete.py @@ -2,10 +2,7 @@ from pyrogram.handlers import MessageHandler from bot import bot, LOGGER -from bot.helper.ext_utils.bot_utils import ( - sync_to_async, - new_task -) +from bot.helper.ext_utils.bot_utils import sync_to_async from bot.helper.ext_utils.links_utils import is_gdrive_link from bot.helper.task_utils.gdrive_utils.delete import gdDelete from bot.helper.telegram_helper.bot_commands import BotCommands @@ -17,7 +14,6 @@ ) -@new_task async def deletefile(_, message): args = message.text.split() from_user = message.from_user diff --git a/bot/modules/gd_search.py b/bot/modules/gd_search.py index 52f57c4f9ba6..dcfd39854ec1 100644 --- a/bot/modules/gd_search.py +++ b/bot/modules/gd_search.py @@ -16,7 +16,6 @@ ) from bot.helper.ext_utils.bot_utils import ( sync_to_async, - new_task, get_telegraph_list ) from bot.helper.ext_utils.status_utils import get_readable_time @@ -135,7 +134,6 @@ async def _list_drive( ) -@new_task async def select_type(_, query): user_id = query.from_user.id message = query.message diff --git a/bot/modules/help.py b/bot/modules/help.py index e86f48405b2b..81589f04f1d3 100644 --- a/bot/modules/help.py +++ b/bot/modules/help.py @@ -1,7 +1,7 @@ from pyrogram.filters import regex from pyrogram.handlers import CallbackQueryHandler -from bot import bot, LOGGER +from bot import bot from bot.helper.ext_utils.bot_utils import COMMAND_USAGE from bot.helper.ext_utils.help_messages import ( YT_HELP_DICT, diff --git a/bot/modules/leech_del.py b/bot/modules/leech_del.py index 7f39157abd3c..d9ebbb40b0b4 100644 --- a/bot/modules/leech_del.py +++ b/bot/modules/leech_del.py @@ -15,7 +15,7 @@ delete = set() -@new_task + async def delete_leech(client, message): args = message.text.split() if len(args) > 1: @@ -53,8 +53,7 @@ async def delete_leech(client, message): message_id, reply_message ) - -@new_task + async def deleting(client, chat_id, message_id, message): delete.add(message_id) try: diff --git a/bot/modules/mirror_leech.py b/bot/modules/mirror_leech.py index e1368ca3d3a9..282155126503 100644 --- a/bot/modules/mirror_leech.py +++ b/bot/modules/mirror_leech.py @@ -10,11 +10,11 @@ from bot import ( bot, DOWNLOAD_DIR, - LOGGER + LOGGER, + bot_loop ) from bot.helper.ext_utils.bot_utils import ( get_content_type, - new_task, sync_to_async, arg_parser, COMMAND_USAGE, @@ -93,7 +93,6 @@ def __init__( self.isNzb = isNzb self.file_ = None - @new_task async def newEvent(self): self.pmsg = await sendMessage( self.message, @@ -534,69 +533,69 @@ async def newEvent(self): async def mirror(client, message): - Mirror( + bot_loop.create_task(Mirror( client, message - ).newEvent() # type: ignore + ).newEvent()) # type: ignore async def qb_mirror(client, message): - Mirror( + bot_loop.create_task(Mirror( client, message, isQbit=True - ).newEvent() # type: ignore + ).newEvent()) # type: ignore async def jd_mirror(client, message): - Mirror( + bot_loop.create_task(Mirror( client, message, isJd=True - ).newEvent() # type: ignore + ).newEvent()) # type: ignore async def nzb_mirror(client, message): - Mirror( + bot_loop.create_task(Mirror( client, message, isNzb=True - ).newEvent() # type: ignore + ).newEvent()) # type: ignore async def leech(client, message): - Mirror( + bot_loop.create_task(Mirror( client, message, isLeech=True - ).newEvent() # type: ignore + ).newEvent()) # type: ignore async def qb_leech(client, message): - Mirror( + bot_loop.create_task(Mirror( client, message, isQbit=True, isLeech=True - ).newEvent() # type: ignore + ).newEvent()) # type: ignore async def jd_leech(client, message): - Mirror( + bot_loop.create_task(Mirror( client, message, isLeech=True, isJd=True - ).newEvent() # type: ignore + ).newEvent()) # type: ignore async def nzb_leech(client, message): - Mirror( + bot_loop.create_task(Mirror( client, message, isLeech=True, isNzb=True - ).newEvent() # type: ignore + ).newEvent()) # type: ignore bot.add_handler( # type: ignore diff --git a/bot/modules/rmdb.py b/bot/modules/rmdb.py index 1ebd084a9ca2..89659ac9c47c 100644 --- a/bot/modules/rmdb.py +++ b/bot/modules/rmdb.py @@ -3,7 +3,6 @@ from pyrogram.handlers import MessageHandler from bot import DATABASE_URL, bot, config_dict -from bot.helper.ext_utils.bot_utils import new_task from bot.helper.ext_utils.links_utils import ( is_magnet, is_url @@ -15,7 +14,6 @@ from bot.helper.telegram_helper.message_utils import sendMessage -@new_task async def rmAllTokens(_, message): if DATABASE_URL: await DbManager().delete_all_access_tokens() @@ -28,7 +26,6 @@ async def rmAllTokens(_, message): ) -@new_task async def rmdbNode(_, message): if ( DATABASE_URL diff --git a/bot/modules/shell.py b/bot/modules/shell.py index a8cee68ddbec..57648947f6d3 100644 --- a/bot/modules/shell.py +++ b/bot/modules/shell.py @@ -6,10 +6,7 @@ ) from bot import LOGGER, bot -from bot.helper.ext_utils.bot_utils import ( - cmd_exec, - new_task -) +from bot.helper.ext_utils.bot_utils import cmd_exec from bot.helper.telegram_helper.bot_commands import BotCommands from bot.helper.telegram_helper.filters import CustomFilters from bot.helper.telegram_helper.message_utils import ( @@ -18,7 +15,6 @@ ) -@new_task async def shell(_, message): cmd = message.text.split(maxsplit=1) if len(cmd) == 1: diff --git a/bot/modules/status.py b/bot/modules/status.py index a9276a959c84..9ac26b74e514 100644 --- a/bot/modules/status.py +++ b/bot/modules/status.py @@ -37,7 +37,6 @@ ) from bot.helper.ext_utils.bot_utils import ( cmd_exec, - new_task, sync_to_async ) from bot.helper.ext_utils.status_utils import ( @@ -62,7 +61,6 @@ from bot.helper.telegram_helper.button_build import ButtonMaker -@new_task async def mirror_status(_, message): async with task_dict_lock: count = len(task_dict) @@ -104,7 +102,6 @@ async def mirror_status(_, message): await deleteMessage(message) -@new_task async def status_pages(_, query): user_id = query.from_user.id spam = ( diff --git a/bot/modules/torrent_search.py b/bot/modules/torrent_search.py index 84ddb12d5276..c95717b33133 100644 --- a/bot/modules/torrent_search.py +++ b/bot/modules/torrent_search.py @@ -16,10 +16,7 @@ config_dict, qbittorrent_client ) -from bot.helper.ext_utils.bot_utils import ( - sync_to_async, - new_task -) +from bot.helper.ext_utils.bot_utils import sync_to_async from bot.helper.ext_utils.status_utils import get_readable_file_size from bot.helper.ext_utils.telegraph_helper import telegraph from bot.helper.telegram_helper.bot_commands import BotCommands @@ -429,7 +426,6 @@ async def torrentSearch(_, message): ) -@new_task async def torrentSearchUpdate(_, query): user_id = query.from_user.id message = query.message diff --git a/bot/modules/users_settings.py b/bot/modules/users_settings.py index 099d86a328c4..85312609d950 100644 --- a/bot/modules/users_settings.py +++ b/bot/modules/users_settings.py @@ -7,7 +7,11 @@ from html import escape from io import BytesIO from math import ceil -from os import getcwd, path as os_path +from os import ( + getcwd, + path as os_path +) + from pyrogram import filters from pyrogram.handlers import ( MessageHandler, diff --git a/bot/modules/ytdlp.py b/bot/modules/ytdlp.py index f4c6d6aca469..13f3d0f57072 100644 --- a/bot/modules/ytdlp.py +++ b/bot/modules/ytdlp.py @@ -2,10 +2,10 @@ DOWNLOAD_DIR, bot, config_dict, - LOGGER + LOGGER, + bot_loop ) from bot.helper.ext_utils.bot_utils import ( - new_task, sync_to_async, arg_parser, COMMAND_USAGE, @@ -58,7 +58,6 @@ def __init__( self.isYtDlp = True self.isLeech = isLeech - @new_task async def newEvent(self): self.pmsg = await sendMessage( self.message, @@ -306,11 +305,11 @@ async def newEvent(self): ) return finally: - await self.run_multi( + self.run_multi( input_list, folder_name, YtDlp - ) + ) # type: ignore if not qual: qual = await YtSelection(self).get_quality(result) @@ -332,18 +331,18 @@ async def newEvent(self): async def ytdl(client, message): - YtDlp( + bot_loop.create_task(YtDlp( client, message - ).newEvent() # type: ignore + ).newEvent()) # type: ignore async def ytdlleech(client, message): - YtDlp( + bot_loop.create_task(YtDlp( client, message, isLeech=True - ).newEvent() # type: ignore + ).newEvent()) # type: ignore bot.add_handler( # type: ignore