This repository has been archived on 2024-08-21. You can view files and clone it, but cannot push or open issues or pull requests.
EmojiCaptchaBot/plugins/callbacks/ban.py
2023-08-10 13:05:40 +02:00

44 lines
1.2 KiB
Python

import logging
from pyrogram import filters
from pyrogram.enums.chat_member_status import ChatMemberStatus
from pyrogram.types import CallbackQuery, Message
from classes.pyroclient import PyroClient
logger = logging.getLogger(__name__)
@PyroClient.on_callback_query(filters.regex(r"ban;[\s\S]*"))
async def callback_ban(app: PyroClient, callback: CallbackQuery):
if (
await app.get_chat_member(callback.message.chat.id, callback.from_user.id)
).status not in [ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER]:
await callback.answer(app._("wrong_user", "callbacks"), show_alert=True)
return
user = await app.find_user(
int(str(callback.data).split(";")[1]), callback.message.chat.id
)
logger.info(
"User %s has been marked as failed the captcha by %s",
user.id,
callback.from_user.id,
)
user.set_mistakes(3)
user.set_failed(True)
await callback.answer(
app._("captcha_failed_force", "callbacks").format(user_id=user.id),
show_alert=True,
)
banned = await app.ban_chat_member(callback.message.chat.id, user.id)
if isinstance(banned, Message):
await banned.delete()
await callback.message.delete()
return