diff --git a/src/trudex/application/bot/handlers.py b/src/trudex/application/bot/handlers.py index 663f378..9476abd 100644 --- a/src/trudex/application/bot/handlers.py +++ b/src/trudex/application/bot/handlers.py @@ -24,15 +24,12 @@ async def start_handler( ) -> None: assert message.from_user is not None - # Проверяем, существует ли пользователь existing_user = await user_dao.get_by_id(message.from_user.id) if existing_user is None: - # Новый пользователь - проверяем наличие групп groups = await group_dao.get_all() if len(groups) > 0: - # Есть группы - создаем пользователя без группы и имени, показываем регистрацию await user_dao.create( user_id=message.from_user.id, first_name=message.from_user.first_name, @@ -45,7 +42,6 @@ async def start_handler( data={"user_id": message.from_user.id} ) else: - # Нет групп - просто создаем пользователя await user_dao.create( user_id=message.from_user.id, first_name=message.from_user.first_name, @@ -54,28 +50,22 @@ async def start_handler( ) await dialog_manager.start(UserMenuSG.main, mode=StartMode.RESET_STACK) else: - # Существующий пользователь - # Проверяем, заполнил ли он имя и группу groups = await group_dao.get_all() if len(groups) > 0 and (existing_user.name is None or existing_user.group is None): - # Есть группы, но пользователь не завершил регистрацию if existing_user.name is None: - # Начинаем с ввода имени await dialog_manager.start( UserRegistrationSG.input_name, mode=StartMode.RESET_STACK, data={"user_id": message.from_user.id} ) else: - # Имя есть, но нет группы await dialog_manager.start( UserRegistrationSG.select_group, mode=StartMode.RESET_STACK, data={"user_id": message.from_user.id} ) else: - # Регистрация завершена или групп нет - обновляем данные и открываем меню await user_dao.upsert( user_id=message.from_user.id, first_name=message.from_user.first_name, @@ -87,18 +77,12 @@ async def start_handler( @router.message(Command("admin")) async def admin_command(message: Message, dialog_manager: DialogManager) -> None: - try: - await dialog_manager.start(AdminMenuSG.main, mode=StartMode.RESET_STACK) - except Exception as e: - await message.answer(f"Ошибка запуска диалога: {e}") + await dialog_manager.start(AdminMenuSG.main, mode=StartMode.RESET_STACK) @router.message(Command("creator")) async def creator_command(message: Message, dialog_manager: DialogManager) -> None: - try: - await dialog_manager.start(CreatorMenuSG.main, mode=StartMode.RESET_STACK) - except Exception as e: - await message.answer(f"Ошибка запуска диалога: {e}") + await dialog_manager.start(CreatorMenuSG.main, mode=StartMode.RESET_STACK) @router.error() diff --git a/src/trudex/application/bot/user_dialogs/take_test.py b/src/trudex/application/bot/user_dialogs/take_test.py index 6117ba5..a103687 100644 --- a/src/trudex/application/bot/user_dialogs/take_test.py +++ b/src/trudex/application/bot/user_dialogs/take_test.py @@ -170,7 +170,7 @@ async def get_question_data( progress = f"{current_index + 1}/{len(questions)}" return { - "question_text": f"Вопрос {progress}\n\n{question.text}", + "question_text": f"📝 Вопрос {progress}\n\n
{question.text}
", "options": [(opt.text, str(opt.id)) for opt in options], } @@ -320,7 +320,6 @@ async def on_next_question( elif answer_data["type"] == "multiple": selected_option_ids = set(answer_data["answer"]) - correct_option_ids = {opt.id for opt in options if opt.is_correct} selected_texts = sorted([opt.text for opt in options if opt.id in selected_option_ids]) correct_texts = sorted([opt.text for opt in options if opt.is_correct]) @@ -368,12 +367,15 @@ async def get_results_data(dialog_manager: DialogManager, **_kwargs): total_questions = dialog_manager.dialog_data.get("total_questions", 0) is_passed = dialog_manager.dialog_data.get("is_passed", False) - status = "✅ Тест пройден!" if is_passed else "❌ Тест не пройден" + if is_passed: + status = "✅ Тест пройден!" + else: + status = "❌ Тест не пройден" results_text = ( - f"{status}\n\n" - f"Результат: {score}%\n" - f"Правильных ответов: {correct_count}/{total_questions}" + f"{status}\n\n" + f"📊 Результат: {score}%\n" + f"✏️ Правильных ответов: {correct_count} из {total_questions}" ) return {"results_text": results_text} @@ -406,7 +408,7 @@ async def get_detailed_results_data( answers = await attempt_repo.get_answers_for_attempt(attempt_id) - lines = ["📋 Подробные результаты:\n"] + lines = ["📋 Подробные результаты\n"] for i, answer in enumerate(answers, 1): question, options = await test_repo.get_question_with_options(answer.question_id) @@ -422,11 +424,10 @@ async def get_detailed_results_data( if "|" in user_answer: user_answer = ", ".join(user_answer.split("|")) - question_text = question.text.split(" (Тест:")[0] if " (Тест:" in question.text else question.text - - lines.append(f"{status} Вопрос {i}: {question_text}") - lines.append(f"Ваш ответ: {user_answer or '—'}") - lines.append(f"Правильный ответ: {', '.join(correct_texts)}\n") + lines.append(f"{status} Вопрос {i}") + lines.append(f"
{question.text}
") + lines.append(f"👤 Ваш ответ: {user_answer or '—'}") + lines.append(f"✓ Правильно: {', '.join(correct_texts)}\n") return {"detailed_text": "\n".join(lines)}