8 Commits
3 changed files with 53 additions and 7 deletions
+11
View File
@@ -1299,6 +1299,17 @@ async def init_db():
""") """)
logger.info("Added apple_id column to users (Pleily)") 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 # app_user_id_seq — sequence для отрицательных user_id
await conn.execute(""" await conn.execute("""
CREATE SEQUENCE IF NOT EXISTS app_user_id_seq CREATE SEQUENCE IF NOT EXISTS app_user_id_seq
+21 -6
View File
@@ -73,7 +73,7 @@ async def get_level(request: Request, level_number: int):
pool = await get_pool() pool = await get_pool()
async with pool.acquire() as conn: async with pool.acquire() as conn:
user = await conn.fetchrow( 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: if not user:
@@ -208,6 +208,7 @@ async def get_level(request: Request, level_number: int):
# 🆕 (10.10.2026): волна и позиция в волне. # 🆕 (10.10.2026): волна и позиция в волне.
"wave": wave, "wave": wave,
"position_in_wave": pos_in_wave, "position_in_wave": pos_in_wave,
"difficulty": user["difficulty"] or "medium",
} }
@@ -356,12 +357,14 @@ async def complete_level(request: Request):
async with pool.acquire() as conn: async with pool.acquire() as conn:
user = await conn.fetchrow( 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 telegram_id
) )
if not user: if not user:
raise HTTPException(401, "User not registered") raise HTTPException(401, "User not registered")
difficulty = user["difficulty"] or "medium"
level = await conn.fetchrow( level = await conn.fetchrow(
"SELECT id, level_number, grid_size, level FROM levels WHERE id = $1", level_id "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 за каждую подсказку # -20 за каждую подсказку
list_opened = bool(body.get("list_opened", False)) list_opened = bool(body.get("list_opened", False))
# Очки: база 100, −20 за каждую подсказку, −20 за список слов, # 🔧 НОВОЕ (13.10.2026): на Hard подсказки и список слов недоступны.
# +10 если без подсказок. if difficulty == "hard" and (hints_used > 0 or list_opened):
# Формула: max(20, min(110, 100 - 20*hints_used - 20*list_opened + bonus)) 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 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)) 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 через единую функцию # Начисляем XP через единую функцию
from services.xp import award_xp from services.xp import award_xp
+20
View File
@@ -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") @router.post("/set-level")
async def set_level(request: Request): async def set_level(request: Request):
"""Устанавливает текущий уровень пользователя (A1, A2, B1, B2, C1, C2)""" """Устанавливает текущий уровень пользователя (A1, A2, B1, B2, C1, C2)"""