from app import app, isAnAdmin
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery
from pyrogram import filters
from pyrogram.client import Client
from modules.utils import locale
from modules.database import col_bans
from modules.logging import logWrite
@app.on_callback_query(filters.regex("ban_[\s\S]*"))
async def callback_query_reject(app: Client, clb: CallbackQuery):
fullclb = clb.data.split("_")
if not await isAnAdmin(int(fullclb[1])):
col_bans.insert_one({"user": int(fullclb[1])})
edited_markup = [
[
InlineKeyboardButton(
text=str(locale("banned", "button")), callback_data="nothing"
)
]
await clb.message.edit(
text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup)
await clb.answer(text=locale("sub_banned", "callback", locale=clb.from_user))
logWrite(f"User {fullclb[1]} has been banned by {clb.from_user.id}")
try:
await app.send_message(int(fullclb[1]), locale("you_are_banned", "message"))
except Exception as exp:
logWrite(f"Could send ban message to {fullclb[1]} due to {exp}")