diff --git a/routers/bubblewords.py b/routers/bubblewords.py index fd7fa12..f9f849f 100644 --- a/routers/bubblewords.py +++ b/routers/bubblewords.py @@ -262,6 +262,61 @@ async def first_part_hint(request: Request): } +@router.post("/show-words") +async def show_words(request: Request): + """Подсказка «показать слова» — возвращает все загаданные слова с переводами. + + 🔧 НОВОЕ (14.10.2026): аналог show-words из филворда. + Easy — без лимита. Medium — 1 раз (−20). Hard — запрещено (400). + """ + telegram_id, _ = await require_auth(request) + + pool = await get_pool() + async with pool.acquire() as conn: + user = await conn.fetchrow( + "SELECT difficulty FROM users WHERE telegram_id = $1", telegram_id + ) + if not user: + raise HTTPException(401, "User not registered") + + difficulty = user["difficulty"] or "medium" + if difficulty == "hard": + raise HTTPException(400, "Word list is disabled on Hard difficulty") + + progress = await conn.fetchrow( + "SELECT current_list_opened, current_level_words " + "FROM bubble_words_progress WHERE user_id = $1", + telegram_id + ) + if not progress: + raise HTTPException(404, "No active level") + + list_opened = progress["current_list_opened"] or 0 + + # Medium — список можно открыть только 1 раз + if difficulty == "medium" and list_opened >= 1: + raise HTTPException(400, "Word list already used on Medium difficulty") + + level_words = progress["current_level_words"] or [] + words = [ + {"word_pl": w.get("word_pl"), "translation": w.get("translation")} + for w in level_words + ] + + # Инкремент счётчика для Easy и Medium (Hard сюда не доходит) + new_list_opened = list_opened + 1 + await conn.execute(""" + UPDATE bubble_words_progress + SET current_list_opened = $2 + WHERE user_id = $1 + """, telegram_id, new_list_opened) + + return { + "words": words, + "list_opened_total": new_list_opened, + } + + @router.post("/complete") async def complete_bubble_level(request: Request): """Завершение уровня пузырей, начисление XP и проверка достижений.