diff --git a/.python-version b/.python-version index 3a4f41ef3..fdcfcfdfc 100644 --- a/.python-version +++ b/.python-version @@ -1 +1 @@ -3.13 \ No newline at end of file +3.12 \ No newline at end of file diff --git a/bot/core/__init__.py b/bot/core/__init__.py index d3f5a12fa..e69de29bb 100644 --- a/bot/core/__init__.py +++ b/bot/core/__init__.py @@ -1 +0,0 @@ - diff --git a/bot/core/aeon_client.py b/bot/core/aeon_client.py index af042436b..8d98a0c4c 100644 --- a/bot/core/aeon_client.py +++ b/bot/core/aeon_client.py @@ -43,6 +43,7 @@ async def start_user(cls): Config.TELEGRAM_HASH, session_string=Config.USER_SESSION_STRING, parse_mode=enums.ParseMode.HTML, + no_updates=True sleep_threshold=60, max_concurrent_transmissions=10, ) diff --git a/bot/core/config_manager.py b/bot/core/config_manager.py index 5ad84d83e..61cc2cad6 100644 --- a/bot/core/config_manager.py +++ b/bot/core/config_manager.py @@ -13,7 +13,7 @@ class Config: DEFAULT_UPLOAD = "rc" DOWNLOAD_DIR = "/usr/src/app/downloads/" EXTENSION_FILTER = "" - FFMPEG_CMDS = {} + FFMPEG_CMDS: ClassVar[Dict[str, List[str]]] = {} FILELION_API = "" GDRIVE_ID = "" INCOMPLETE_TASK_NOTIFIER = False diff --git a/bot/helper/__init__.py b/bot/helper/__init__.py index d3f5a12fa..e69de29bb 100644 --- a/bot/helper/__init__.py +++ b/bot/helper/__init__.py @@ -1 +0,0 @@ - diff --git a/bot/helper/ext_utils/__init__.py b/bot/helper/ext_utils/__init__.py index d3f5a12fa..e69de29bb 100644 --- a/bot/helper/ext_utils/__init__.py +++ b/bot/helper/ext_utils/__init__.py @@ -1 +0,0 @@ - diff --git a/bot/helper/listeners/__init__.py b/bot/helper/listeners/__init__.py index d3f5a12fa..e69de29bb 100644 --- a/bot/helper/listeners/__init__.py +++ b/bot/helper/listeners/__init__.py @@ -1 +0,0 @@ - diff --git a/bot/helper/listeners/qbit_listener.py b/bot/helper/listeners/qbit_listener.py index ffabc848b..17a390697 100644 --- a/bot/helper/listeners/qbit_listener.py +++ b/bot/helper/listeners/qbit_listener.py @@ -58,12 +58,8 @@ async def _on_seed_finish(tor): @new_task async def _stop_duplicate(tor): - if task := await get_task_by_gid(tor.hash[:12]): - if task.listener.stop_duplicate: - task.listener.name = tor.content_path.rsplit("/", 1)[-1].rsplit( - ".!qB", - 1, - )[0] + if (task := await get_task_by_gid(tor.hash[:12])) and task.listener.stop_duplicate: + task.listener.name = tor.content_path.rsplit("/", 1)[-1].rsplit(".!qB", 1)[0] msg, button = await stop_duplicate_check(task.listener) if msg: _on_download_error(msg, tor, button) diff --git a/bot/helper/listeners/task_listener.py b/bot/helper/listeners/task_listener.py index 1a9c6b0e0..d0c2ea5c6 100644 --- a/bot/helper/listeners/task_listener.py +++ b/bot/helper/listeners/task_listener.py @@ -364,8 +364,8 @@ async def on_upload_complete( await send_message(self.message, msg) else: fmsg = "" - for index, (link, name) in enumerate(files.items(), start=1): - fmsg += f"{index}. {name}\n" + for index, (url, name) in enumerate(files.items(), start=1): + fmsg += f"{index}. {name}\n" if len(fmsg.encode() + msg.encode()) > 4000: await send_message( self.user_id, diff --git a/bot/helper/mirror_leech_utils/__init__.py b/bot/helper/mirror_leech_utils/__init__.py index d3f5a12fa..e69de29bb 100644 --- a/bot/helper/mirror_leech_utils/__init__.py +++ b/bot/helper/mirror_leech_utils/__init__.py @@ -1 +0,0 @@ - diff --git a/bot/helper/mirror_leech_utils/download_utils/__init__.py b/bot/helper/mirror_leech_utils/download_utils/__init__.py index d3f5a12fa..e69de29bb 100644 --- a/bot/helper/mirror_leech_utils/download_utils/__init__.py +++ b/bot/helper/mirror_leech_utils/download_utils/__init__.py @@ -1 +0,0 @@ - diff --git a/bot/helper/mirror_leech_utils/download_utils/yt_dlp_download.py b/bot/helper/mirror_leech_utils/download_utils/yt_dlp_download.py index 7a9433f1a..ee6eadf6c 100644 --- a/bot/helper/mirror_leech_utils/download_utils/yt_dlp_download.py +++ b/bot/helper/mirror_leech_utils/download_utils/yt_dlp_download.py @@ -379,6 +379,6 @@ def _set_options(self, options): self.opts[key].append(value) elif key == "download_ranges": if isinstance(value, list): - self.opts[key] = lambda info, ytdl: value + self.opts[key] = (lambda v: (lambda info, ytdl: v))(value) else: self.opts[key] = value diff --git a/bot/helper/mirror_leech_utils/gdrive_utils/__init__.py b/bot/helper/mirror_leech_utils/gdrive_utils/__init__.py index d3f5a12fa..e69de29bb 100644 --- a/bot/helper/mirror_leech_utils/gdrive_utils/__init__.py +++ b/bot/helper/mirror_leech_utils/gdrive_utils/__init__.py @@ -1 +0,0 @@ - diff --git a/bot/helper/mirror_leech_utils/gdrive_utils/download.py b/bot/helper/mirror_leech_utils/gdrive_utils/download.py index edf045d69..42d533b30 100644 --- a/bot/helper/mirror_leech_utils/gdrive_utils/download.py +++ b/bot/helper/mirror_leech_utils/gdrive_utils/download.py @@ -62,9 +62,8 @@ def download(self): self.listener.is_cancelled = True finally: self._updater.cancel() - if self.listener.is_cancelled: - return None - async_to_sync(self.listener.on_download_complete) + if not self.listener.is_cancelled: + async_to_sync(self.listener.on_download_complete) def _download_folder(self, folder_id, path, folder_name): folder_name = folder_name.replace("/", "") diff --git a/bot/helper/mirror_leech_utils/gdrive_utils/upload.py b/bot/helper/mirror_leech_utils/gdrive_utils/upload.py index 2d2b769bb..8b0bacd6a 100644 --- a/bot/helper/mirror_leech_utils/gdrive_utils/upload.py +++ b/bot/helper/mirror_leech_utils/gdrive_utils/upload.py @@ -47,6 +47,9 @@ def upload(self, unwanted_files, ft_delete): self.service = self.authorize() LOGGER.info(f"Uploading: {self._path}") self._updater = SetInterval(self.update_interval, self.progress) + link = None + dir_id = None + mime_type = None try: if ospath.isfile(self._path): if self._path.lower().endswith( @@ -96,24 +99,25 @@ def upload(self, unwanted_files, ft_delete): self._is_errored = True finally: self._updater.cancel() - if self.listener.is_cancelled and not self._is_errored: - if mime_type == "Folder": - LOGGER.info("Deleting uploaded data from Drive...") - self.service.files().delete( - fileId=dir_id, - supportsAllDrives=True, - ).execute() - return - if self._is_errored: - return - async_to_sync( - self.listener.on_upload_complete, - link, - self.total_files, - self.total_folders, - mime_type, - dir_id=self.get_id_from_url(link), - ) + + if self.listener.is_cancelled and not self._is_errored: + if mime_type == "Folder" and dir_id: + LOGGER.info("Deleting uploaded data from Drive...") + self.service.files().delete( + fileId=dir_id, + supportsAllDrives=True, + ).execute() + return + if self._is_errored: + return + async_to_sync( + self.listener.on_upload_complete, + link, + self.total_files, + self.total_folders, + mime_type, + dir_id=self.get_id_from_url(link) if link else None, + ) def _upload_dir(self, input_directory, dest_id, unwanted_files, ft_delete): list_dirs = listdir(input_directory) diff --git a/bot/helper/mirror_leech_utils/rclone_utils/__init__.py b/bot/helper/mirror_leech_utils/rclone_utils/__init__.py index d3f5a12fa..e69de29bb 100644 --- a/bot/helper/mirror_leech_utils/rclone_utils/__init__.py +++ b/bot/helper/mirror_leech_utils/rclone_utils/__init__.py @@ -1 +0,0 @@ - diff --git a/bot/helper/mirror_leech_utils/status_utils/__init__.py b/bot/helper/mirror_leech_utils/status_utils/__init__.py index d3f5a12fa..e69de29bb 100644 --- a/bot/helper/mirror_leech_utils/status_utils/__init__.py +++ b/bot/helper/mirror_leech_utils/status_utils/__init__.py @@ -1 +0,0 @@ - diff --git a/bot/helper/telegram_helper/__init__.py b/bot/helper/telegram_helper/__init__.py index d3f5a12fa..e69de29bb 100644 --- a/bot/helper/telegram_helper/__init__.py +++ b/bot/helper/telegram_helper/__init__.py @@ -1 +0,0 @@ - diff --git a/bot/modules/mediainfo.py b/bot/modules/mediainfo.py index 59d8c6af3..3146c051d 100644 --- a/bot/modules/mediainfo.py +++ b/bot/modules/mediainfo.py @@ -63,13 +63,12 @@ async def gen_mediainfo(message, link=None, media=None, msg=None): headers = { "user-agent": "Mozilla/5.0 (Linux; Android 12; 2201116PI) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Mobile Safari/537.36", } - async with aiohttp.ClientSession() as session: - async with session.get(link, headers=headers) as response: - file_size = int(response.headers.get("Content-Length", 0)) - async with aiopen(des_path, "wb") as f: - async for chunk in response.content.iter_chunked(10000000): - await f.write(chunk) - break + async with aiohttp.ClientSession() as session, session.get(link, headers=headers) as response, aiopen(des_path, "wb") as f: + file_size = int(response.headers.get("Content-Length", 0)) + async with aiopen(des_path, "wb") as f: + async for chunk in response.content.iter_chunked(10000000): + await f.write(chunk) + break elif media: des_path = ospath.join(path, media.file_name) file_size = media.file_size diff --git a/bot/modules/mirror_leech.py b/bot/modules/mirror_leech.py index b81269695..a9684ab8f 100644 --- a/bot/modules/mirror_leech.py +++ b/bot/modules/mirror_leech.py @@ -235,9 +235,8 @@ async def new_event(self): path = f"{Config.DOWNLOAD_DIR}{self.mid}{self.folder_name}" - if not self.link and (reply_to := self.message.reply_to_message): - if reply_to.text: - self.link = reply_to.text.split("\n", 1)[0].strip() + if not self.link and (reply_to := self.message.reply_to_message) and reply_to.text: + self.link = reply_to.text.split("\n", 1)[0].strip() if is_telegram_link(self.link): try: reply_to, session = await get_tg_link_message(self.link, user_id) diff --git a/bot/modules/restart.py b/bot/modules/restart.py index 734d6bb71..0cede6d06 100644 --- a/bot/modules/restart.py +++ b/bot/modules/restart.py @@ -66,26 +66,25 @@ async def send_incomplete_task_message(cid, msg_id, msg): async def restart_notification(): if await aiopath.isfile(".restartmsg"): - with open(".restartmsg") as f: - chat_id, msg_id = map(int, f) + with aiopen(".restartmsg", "r") as f: + chat_id, msg_id = map(int, await f.read().splitlines()) else: chat_id, msg_id = 0, 0 - if Config.INCOMPLETE_TASK_NOTIFIER and Config.DATABASE_URL: - if notifier_dict := await database.get_incomplete_tasks(): - for cid, data in notifier_dict.items(): - msg = ( - "Restarted Successfully!" if cid == chat_id else "Bot Restarted!" - ) - for tag, links in data.items(): - msg += f"\n\n{tag}: " - for index, link in enumerate(links, start=1): - msg += f" {index} |" - if len(msg.encode()) > 4000: - await send_incomplete_task_message(cid, msg_id, msg) - msg = "" - if msg: - await send_incomplete_task_message(cid, msg_id, msg) + if Config.INCOMPLETE_TASK_NOTIFIER and Config.DATABASE_URL and (notifier_dict := await database.get_incomplete_tasks()): + for cid, data in notifier_dict.items(): + msg = ( + "Restarted Successfully!" if cid == chat_id else "Bot Restarted!" + ) + for tag, links in data.items(): + msg += f"\n\n{tag}: " + for index, link in enumerate(links, start=1): + msg += f" {index} |" + if len(msg.encode()) > 4000: + await send_incomplete_task_message(cid, msg_id, msg) + msg = "" + if msg: + await send_incomplete_task_message(cid, msg_id, msg) if await aiopath.isfile(".restartmsg"): with contextlib.suppress(Exception): diff --git a/bot/modules/stats.py b/bot/modules/stats.py index 0b9fd2b47..cb9b0f522 100644 --- a/bot/modules/stats.py +++ b/bot/modules/stats.py @@ -89,8 +89,7 @@ async def get_packages_version(): get_version_async(command, regex) for command, regex in commands.values() ] versions = await gather(*tasks) - for tool, version in zip(commands.keys(), versions, strict=False): - commands[tool] = version + commands.update({tool: version for tool, version in zip(commands.keys(), versions, strict=False)}) if await aiopath.exists(".git"): last_commit = await cmd_exec( "git log -1 --date=short --pretty=format:'%cd From %cr'", diff --git a/ruff.toml b/ruff.toml index a345ad871..8957f58ae 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,7 +1,7 @@ fix = true unsafe-fixes = true line-length = 85 -target-version = "py313" +target-version = "py312" [lint.mccabe] max-complexity = 100