From 2b5ef446c1da7687c4f827b6c13e7c95396e8d85 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Tue, 13 Oct 2026 11:38:59 +0000 Subject: [PATCH 1/7] =?UTF-8?q?[Eva]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D1=8D=D0=BD=D0=B4=D0=BF=D0=BE=D0=B8=D0=BD?= =?UTF-8?q?=D1=82=20POST=20/users/set-difficulty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/users.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/routers/users.py b/routers/users.py index 2bcd524..744688b 100644 --- a/routers/users.py +++ b/routers/users.py @@ -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)""" -- 2.54.0 From f78a1fa19fe9bbc8613d176d5b916acc1130460f Mon Sep 17 00:00:00 2001 From: Drobysh Date: Tue, 13 Oct 2026 11:46:06 +0000 Subject: [PATCH 2/7] =?UTF-8?q?[Eva]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20users.difficulty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- database.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/database.py b/database.py index 1cb57d8..be06b58 100644 --- a/database.py +++ b/database.py @@ -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 -- 2.54.0 From 6f89336a0295245d919290caaefe1d9c9ec2383b Mon Sep 17 00:00:00 2001 From: Drobysh Date: Tue, 13 Oct 2026 11:51:33 +0000 Subject: [PATCH 3/7] =?UTF-8?q?[Eva]=20game.py:=20=D1=87=D0=B8=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=D0=BC=20difficulty=20=D0=B8=D0=B7=20users=20=D0=B2=20com?= =?UTF-8?q?plete-level?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/game.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routers/game.py b/routers/game.py index 399051c..5d42d00 100644 --- a/routers/game.py +++ b/routers/game.py @@ -356,11 +356,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 -- 2.54.0 From d181e43ee32b7656800fa54c8d4a835656f430f1 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Tue, 13 Oct 2026 11:51:41 +0000 Subject: [PATCH 4/7] =?UTF-8?q?[Eva]=20game.py:=20=D0=B2=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B4=D0=B0=D1=86=D0=B8=D1=8F=20hard-=D1=80=D0=B5=D0=B6=D0=B8?= =?UTF-8?q?=D0=BC=D0=B0=20=D0=B2=20complete-level?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/game.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/routers/game.py b/routers/game.py index 5d42d00..17cbfa0 100644 --- a/routers/game.py +++ b/routers/game.py @@ -422,6 +422,13 @@ async def complete_level(request: Request): # -20 за каждую подсказку list_opened = bool(body.get("list_opened", False)) + # 🔧 НОВОЕ (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" + ) + # Очки: база 100, −20 за каждую подсказку, −20 за список слов, # +10 если без подсказок. # Формула: max(20, min(110, 100 - 20*hints_used - 20*list_opened + bonus)) -- 2.54.0 From 959f789f246bbfa77e1ad5addaa34234f22f5a67 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Tue, 13 Oct 2026 11:51:50 +0000 Subject: [PATCH 5/7] =?UTF-8?q?[Eva]=20game.py:=20=D1=84=D0=BE=D1=80=D0=BC?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=20=D0=BE=D1=87=D0=BA=D0=BE=D0=B2=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/game.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/routers/game.py b/routers/game.py index 17cbfa0..25a48c7 100644 --- a/routers/game.py +++ b/routers/game.py @@ -429,11 +429,16 @@ async def complete_level(request: Request): detail="Hints and word list are disabled on Hard difficulty" ) - # Очки: база 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)) + # Очки в зависимости от сложности + 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 -- 2.54.0 From a6fe755fdbfef1f435916b11e543f49d4ff60763 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Tue, 13 Oct 2026 11:51:58 +0000 Subject: [PATCH 6/7] =?UTF-8?q?[Eva]=20game.py:=20difficulty=20=D0=B2=20SE?= =?UTF-8?q?LECT=20/game/level/{n}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/game.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/game.py b/routers/game.py index 25a48c7..e072c26 100644 --- a/routers/game.py +++ b/routers/game.py @@ -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: -- 2.54.0 From e3bc3e845648dc4691e9de65999f2ec82e1f3af4 Mon Sep 17 00:00:00 2001 From: Drobysh Date: Tue, 13 Oct 2026 11:52:04 +0000 Subject: [PATCH 7/7] =?UTF-8?q?[Eva]=20game.py:=20difficulty=20=D0=B2=20?= =?UTF-8?q?=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=B5=20/game/level/{n}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/game.py | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/game.py b/routers/game.py index e072c26..585ac2a 100644 --- a/routers/game.py +++ b/routers/game.py @@ -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", } -- 2.54.0