Compare commits

...

2 Commits

Author SHA1 Message Date
414bfefb21 Fixed tmp download function 2023-01-13 14:45:23 +01:00
fd5e0b5b22 Spoilers on custom filters 2023-01-13 10:43:27 +01:00
5 changed files with 13 additions and 6 deletions

View File

@@ -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
)

View File

@@ -10,7 +10,7 @@ from modules.database import col_spoilers
from modules import custom_filters
# Spoiler command ==============================================================================================================
@app.on_message(custom_filters.member & ~filters.scheduled & filters.private & filters.command(["spoiler"], prefixes=["/"]))
@app.on_message(custom_filters.enabled_spoilers & custom_filters.member & ~filters.scheduled & filters.private & filters.command(["spoiler"], prefixes=["/"]))
async def cmd_spoiler(app: Client, msg: Message):
try:

View File

@@ -39,6 +39,9 @@ async def enabled_invites_check_func(_, __, msg: Message):
async def enabled_dinovoice_func(_, __, msg: Message):
return configGet("enabled", "features", "dinovoice")
async def enabled_spoilers_func(_, __, msg: Message):
return configGet("enabled", "features", "spoilers")
async def filling_sponsorship_func(_, __, msg: Message):
return True if col_tmp.find_one({"user": msg.from_user.id, "type": "sponsorship"}) is not None else False
@@ -52,5 +55,6 @@ enabled_sponsorships = filters.create(enabled_sponsorships_func)
enabled_warnings = filters.create(enabled_warnings_func)
enabled_invites_check = filters.create(enabled_invites_check_func)
enabled_dinovoice = filters.create(enabled_dinovoice_func)
enabled_spoilers = filters.create(enabled_spoilers_func)
filling_sponsorship = filters.create(filling_sponsorship_func)

View File

@@ -66,6 +66,9 @@ async def any_stage(app: Client, msg: Message):
if holo_user.application_state()[0] != "fill" and holo_user.sponsorship_state()[0] != "fill":
if configGet("enabled", "features", "spoilers") is False:
return
spoiler = col_spoilers.find_one( {"user": msg.from_user.id, "completed": False} )
if spoiler is None:

View File

@@ -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