53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
from aiogram import types
|
||
from aiogram.types.chat_permissions import ChatPermissions
|
||
|
||
from load import dp, bot, config
|
||
from keyboards.inline.keyboard import verify_button
|
||
from utils.timer import timer_manager, KickTimer
|
||
|
||
|
||
|
||
async def captcha_kick_user(message: types.Message, chat_id: int, user_id:int):
|
||
print("asdasdasd")
|
||
try:
|
||
await bot.ban_chat_member(chat_id=chat_id, user_id=user_id)
|
||
except Exception: pass
|
||
await bot.unban_chat_member(chat_id, user_id, only_if_banned=True)
|
||
await message.delete()
|
||
try:
|
||
await bot.send_message(user_id, "Время вышло!")
|
||
except Exception: pass
|
||
state = dp.current_state(chat=user_id, user=user_id)
|
||
await state.finish()
|
||
|
||
|
||
@dp.message_handler(is_chat=True, content_types=["new_chat_members"])
|
||
async def on_join(message: types.Message):
|
||
user_id = message.from_user.id
|
||
chat_id = message.chat.id
|
||
|
||
try:
|
||
await bot.restrict_chat_member(
|
||
chat_id=chat_id,
|
||
user_id=user_id,
|
||
permissions=ChatPermissions(can_send_messages=False)
|
||
)
|
||
except Exception: return
|
||
|
||
hello_message = (
|
||
"Привет, <a href='tg://user?id={user_id}'>{name}</a>! "
|
||
"Для того чтобы удостоверится что ты наш игрок, мы попросим пройти верификацию!\n"
|
||
"<b>У вас есть 2 минуты на прохождение верификации!</b>"
|
||
)
|
||
|
||
me = await bot.get_me()
|
||
captcha_message = await bot.send_message(
|
||
message.chat.id,
|
||
hello_message.format(user_id=user_id, name=message.from_user.first_name),
|
||
reply_markup=verify_button(message.from_user, me.username)
|
||
)
|
||
timer_manager.add_timer(user_id, captcha_message, KickTimer(int(config['Bot']['verify_timeout']), captcha_kick_user,
|
||
args=[captcha_message, chat_id, user_id]))
|
||
#Timer(int(config['Bot']['verify_timeout']), captcha_kick_user, args=[captcha_message, chat_id, user_id])
|
||
await message.delete()
|