From 2f697c760c0cfd8c31b670af489baa5ea0fb7b51 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Mon, 1 Nov 2021 15:57:52 +0700 Subject: [PATCH] fixes error `NoneType` object --- program/admins.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/program/admins.py b/program/admins.py index 1b9c370..e83e8a2 100644 --- a/program/admins.py +++ b/program/admins.py @@ -1,4 +1,3 @@ -from typing import Callable from cache.admins import admins from driver.veez import call_py from pyrogram import Client, filters @@ -15,18 +14,6 @@ from pyrogram.types import ( ) -def admin_only(func: Callable) -> Callable: - async def decorator(client, cb): - author = admins.get(cb.message.chat.id) - if cb.from_user.id in author: - return await func(client, cb) - else: - await cb.answer("💡 only admin can tap this button !", show_alert=True) - return - - return decorator - - bttn = InlineKeyboardMarkup( [[InlineKeyboardButton("🔙 Go Back", callback_data="cbmenu")]] ) @@ -190,8 +177,10 @@ async def unmute(client, m: Message): @Client.on_callback_query(filters.regex("cbpause")) -@admin_only async def cbpause(_, query: CallbackQuery): + a = await _.get_chat_member(query.message.chat.id, query.from_user.id) + if not a.can_manage_voice_chats: + return await query.answer("💡 only admin can tap this button !") chat_id = query.message.chat.id if chat_id in QUEUE: try: @@ -206,8 +195,10 @@ async def cbpause(_, query: CallbackQuery): @Client.on_callback_query(filters.regex("cbresume")) -@admin_only async def cbresume(_, query: CallbackQuery): + a = await _.get_chat_member(query.message.chat.id, query.from_user.id) + if not a.can_manage_voice_chats: + return await query.answer("💡 only admin can tap this button !") chat_id = query.message.chat.id if chat_id in QUEUE: try: @@ -222,8 +213,10 @@ async def cbresume(_, query: CallbackQuery): @Client.on_callback_query(filters.regex("cbstop")) -@admin_only async def cbstop(_, query: CallbackQuery): + a = await _.get_chat_member(query.message.chat.id, query.from_user.id) + if not a.can_manage_voice_chats: + return await query.answer("💡 only admin can tap this button !") chat_id = query.message.chat.id if chat_id in QUEUE: try: @@ -237,8 +230,10 @@ async def cbstop(_, query: CallbackQuery): @Client.on_callback_query(filters.regex("cbmute")) -@admin_only async def cbmute(_, query: CallbackQuery): + a = await _.get_chat_member(query.message.chat.id, query.from_user.id) + if not a.can_manage_voice_chats: + return await query.answer("💡 only admin can tap this button !") chat_id = query.message.chat.id if chat_id in QUEUE: try: @@ -253,8 +248,10 @@ async def cbmute(_, query: CallbackQuery): @Client.on_callback_query(filters.regex("cbunmute")) -@admin_only async def cbunmute(_, query: CallbackQuery): + a = await _.get_chat_member(query.message.chat.id, query.from_user.id) + if not a.can_manage_voice_chats: + return await query.answer("💡 only admin can tap this button !") chat_id = query.message.chat.id if chat_id in QUEUE: try: