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__)
|
|
|
|
|
|
|
|
|
2023-08-12 23:36:55 +03:00
|
|
|
@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
|