This commit is contained in:
2026-01-03 22:59:38 +03:00
parent a82fb437d5
commit d5130d61c9
2 changed files with 15 additions and 30 deletions
-16
View File
@@ -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}")
@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}")
@router.error()
@@ -170,7 +170,7 @@ async def get_question_data(
progress = f"{current_index + 1}/{len(questions)}"
return {
"question_text": f"<b>Вопрос {progress}</b>\n\n{question.text}",
"question_text": f"<b>📝 Вопрос {progress}</b>\n\n<blockquote>{question.text}</blockquote>",
"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 = "✅ <b>Тест пройден!</b>"
else:
status = "❌ <b>Тест не пройден</b>"
results_text = (
f"<b>{status}</b>\n\n"
f"<b>Результат:</b> {score}%\n"
f"<b>Правильных ответов:</b> {correct_count}/{total_questions}"
f"{status}\n\n"
f"📊 <b>Результат:</b> {score}%\n"
f"✏️ <b>Правильных ответов:</b> {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 = ["<b>📋 Подробные результаты:</b>\n"]
lines = ["<b>📋 Подробные результаты</b>\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"<b>{status} Вопрос {i}:</b> {question_text}")
lines.append(f"<b>Ваш ответ:</b> {user_answer or ''}")
lines.append(f"<b>Правильный ответ:</b> {', '.join(correct_texts)}\n")
lines.append(f"{status} <b>Вопрос {i}</b>")
lines.append(f"<blockquote>{question.text}</blockquote>")
lines.append(f"👤 <i>Ваш ответ:</i> {user_answer or ''}")
lines.append(f"✓ <i>Правильно:</i> {', '.join(correct_texts)}\n")
return {"detailed_text": "\n".join(lines)}