Fixed reg_confirm
admins_ids value type
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
from asyncio import Event
|
from asyncio import Event, wait_for, TimeoutError
|
||||||
|
|
||||||
from aiogram import Router, Bot
|
from aiogram import Router, Bot
|
||||||
from aiogram.filters import CommandStart
|
from aiogram.filters import CommandStart
|
||||||
from aiogram.types import Message, User
|
from aiogram.types import Message, User
|
||||||
|
|
||||||
from sqlalchemy import insert, select
|
from sqlalchemy import insert, select
|
||||||
from sqlalchemy.orm import selectinload
|
|
||||||
|
|
||||||
from keyboards import create_inline_kb
|
from keyboards import create_inline_kb
|
||||||
from database import async_session_, Worker
|
from database import async_session_, Worker
|
||||||
@@ -20,10 +19,11 @@ user_info_template = ("Новый пользователь ждет регист
|
|||||||
"Юзернейм: @{}\n"
|
"Юзернейм: @{}\n"
|
||||||
"ID: @msg_{}\n")
|
"ID: @msg_{}\n")
|
||||||
|
|
||||||
|
admins_ids = list(map(int, os.getenv("BOT_ADMINS").split(",")))
|
||||||
|
|
||||||
|
|
||||||
@registration_router.message(CommandStart())
|
@registration_router.message(CommandStart())
|
||||||
async def registration_command(message: Message, bot: Bot):
|
async def registration_command(message: Message, bot: Bot):
|
||||||
admins_ids = os.getenv("BOT_ADMINS").split(",")
|
|
||||||
async with async_session_() as session:
|
async with async_session_() as session:
|
||||||
async with session.begin():
|
async with session.begin():
|
||||||
result = await session.execute(select(Worker).where(Worker.telegram_id == message.from_user.id))
|
result = await session.execute(select(Worker).where(Worker.telegram_id == message.from_user.id))
|
||||||
@@ -31,19 +31,28 @@ async def registration_command(message: Message, bot: Bot):
|
|||||||
if not user:
|
if not user:
|
||||||
|
|
||||||
user = message.from_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_info = user_info_template.format(user.first_name, user.last_name if user.last_name else 'Не указана',
|
||||||
user.username if user.username else 'Не указан', user.id)
|
user.username if user.username else 'Не указан', user.id)
|
||||||
for admin in admins_ids:
|
for admin in admins_ids:
|
||||||
|
try:
|
||||||
await bot.send_message(chat_id=admin, text=user_info)
|
await bot.send_message(chat_id=admin, text=user_info)
|
||||||
await bot.send_message(chat_id=admin, text='Зарегистрировать пользователя',
|
await bot.send_message(chat_id=admin, text='Зарегистрировать пользователя',
|
||||||
reply_markup=create_inline_kb(width=2, **dict_for_inline))
|
reply_markup=create_inline_kb(width=2, **dict_for_inline))
|
||||||
|
except Exception as err:
|
||||||
|
pass
|
||||||
reg_confirm = Event()
|
reg_confirm = Event()
|
||||||
registration_confirm[user.id] = reg_confirm
|
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 async_session_() as local_session:
|
||||||
async with local_session.begin():
|
async with local_session.begin():
|
||||||
local_session.add(Worker(telegram_id=int(user.id), name=user.first_name))
|
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]
|
del registration_confirm[user.id]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user