Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26442db954 | ||
|
|
e3bc3e8456 | ||
|
|
a6fe755fdb | ||
|
|
959f789f24 | ||
|
|
d181e43ee3 | ||
|
|
6f89336a02 | ||
|
|
f78a1fa19f | ||
|
|
2b5ef446c1 |
+11
@@ -1299,6 +1299,17 @@ async def init_db():
|
||||
""")
|
||||
logger.info("Added apple_id column to users (Pleily)")
|
||||
|
||||
# difficulty
|
||||
col_exists = await conn.fetchval("""
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'users' AND column_name = 'difficulty'
|
||||
""")
|
||||
if not col_exists:
|
||||
await conn.execute("""
|
||||
ALTER TABLE users ADD COLUMN difficulty TEXT DEFAULT 'medium'
|
||||
""")
|
||||
logger.info("Added difficulty column to users (Pleily)")
|
||||
|
||||
# app_user_id_seq — sequence для отрицательных user_id
|
||||
await conn.execute("""
|
||||
CREATE SEQUENCE IF NOT EXISTS app_user_id_seq
|
||||
|
||||
+22
-7
@@ -73,7 +73,7 @@ async def get_level(request: Request, level_number: int):
|
||||
pool = await get_pool()
|
||||
async with pool.acquire() as conn:
|
||||
user = await conn.fetchrow(
|
||||
"SELECT app_language, current_level, last_completed_level, last_completed_by_level FROM users WHERE telegram_id = $1", telegram_id
|
||||
"SELECT app_language, current_level, last_completed_level, last_completed_by_level, difficulty FROM users WHERE telegram_id = $1", telegram_id
|
||||
)
|
||||
|
||||
if not user:
|
||||
@@ -208,6 +208,7 @@ async def get_level(request: Request, level_number: int):
|
||||
# 🆕 (10.10.2026): волна и позиция в волне.
|
||||
"wave": wave,
|
||||
"position_in_wave": pos_in_wave,
|
||||
"difficulty": user["difficulty"] or "medium",
|
||||
}
|
||||
|
||||
|
||||
@@ -356,11 +357,13 @@ async def complete_level(request: Request):
|
||||
|
||||
async with pool.acquire() as conn:
|
||||
user = await conn.fetchrow(
|
||||
"SELECT id, telegram_id, last_completed_level, current_level FROM users WHERE telegram_id = $1",
|
||||
"SELECT id, telegram_id, last_completed_level, current_level, difficulty FROM users WHERE telegram_id = $1",
|
||||
telegram_id
|
||||
)
|
||||
if not user:
|
||||
raise HTTPException(401, "User not registered")
|
||||
|
||||
difficulty = user["difficulty"] or "medium"
|
||||
|
||||
level = await conn.fetchrow(
|
||||
"SELECT id, level_number, grid_size, level FROM levels WHERE id = $1", level_id
|
||||
@@ -420,11 +423,23 @@ async def complete_level(request: Request):
|
||||
# -20 за каждую подсказку
|
||||
list_opened = bool(body.get("list_opened", False))
|
||||
|
||||
# Очки: база 100, −20 за каждую подсказку, −20 за список слов,
|
||||
# +10 если без подсказок.
|
||||
# Формула: max(20, min(110, 100 - 20*hints_used - 20*list_opened + bonus))
|
||||
bonus = 10 if hints_used == 0 else 0
|
||||
points = max(20, min(110, 100 - 20 * hints_used - 20 * (1 if list_opened else 0) + bonus))
|
||||
# 🔧 НОВОЕ (13.10.2026): на Hard подсказки и список слов недоступны.
|
||||
if difficulty == "hard" and (hints_used > 0 or list_opened):
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Hints and word list are disabled on Hard difficulty"
|
||||
)
|
||||
|
||||
# Очки в зависимости от сложности
|
||||
if difficulty == "hard":
|
||||
# Hard: фикс 110 (без подсказок и списка)
|
||||
points = 110
|
||||
else:
|
||||
# Easy / Medium
|
||||
bonus = 10 if hints_used == 0 else 0
|
||||
penalty_hints = 20 * hints_used
|
||||
penalty_list = 0 if difficulty == "easy" else 20 * (1 if list_opened else 0)
|
||||
points = max(20, min(110, 100 - penalty_hints - penalty_list + bonus))
|
||||
|
||||
# Начисляем XP через единую функцию
|
||||
from services.xp import award_xp
|
||||
|
||||
@@ -76,6 +76,26 @@ async def set_language(request: Request):
|
||||
}
|
||||
|
||||
|
||||
@router.post("/set-difficulty")
|
||||
async def set_difficulty(request: Request):
|
||||
"""Устанавливает уровень сложности (easy/medium/hard)."""
|
||||
user_id, _ = await require_auth(request)
|
||||
body = await request.json()
|
||||
difficulty = body.get("difficulty", "medium")
|
||||
|
||||
if difficulty not in {"easy", "medium", "hard"}:
|
||||
raise HTTPException(400, "Unsupported difficulty")
|
||||
|
||||
pool = await get_pool()
|
||||
async with pool.acquire() as conn:
|
||||
await conn.execute(
|
||||
"UPDATE users SET difficulty = $1 WHERE telegram_id = $2",
|
||||
difficulty, user_id,
|
||||
)
|
||||
|
||||
return {"status": "ok", "difficulty": difficulty}
|
||||
|
||||
|
||||
@router.post("/set-level")
|
||||
async def set_level(request: Request):
|
||||
"""Устанавливает текущий уровень пользователя (A1, A2, B1, B2, C1, C2)"""
|
||||
|
||||
Reference in New Issue
Block a user