Files
telegram-bot-for-manipulate…/app/handlers/registration.py
ronis_0505 5662d8877a
Some checks failed
continuous-integration/drone Build is failing
MVP
2025-07-27 22:17:28 +03:00

51 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from asyncio import Event
from aiogram import Router, Bot
from aiogram.filters import CommandStart
from aiogram.types import Message, User
from sqlalchemy import insert, select
from sqlalchemy.orm import selectinload
from keyboards import create_inline_kb
from database import async_session_, Worker
registration_router = Router()
registration_confirm: dict[int, Event] = {}
user_info_template = ("Новый пользователь ждет регистрации:\n"
"Имя: {}\n"
"Фамилия: {}\n"
"Юзернейм: @{}\n"
"ID: @msg_{}\n")
@registration_router.message(CommandStart())
async def registration_command(message: Message, bot: Bot):
admins_ids = os.getenv("BOT_ADMINS").split(",")
async with async_session_() as session:
async with session.begin():
result = await session.execute(select(Worker).where(Worker.telegram_id == message.from_user.id))
user = result.scalars().first()
if not user:
user = message.from_user
dict_for_inline = {f'reg @{user.id}': 'Allow', f'del @{user.id}': 'Reject'}
user_info = user_info_template.format(user.first_name, user.last_name if user.last_name else 'Не указана',
user.username if user.username else 'Не указан', user.id)
for admin in admins_ids:
await bot.send_message(chat_id=admin, text=user_info)
await bot.send_message(chat_id=admin, text='Зарегистрировать пользователя',
reply_markup=create_inline_kb(width=2, **dict_for_inline))
reg_confirm = Event()
registration_confirm[user.id] = reg_confirm
if await reg_confirm:
async with async_session_() as local_session:
async with local_session.begin():
local_session.add(Worker(telegram_id=int(user.id), name=user.first_name))
del registration_confirm[user.id]
else:
await message.answer("Работа бота возобновлена")