This commit is contained in:
2022-03-18 21:25:50 +02:00
commit 2baff4118e
28 changed files with 573 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
from . import main
from . import users
from . import captcha

52
handlers/group/captcha.py Normal file
View File

@@ -0,0 +1,52 @@
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()

12
handlers/group/main.py Normal file
View File

@@ -0,0 +1,12 @@
from aiogram import types
from load import dp, bot, config
from database.worker import delete
@dp.message_handler(is_chat=True, content_types=['left_chat_member'])
async def on_left(message: types.Message):
user_id = message.from_user.id
delete(user_id)
await message.delete()

18
handlers/group/users.py Normal file
View File

@@ -0,0 +1,18 @@
from aiogram import types
from load import bot, dp
from database.worker import get_users
@dp.message_handler(is_chat=True, commands=['get'])
async def get_users_info(message: types.Message):
text = ''
users = get_users()
if users is not None:
for p in users:
text += ("<a href='tg://user?id={user_id}'>{first_name}</a> ({nickname} <code>{tag}</code>)\n").format(
user_id=p['user_id'], first_name=p['first_name'], nickname=p['nickname'], tag=p['tag']
)
await bot.send_message(message.chat.id, text)
else:
await bot.send_message(message.chat.id, "Ничего не найдено!")