Files
qwork/handlers/registration.py

81 lines
3.6 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.
from aiogram import Router, F
from aiogram.types import Message, CallbackQuery
from aiogram.fsm.context import FSMContext
from states import Registration
from keyboards import get_spheres_kb, get_skip_kb
from database import Database
router = Router()
db = Database("users.db")
@router.callback_query(F.data == "subscribe")
async def subscribe_handler(callback: CallbackQuery, state: FSMContext):
await db.add_user(callback.from_user.id)
await callback.message.edit_text(
"Отлично! Давай настроим профиль.\n<b>В какой сфере IT ты работаешь?</b>",
reply_markup=get_spheres_kb()
)
await state.set_state(Registration.waiting_for_sphere)
await callback.answer()
@router.callback_query(Registration.waiting_for_sphere)
async def sphere_chosen(callback: CallbackQuery, state: FSMContext):
sphere = callback.data.split("_")[1]
if sphere == "other":
await callback.message.edit_text("Напиши свою сферу деятельности:")
await state.set_state(Registration.waiting_for_custom_sphere)
else:
await state.update_data(sphere=sphere)
await callback.message.edit_text(f"Выбрано: <b>{sphere}</b>\n\nКакой основной стек технологий?")
await state.set_state(Registration.waiting_for_language)
await callback.answer()
@router.message(Registration.waiting_for_custom_sphere)
async def custom_sphere_input(message: Message, state: FSMContext):
await state.update_data(sphere=message.text)
await message.answer(f"Принято: <b>{message.text}</b>\n\nКакой основной стек?")
await state.set_state(Registration.waiting_for_language)
@router.message(Registration.waiting_for_language)
async def language_chosen(message: Message, state: FSMContext):
await state.update_data(language=message.text)
await message.answer(
"Принято! И последнее: напиши свои <b>предпочтения по заказам</b> (фильтры).\n"
"Например: 'чек от 5000р' или 'без правок'.\n\n"
"<i>Если не хочешь заполнять сейчас, нажми кнопку ниже.</i>",
reply_markup=get_skip_kb()
)
await state.set_state(Registration.waiting_for_preferences)
@router.callback_query(Registration.waiting_for_preferences, F.data == "skip_preferences")
async def skip_preferences(callback: CallbackQuery, state: FSMContext):
await state.update_data(preferences="Не указано")
data = await state.get_data()
await db.update_user_data(callback.from_user.id, data)
await callback.message.edit_text(
"✅ <b>Профиль успешно настроен!</b> (Фильтры пропущены)\n\n"
f"🌐 Сфера: {data['sphere']}\n"
f"🛠 Стек: {data['language']}\n"
f"⚙️ Фильтры: {data['preferences']}"
)
await state.clear()
await callback.answer()
@router.message(Registration.waiting_for_preferences)
async def preferences_input(message: Message, state: FSMContext):
await state.update_data(preferences=message.text)
data = await state.get_data()
# Сохраняем в базу данных
await db.update_user_data(message.from_user.id, data)
await message.answer(
"✅ <b>Профиль успешно настроен!</b>\n\n"
f"🌐 Сфера: {data['sphere']}\n"
f"🛠 Стек: {data['language']}\n"
f"⚙️ Фильтры: {data['preferences']}"
)
await state.clear()