This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Telegram/modules/callbacks/ban.py

39 lines
1.3 KiB
Python
Raw Permalink Normal View History

2023-04-02 19:42:11 +03:00
from datetime import datetime
2023-01-30 12:28:23 +02:00
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
2023-03-09 17:25:06 +02:00
2023-01-30 12:28:23 +02:00
@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])):
2023-04-02 19:42:11 +03:00
col_bans.insert_one(
{"user": int(fullclb[1]), "admin": clb.from_user.id, "date": datetime.now()}
)
2023-01-30 12:28:23 +02:00
2023-03-09 17:25:06 +02:00
edited_markup = [
[
InlineKeyboardButton(
text=str(locale("banned", "button")), callback_data="nothing"
)
]
]
2023-01-30 12:28:23 +02:00
2023-03-09 17:25:06 +02:00
await clb.message.edit(
text=clb.message.text, reply_markup=InlineKeyboardMarkup(edited_markup)
)
2023-01-30 12:28:23 +02:00
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:
2023-03-09 17:25:06 +02:00
logWrite(f"Could send ban message to {fullclb[1]} due to {exp}")