Fixed tmp download function
This commit is contained in:
parent
fd5e0b5b22
commit
414bfefb21
@ -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
|
||||
)
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user