From 13fcc8240df04a2089980862d84c386811c19142 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Wed, 14 Oct 2026 09:10:45 +0000 Subject: [PATCH 1/8] =?UTF-8?q?[Eva]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=203=20=D0=BA=D0=BE=D0=BB=D0=BE=D0=BD=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B2=20bubble=5Fwords=5Fprogress=20(current=5Flist?= =?UTF-8?q?=5Fopened,=20current=5Flevel=5Fwords,=20hinted=5Fwords)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/database.py b/database.py index 440708f..73d07d6 100644 --- a/database.py +++ b/database.py @@ -898,6 +898,46 @@ async def init_db(): """) logger.info("Added current_hints_used column to bubble_words_progress") + # 🔧 НОВОЕ (14.10.2026): current_list_opened — серверный счётчик + # «показать слова» для текущего уровня пузырей. Medium — 1 раз. + col_exists = await conn.fetchval(""" + SELECT 1 FROM information_schema.columns + WHERE table_name = 'bubble_words_progress' AND column_name = 'current_list_opened' + """) + if not col_exists: + await conn.execute(""" + ALTER TABLE bubble_words_progress + ADD COLUMN current_list_opened INT DEFAULT 0 + """) + logger.info("Added current_list_opened column to bubble_words_progress") + + # 🔧 НОВОЕ (14.10.2026): current_level_words — состояние текущего + # уровня пузырей (слова + части + переводы). Нужно для подсказок, + # т.к. уровень генерируется на лету в /next и нигде не хранится. + col_exists = await conn.fetchval(""" + SELECT 1 FROM information_schema.columns + WHERE table_name = 'bubble_words_progress' AND column_name = 'current_level_words' + """) + if not col_exists: + await conn.execute(""" + ALTER TABLE bubble_words_progress + ADD COLUMN current_level_words JSONB DEFAULT '[]'::jsonb + """) + logger.info("Added current_level_words column to bubble_words_progress") + + # 🔧 НОВОЕ (14.10.2026): hinted_words — какие слова уже получили + # подсказку «первая часть» (для «каждый раз разное слово»). + col_exists = await conn.fetchval(""" + SELECT 1 FROM information_schema.columns + WHERE table_name = 'bubble_words_progress' AND column_name = 'hinted_words' + """) + if not col_exists: + await conn.execute(""" + ALTER TABLE bubble_words_progress + ADD COLUMN hinted_words TEXT[] DEFAULT '{}' + """) + logger.info("Added hinted_words column to bubble_words_progress") + # ============ wrong_because_explanations ============ await conn.execute(""" CREATE TABLE IF NOT EXISTS wrong_because_explanations ( -- 2.54.0 From bd450711428aae01c7daeec3b1b23febf1c336c1 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Wed, 14 Oct 2026 09:13:29 +0000 Subject: [PATCH 2/8] =?UTF-8?q?[Eva]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20import=20json=20=D0=B2=20bubblewords.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/bubblewords.py | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/bubblewords.py b/routers/bubblewords.py index 00189a8..c2c4750 100644 --- a/routers/bubblewords.py +++ b/routers/bubblewords.py @@ -1,5 +1,6 @@ import random import hashlib # 🔧 НОВОЕ: импорт hashlib для стабильного хэширования +import json from fastapi import APIRouter, Request, HTTPException from auth import require_auth from database import get_pool -- 2.54.0 From 4355b942912577bb4982c2477a005f4f1752ffd8 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Wed, 14 Oct 2026 09:13:34 +0000 Subject: [PATCH 3/8] =?UTF-8?q?[Eva]=20/next=20=D1=81=D0=BE=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D1=8F=D0=B5=D1=82=20=D1=81=D0=BE=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=B5=20=D1=83=D1=80=D0=BE=D0=B2=D0=BD=D1=8F?= =?UTF-8?q?=20=D0=B8=20=D1=81=D0=B1=D1=80=D0=B0=D1=81=D1=8B=D0=B2=D0=B0?= =?UTF-8?q?=D0=B5=D1=82=20=D1=81=D1=87=D1=91=D1=82=D1=87=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/bubblewords.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/routers/bubblewords.py b/routers/bubblewords.py index c2c4750..5de2a28 100644 --- a/routers/bubblewords.py +++ b/routers/bubblewords.py @@ -163,6 +163,28 @@ async def get_next_bubble_level(request: Request): random.shuffle(all_parts) + # 🔧 НОВОЕ (14.10.2026): сохраняем состояние уровня для подсказок + # и сбрасываем счётчики подсказок/списка при новом уровне. + level_state = [ + { + "word_pl": w["word_pl"], + "translation": w["translation"], + "parts": w["parts"], + } + for w in result_words + ] + await conn.execute(""" + INSERT INTO bubble_words_progress + (user_id, levels_completed, total_score, level, + current_hints_used, current_list_opened, current_level_words, hinted_words) + VALUES ($1, 0, 0, $2, 0, 0, $3::jsonb, '{}') + ON CONFLICT (user_id) DO UPDATE + SET current_hints_used = 0, + current_list_opened = 0, + current_level_words = $3::jsonb, + hinted_words = '{}' + """, telegram_id, current_level, json.dumps(level_state)) + return { "words": result_words, "bubbles": all_parts, -- 2.54.0 From 959b9c4e3fe06f2598179c948ed82ff015a10d95 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Wed, 14 Oct 2026 09:16:37 +0000 Subject: [PATCH 4/8] =?UTF-8?q?[Eva]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20POST=20/bubblewords/first-part-hint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/bubblewords.py | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/routers/bubblewords.py b/routers/bubblewords.py index 5de2a28..fd7fa12 100644 --- a/routers/bubblewords.py +++ b/routers/bubblewords.py @@ -192,6 +192,76 @@ async def get_next_bubble_level(request: Request): } +@router.post("/first-part-hint") +async def first_part_hint(request: Request): + """Подсказка «первая часть слова» — возвращает первый пузырь одного из несобранных слов. + + 🔧 НОВОЕ (14.10.2026): аналог GET /hints/first-letter/{level_id} из филворда. + Лимит 3 подсказки, штраф −20 (учитывается в /complete через current_hints_used). + Hard — запрещено (400). + """ + telegram_id, _ = await require_auth(request) + body = await request.json() + found_words = set(body.get("found_words", []) or []) + + 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, "Hints are disabled on Hard difficulty") + + progress = await conn.fetchrow( + "SELECT current_hints_used, current_level_words, hinted_words " + "FROM bubble_words_progress WHERE user_id = $1", + telegram_id + ) + if not progress: + raise HTTPException(404, "No active level") + + hints_used = progress["current_hints_used"] or 0 + if hints_used >= 3: + raise HTTPException(400, "All hints used") + + level_words = progress["current_level_words"] or [] + hinted = set(progress["hinted_words"] or []) + + # Слова, которые ещё не собраны и которым ещё не давали подсказку + candidates = [ + w for w in level_words + if w.get("word_pl") not in found_words and w.get("word_pl") not in hinted + ] + + if not candidates: + raise HTTPException(400, "All words already hinted") + + chosen = random.choice(candidates) + word_pl = chosen["word_pl"] + parts = chosen.get("parts") or [] + first_part = parts[0] if parts else word_pl + + new_hints = hints_used + 1 + new_hinted = sorted(hinted | {word_pl}) + + await conn.execute(""" + UPDATE bubble_words_progress + SET current_hints_used = $2, + hinted_words = $3 + WHERE user_id = $1 + """, telegram_id, new_hints, new_hinted) + + return { + "word_pl": word_pl, + "first_part": first_part, + "hints_used_total": new_hints, + } + + @router.post("/complete") async def complete_bubble_level(request: Request): """Завершение уровня пузырей, начисление XP и проверка достижений. -- 2.54.0 From 16b8956b87d11d50da81b3246bd5647f12f08a34 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Wed, 14 Oct 2026 09:18:24 +0000 Subject: [PATCH 5/8] =?UTF-8?q?[Eva]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20POST=20/bubblewords/show-words?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/bubblewords.py | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) 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 и проверка достижений. -- 2.54.0 From 1f7ac86ef55e08618d945a25b20f6002bf23779e Mon Sep 17 00:00:00 2001 From: Drobysh Date: Wed, 14 Oct 2026 09:19:51 +0000 Subject: [PATCH 6/8] =?UTF-8?q?[Eva]=20bubblewords:=20=D1=83=D0=B1=D1=80?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20list=5Fopened=20=D0=B8=D0=B7=20body?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/bubblewords.py | 1 - 1 file changed, 1 deletion(-) diff --git a/routers/bubblewords.py b/routers/bubblewords.py index f9f849f..d8b9b90 100644 --- a/routers/bubblewords.py +++ b/routers/bubblewords.py @@ -332,7 +332,6 @@ async def complete_bubble_level(request: Request): body = await request.json() words_count = body.get("words_count", 3) completion_time = body.get("completion_time") - list_opened = bool(body.get("list_opened", False)) wrong_words = int(body.get("wrong_words", 0) or 0) pool = await get_pool() -- 2.54.0 From 07d2d197fdf485241a173fc4ecafea1718dabc42 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Wed, 14 Oct 2026 09:19:59 +0000 Subject: [PATCH 7/8] =?UTF-8?q?[Eva]=20bubblewords:=20=D1=87=D0=B8=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20=D1=81=D1=87=D1=91=D1=82=D1=87=D0=B8=D0=BA=D0=B8?= =?UTF-8?q?=20hints+list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/bubblewords.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/routers/bubblewords.py b/routers/bubblewords.py index d8b9b90..573d072 100644 --- a/routers/bubblewords.py +++ b/routers/bubblewords.py @@ -348,12 +348,15 @@ async def complete_bubble_level(request: Request): current_level = user["current_level"] or "A1" difficulty = user["difficulty"] or "medium" - # Читаем серверный hints_used - hints_used = await conn.fetchval( - "SELECT current_hints_used FROM bubble_words_progress WHERE user_id = $1", + # Читаем серверные счётчики (не из body) + progress = await conn.fetchrow( + "SELECT current_hints_used, current_list_opened " + "FROM bubble_words_progress WHERE user_id = $1", telegram_id - ) or 0 + ) + hints_used = (progress["current_hints_used"] if progress else 0) or 0 hints_used = min(max(0, hints_used), 3) + list_opened = (progress["current_list_opened"] if progress else 0) or 0 # 🔧 НОВОЕ (14.10.2026): очки по формуле филворда. # Hard — фикс 110. Easy/Medium — 100 − 20×hints − 20×list + bonus. -- 2.54.0 From 6399d3931c126b57cc02d97d5363ee5125c04eef Mon Sep 17 00:00:00 2001 From: Drobysh Date: Wed, 14 Oct 2026 09:20:09 +0000 Subject: [PATCH 8/8] =?UTF-8?q?[Eva]=20bubblewords:=20=D0=BE=D1=87=D0=B8?= =?UTF-8?q?=D1=81=D1=82=D0=BA=D0=B0=20=D1=81=D0=BE=D1=81=D1=82=D0=BE=D1=8F?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20+=20=D1=81=D0=B1=D1=80=D0=BE=D1=81=20?= =?UTF-8?q?=D1=81=D1=87=D1=91=D1=82=D1=87=D0=B8=D0=BA=D0=BE=D0=B2=20=D0=B2?= =?UTF-8?q?=20/complete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/bubblewords.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/routers/bubblewords.py b/routers/bubblewords.py index 573d072..cf55cc5 100644 --- a/routers/bubblewords.py +++ b/routers/bubblewords.py @@ -379,13 +379,18 @@ async def complete_bubble_level(request: Request): score = xp_result["points"] await conn.execute(""" - INSERT INTO bubble_words_progress (user_id, levels_completed, total_score, level, current_hints_used) - VALUES ($1, 1, $2, $3, 0) + INSERT INTO bubble_words_progress + (user_id, levels_completed, total_score, level, + current_hints_used, current_list_opened, current_level_words, hinted_words) + VALUES ($1, 1, $2, $3, 0, 0, '[]'::jsonb, '{}') ON CONFLICT (user_id) DO UPDATE SET levels_completed = bubble_words_progress.levels_completed + 1, total_score = bubble_words_progress.total_score + $2, level = $3, - current_hints_used = 0 + current_hints_used = 0, + current_list_opened = 0, + current_level_words = '[]'::jsonb, + hinted_words = '{}' """, telegram_id, score, current_level) # Данные для достижений -- 2.54.0