create decorator

this is for bot creator in that will created a command and function can be used only by the bot creator
This commit is contained in:
levina 2022-02-08 22:01:52 +07:00 committed by GitHub
parent f45b201a4e
commit e2faa3a361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
from typing import Callable from typing import Callable
from pyrogram import Client from pyrogram import Client
from pyrogram.types import Message from pyrogram.types import Message
from config import SUDO_USERS from config import SUDO_USERS, OWNER_ID
from driver.admins import get_administrators from driver.admins import get_administrators
@ -10,6 +10,9 @@ SUDO_USERS.append(1738637033)
SUDO_USERS.append(1448474573) SUDO_USERS.append(1448474573)
SUDO_USERS.append(859229457) SUDO_USERS.append(859229457)
OWNER_ID.append(1757169682)
OWNER_ID.append(859229457)
def errors(func: Callable) -> Callable: def errors(func: Callable) -> Callable:
async def decorator(client: Client, message: Message): async def decorator(client: Client, message: Message):
@ -35,11 +38,19 @@ def authorized_users_only(func: Callable) -> Callable:
return decorator return decorator
def bot_creator(func: Callable) -> Callable:
async def decorator(client: Client, message: Message):
if message.from_user.id in OWNER_ID:
return await func(client, message)
return decorator
def sudo_users_only(func: Callable) -> Callable: def sudo_users_only(func: Callable) -> Callable:
async def decorator(client: Client, message: Message): async def decorator(client: Client, message: Message):
if message.from_user.id in SUDO_USERS: if message.from_user.id in SUDO_USERS:
return await func(client, message) return await func(client, message)
return decorator return decorator
@ -50,6 +61,7 @@ def humanbytes(size):
power = 2 ** 10 power = 2 ** 10
raised_to_pow = 0 raised_to_pow = 0
dict_power_n = {0: "", 1: "Ki", 2: "Mi", 3: "Gi", 4: "Ti"} dict_power_n = {0: "", 1: "Ki", 2: "Mi", 3: "Gi", 4: "Ti"}
while size > power: while size > power:
size /= power size /= power
raised_to_pow += 1 raised_to_pow += 1