video-stream/driver/chat_author.py

41 lines
1.0 KiB
Python
Raw Normal View History

2022-01-19 14:15:48 +00:00
""" chat utilities """
from functools import wraps
from driver.veez import bot
from config import SUDO_USERS
from pyrogram.types import Message
from program.admins import member_permissions
from pyrogram.errors.exceptions.forbidden_403 import ChatWriteForbidden
2022-01-19 14:23:20 +00:00
async def authorised(m: Message):
2022-01-19 14:15:48 +00:00
chatID = message.chat.id
return 0
2022-01-19 14:23:20 +00:00
async def unauthorised(m: Message):
chatID = m.chat.id
2022-01-19 14:15:48 +00:00
text = (
"You're missing admin rights to use this command."
+ f"\n\n» ❌ can_manage_voice_chats"
)
try:
2022-01-19 14:23:20 +00:00
await m.reply_text(text)
2022-01-19 14:15:48 +00:00
except ChatWriteForbidden:
await bot.leave_chat(chatID)
return 1
2022-01-19 14:23:20 +00:00
async def adminsOnly(permission, m: Message):
chatID = m.chat.id
if not m.from_user:
if m.sender_chat:
return await authorised(m)
return await unauthorised(m)
userID = m.from_user.id
2022-01-19 14:15:48 +00:00
permissions = await member_permissions(chatID, userID)
if userID not in SUDO_USERS and permission not in permissions:
2022-01-19 14:23:20 +00:00
return await unauthorised(m)
return await authorised(m)