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

50 lines
1.3 KiB
Python
Raw Permalink Normal View History

2023-08-10 14:05:40 +03:00
import logging
from pyrogram import filters
from pyrogram.types import CallbackQuery, Message
2023-08-11 16:04:21 +03:00
from classes.callbacks import CallbackBan
2023-08-10 14:05:40 +03:00
from classes.pyroclient import PyroClient
2023-08-23 12:12:26 +03:00
from modules.utils import is_permitted
2023-08-10 14:05:40 +03:00
logger = logging.getLogger(__name__)
@PyroClient.on_callback_query(filters.regex(r"ban:[\s\S]*")) # type: ignore
2023-08-10 14:05:40 +03:00
async def callback_ban(app: PyroClient, callback: CallbackQuery):
2023-08-17 17:37:42 +03:00
group = await app.find_group(callback.message.chat.id)
2023-08-11 16:04:21 +03:00
locale = group.select_locale(app, callback.message.from_user)
2023-08-23 12:12:26 +03:00
if not (await is_permitted(app, group, callback=callback)):
2023-08-11 16:04:21 +03:00
await callback.answer(
app._("wrong_user", "callbacks", locale=locale), show_alert=True
)
2023-08-10 14:05:40 +03:00
return
2023-08-11 16:04:21 +03:00
parsed = CallbackBan.from_callback(callback)
user = await app.find_user(parsed.user_id, group.id)
2023-08-10 14:05:40 +03:00
logger.info(
"User %s has been marked as failed the captcha by %s",
user.id,
callback.from_user.id,
)
2023-08-11 16:04:21 +03:00
await user.set_mistakes(3)
await user.set_failed(True)
2023-08-10 14:05:40 +03:00
await callback.answer(
2023-08-11 16:04:21 +03:00
app._("captcha_failed_force", "callbacks", locale=locale).format(
user_id=user.id
),
2023-08-10 14:05:40 +03:00
show_alert=True,
)
2023-08-11 16:04:21 +03:00
banned = await app.ban_chat_member(group.id, user.id)
2023-08-10 14:05:40 +03:00
if isinstance(banned, Message):
await banned.delete()
await callback.message.delete()
return