Fixed reg_confirm

admins_ids value type
This commit is contained in:
2025-07-28 23:47:17 +03:00
parent 1148d91598
commit 4748127399

View File

@@ -1,12 +1,11 @@
import os
from asyncio import Event
from asyncio import Event, wait_for, TimeoutError
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
@@ -20,10 +19,11 @@ user_info_template = ("Новый пользователь ждет регист
"Юзернейм: @{}\n"
"ID: @msg_{}\n")
admins_ids = list(map(int, os.getenv("BOT_ADMINS").split(",")))
@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))
@@ -31,20 +31,29 @@ async def registration_command(message: Message, bot: Bot):
if not user:
user = message.from_user
dict_for_inline = {f'reg @{user.id}': 'Allow', f'del @{user.id}': 'Reject'}
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))
try:
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))
except Exception as err:
pass
reg_confirm = Event()
registration_confirm[user.id] = reg_confirm
if await reg_confirm:
try:
await wait_for(reg_confirm.wait(), timeout=60)
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]
local_session.add(Worker(telegram_id=user.id, name=user.first_name))
await message.answer("Регистрация подтверждена")
except TimeoutError:
await message.answer("Время ожидания истекло.")
del registration_confirm[user.id]
else:
await message.answer("Работа бота возобновлена")