[Eva] Ева, патч 21 применён — теперь ты можешь #41
@@ -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 и проверка достижений.
|
||||
|
||||
Reference in New Issue
Block a user