From 414bfefb21090b469154f3adea9137656e54b392 Mon Sep 17 00:00:00 2001 From: profitroll Date: Fri, 13 Jan 2023 14:45:23 +0100 Subject: [PATCH] Fixed tmp download function --- modules/commands/identify.py | 2 +- modules/utils.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/commands/identify.py b/modules/commands/identify.py index ad76a0b..83a450b 100644 --- a/modules/commands/identify.py +++ b/modules/commands/identify.py @@ -51,7 +51,7 @@ async def cmd_identify(app: Client, msg: Message): if user.photo is not None: await app.send_chat_action(msg.chat.id, action=ChatAction.UPLOAD_PHOTO) await msg.reply_photo( - create_tmp(await download_tmp(app, user.photo.big_file_id), kind="image"), + create_tmp((await download_tmp(app, user.photo.big_file_id))[1], kind="image"), quote=should_quote(msg), caption=output ) diff --git a/modules/utils.py b/modules/utils.py index 880d087..cad4af5 100644 --- a/modules/utils.py +++ b/modules/utils.py @@ -1,4 +1,4 @@ -from typing import Any, Literal, Union +from typing import Any, Literal, Tuple, Union from uuid import uuid1 from requests import get from pyrogram.enums.chat_type import ChatType @@ -212,7 +212,7 @@ def create_tmp(bytedata: Union[bytes, bytearray], kind: Union[Literal["image", " file.write(bytedata) return path.join("tmp", filename) -async def download_tmp(app: Client, file_id: str) -> bytes: +async def download_tmp(app: Client, file_id: str) -> Tuple[str, bytes]: """Download file by its ID and return its bytes ### Args: @@ -220,14 +220,14 @@ async def download_tmp(app: Client, file_id: str) -> bytes: * file_id (`str`): File's unique id ### Returns: - * `bytes`: Bytes of downloaded file + * `Tuple[str, bytes]`: First is a filepath and the second is file's bytes """ filename = str(uuid1()) makedirs("tmp", exist_ok=True) await app.download_media(file_id, path.join("tmp", filename)) with open(path.join("tmp", filename), "rb") as f: bytedata = f.read() - return bytedata + return path.join("tmp", filename), bytedata try: from psutil import Process