diff --git a/database.py b/database.py index 73d07d6..1581f6b 100644 --- a/database.py +++ b/database.py @@ -938,6 +938,47 @@ async def init_db(): """) logger.info("Added hinted_words column to bubble_words_progress") + # 🔧 НОВОЕ (15.10.2026): words_collected — суммарно собранных слов + # в пузырях. Нужен для достижения bubble_words (собрать N слов). + col_exists = await conn.fetchval(""" + SELECT 1 FROM information_schema.columns + WHERE table_name = 'bubble_words_progress' AND column_name = 'words_collected' + """) + if not col_exists: + await conn.execute(""" + ALTER TABLE bubble_words_progress + ADD COLUMN words_collected INTEGER DEFAULT 0 + """) + logger.info("Added words_collected column to bubble_words_progress") + + # 🔧 НОВОЕ (15.10.2026): no_hints_streak — серия уровней БЕЗ подсказок + # и без «показать слова». +1 если hints_used == 0 и not list_opened, + # иначе сброс в 0. Нужен для достижения bubble_streak. + col_exists = await conn.fetchval(""" + SELECT 1 FROM information_schema.columns + WHERE table_name = 'bubble_words_progress' AND column_name = 'no_hints_streak' + """) + if not col_exists: + await conn.execute(""" + ALTER TABLE bubble_words_progress + ADD COLUMN no_hints_streak INTEGER DEFAULT 0 + """) + logger.info("Added no_hints_streak column to bubble_words_progress") + + # 🔧 НОВОЕ (15.10.2026): perfect_streak — серия идеальных уровней + # (без подсказок + без списка + без ошибок). +1 если всё чисто, + # иначе сброс в 0. Нужен для достижения bubble_perfect_streak. + col_exists = await conn.fetchval(""" + SELECT 1 FROM information_schema.columns + WHERE table_name = 'bubble_words_progress' AND column_name = 'perfect_streak' + """) + if not col_exists: + await conn.execute(""" + ALTER TABLE bubble_words_progress + ADD COLUMN perfect_streak INTEGER DEFAULT 0 + """) + logger.info("Added perfect_streak column to bubble_words_progress") + # ============ wrong_because_explanations ============ await conn.execute(""" CREATE TABLE IF NOT EXISTS wrong_because_explanations ( diff --git a/routers/achievements.py b/routers/achievements.py index 9ac5092..7f4aaf1 100644 --- a/routers/achievements.py +++ b/routers/achievements.py @@ -204,7 +204,7 @@ ACHIEVEMENTS_DATA = [ "desc_pl": "Odgadnij słowo bez żadnej pomyłki", "desc_ru": "Угадать слово без единой ошибки", "desc_uk": "Відгадати слово без жодної помилки", "desc_en": "Guess a word without any mistakes", "type": "quiz_no_mistakes", "value": 1}, - # ===== Bubble Words (8) ===== + # ===== Bubble Words (20) ===== {"code": "bubble_5", "category": "bubblewords", "icon": "🫧", "name_pl": "Początkujący", "name_ru": "Начинающий", "name_uk": "Початківець", "name_en": "Beginner", "desc_pl": "Ukończ 5 poziomów w Bąbelkach słów", "desc_ru": "Пройти 5 уровней в Пузырях слов", "desc_uk": "Пройти 5 рівнів у Бульбашках слів", "desc_en": "Complete 5 levels in Bubble Words", @@ -238,12 +238,72 @@ ACHIEVEMENTS_DATA = [ {"code": "bubble_speed", "category": "bubblewords", "icon": "🚀", "name_pl": "Szybki bańki", "name_ru": "Быстрые пузыри", "name_uk": "Швидкі бульбашки", "name_en": "Fast Bubbles", "desc_pl": "Ukończ poziom w mniej niż 45 sekund", "desc_ru": "Пройти уровень быстрее 45 секунд", "desc_uk": "Пройти рівень швидше 45 секунд", "desc_en": "Complete a level in under 45 seconds", - "type": "bubble_speed", "value": 45}, + "type": "bubble_speed_45", "value": 45}, {"code": "bubble_speed_30", "category": "bubblewords", "icon": "⚡", "name_pl": "Bąbelkowa błyskawica", "name_ru": "Пузырьковая молния", "name_uk": "Бульбашкова блискавка", "name_en": "Bubble Lightning", "desc_pl": "Ukończ poziom w mniej niż 30 sekund", "desc_ru": "Пройти уровень быстрее 30 секунд", "desc_uk": "Пройти рівень швидше 30 секунд", "desc_en": "Complete a level in under 30 seconds", - "type": "bubble_speed", "value": 30}, + "type": "bubble_speed_30", "value": 30}, + + {"code": "bubble_1", "category": "bubblewords", "icon": "🫧", + "name_pl": "Pierwszy bąbelek", "name_ru": "Первый пузырь", "name_uk": "Перша бульбашка", "name_en": "First Bubble", + "desc_pl": "Ukończ 1 poziom w Bąbelkach słów", "desc_ru": "Пройти 1 уровень в Пузырях слов", "desc_uk": "Пройти 1 рівень у Бульбашках слів", "desc_en": "Complete 1 level in Bubble Words", + "type": "bubble_levels", "value": 1}, + + {"code": "bubble_10", "category": "bubblewords", "icon": "🫧", + "name_pl": "Dziesięć bąbelków", "name_ru": "Десять пузырей", "name_uk": "Десять бульбашок", "name_en": "Ten Bubbles", + "desc_pl": "Ukończ 10 poziomów w Bąbelkach słów", "desc_ru": "Пройти 10 уровней в Пузырях слов", "desc_uk": "Пройти 10 рівнів у Бульбашках слів", "desc_en": "Complete 10 levels in Bubble Words", + "type": "bubble_levels", "value": 10}, + + {"code": "bubble_words_25", "category": "bubblewords", "icon": "📚", + "name_pl": "Kolekcjoner", "name_ru": "Собиратель", "name_uk": "Колекціонер", "name_en": "Collector", + "desc_pl": "Zbierz 25 słów", "desc_ru": "Собрать 25 слов", "desc_uk": "Зібрати 25 слів", "desc_en": "Collect 25 words", + "type": "bubble_words", "value": 25}, + + {"code": "bubble_no_mistakes", "category": "bubblewords", "icon": "✨", + "name_pl": "Bezbłędny", "name_ru": "Без ошибок", "name_uk": "Без помилок", "name_en": "No Mistakes", + "desc_pl": "Ukończ poziom bez żadnej pomyłki", "desc_ru": "Пройти уровень без единой ошибки", "desc_uk": "Пройти рівень без жодної помилки", "desc_en": "Complete a level without any mistakes", + "type": "bubble_no_mistakes", "value": 1}, + + {"code": "bubble_streak_3", "category": "bubblewords", "icon": "🔥", + "name_pl": "Seria", "name_ru": "Серия", "name_uk": "Серія", "name_en": "Streak", + "desc_pl": "Ukończ 3 poziomy z rzędu bez podpowiedzi", "desc_ru": "Пройти 3 уровня подряд без подсказок", "desc_uk": "Пройти 3 рівні поспіль без підказок", "desc_en": "Complete 3 levels in a row without hints", + "type": "bubble_streak", "value": 3}, + + {"code": "bubble_streak_10", "category": "bubblewords", "icon": "💪", + "name_pl": "Niepowstrzymany", "name_ru": "Неудержимый", "name_uk": "Невтримний", "name_en": "Unstoppable", + "desc_pl": "Ukończ 10 poziomów z rzędu bez podpowiedzi", "desc_ru": "Пройти 10 уровней подряд без подсказок", "desc_uk": "Пройти 10 рівнів поспіль без підказок", "desc_en": "Complete 10 levels in a row without hints", + "type": "bubble_streak", "value": 10}, + + {"code": "bubble_words_100", "category": "bubblewords", "icon": "📖", + "name_pl": "Sto słów", "name_ru": "Сто слов", "name_uk": "Сто слів", "name_en": "Hundred Words", + "desc_pl": "Zbierz 100 słów", "desc_ru": "Собрать 100 слов", "desc_uk": "Зібрати 100 слів", "desc_en": "Collect 100 words", + "type": "bubble_words", "value": 100}, + + {"code": "bubble_xp_1000", "category": "bubblewords", "icon": "💎", + "name_pl": "Bąbelkowy XP", "name_ru": "Пузырьковый XP", "name_uk": "Бульбашковий XP", "name_en": "Bubble XP", + "desc_pl": "Zdobądź 1000 XP w Bąbelkach", "desc_ru": "Набрать 1000 XP в пузырях", "desc_uk": "Набрати 1000 XP у бульбашках", "desc_en": "Earn 1000 XP in Bubbles", + "type": "bubble_xp", "value": 1000}, + + {"code": "bubble_200", "category": "bubblewords", "icon": "👑", + "name_pl": "Dwustu poziomów", "name_ru": "Двести уровней", "name_uk": "Двісті рівнів", "name_en": "Two Hundred Levels", + "desc_pl": "Ukończ 200 poziomów w Bąbelkach słów", "desc_ru": "Пройти 200 уровней в Пузырях слов", "desc_uk": "Пройти 200 рівнів у Бульбашках слів", "desc_en": "Complete 200 levels in Bubble Words", + "type": "bubble_levels", "value": 200}, + + {"code": "bubble_speed_15", "category": "bubblewords", "icon": "⚡", + "name_pl": "Błyskawica", "name_ru": "Молния", "name_uk": "Блискавка", "name_en": "Lightning", + "desc_pl": "Ukończ poziom w mniej niż 15 sekund", "desc_ru": "Пройти уровень быстрее 15 секунд", "desc_uk": "Пройти рівень швидше 15 секунд", "desc_en": "Complete a level in under 15 seconds", + "type": "bubble_speed_15", "value": 15}, + + {"code": "bubble_perfect_10", "category": "bubblewords", "icon": "🌟", + "name_pl": "Perfekcyjna seria", "name_ru": "Идеальная серия", "name_uk": "Ідеальна серія", "name_en": "Perfect Streak", + "desc_pl": "Ukończ 10 idealnych poziomów z rzędu", "desc_ru": "Пройти 10 идеальных уровней подряд", "desc_uk": "Пройти 10 ідеальних рівнів поспіль", "desc_en": "Complete 10 perfect levels in a row", + "type": "bubble_perfect_streak", "value": 10}, + + {"code": "bubble_words_500", "category": "bubblewords", "icon": "🏆", + "name_pl": "Pięćset słów", "name_ru": "Пятьсот слов", "name_uk": "П'ятсот слів", "name_en": "Five Hundred Words", + "desc_pl": "Zbierz 500 słów", "desc_ru": "Собрать 500 слов", "desc_uk": "Зібрати 500 слів", "desc_en": "Collect 500 words", + "type": "bubble_words", "value": 500}, # ===== General (9) ===== {"code": "score_1000", "category": "general", "icon": "🌟", diff --git a/routers/bubblewords.py b/routers/bubblewords.py index 7e4df66..a8d80f7 100644 --- a/routers/bubblewords.py +++ b/routers/bubblewords.py @@ -389,11 +389,16 @@ async def complete_bubble_level(request: Request): xp_result = await award_xp(conn, telegram_id, "bubbles", points) score = xp_result["points"] + # 🔧 НОВОЕ (15.10.2026): флаги для накопления серий. + no_hints_clean = 1 if (hints_used == 0 and not list_opened) else 0 + perfect_clean = 1 if (hints_used == 0 and not list_opened and wrong_words == 0) else 0 + 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, 1, $2, $3, 0, 0, '[]'::jsonb, '{}') + current_hints_used, current_list_opened, current_level_words, hinted_words, + words_collected, no_hints_streak, perfect_streak) + VALUES ($1, 1, $2, $3, 0, 0, '[]'::jsonb, '{}', $4, $5, $6) ON CONFLICT (user_id) DO UPDATE SET levels_completed = bubble_words_progress.levels_completed + 1, total_score = bubble_words_progress.total_score + $2, @@ -401,8 +406,23 @@ async def complete_bubble_level(request: Request): current_hints_used = 0, current_list_opened = 0, current_level_words = '[]'::jsonb, - hinted_words = '{}' - """, telegram_id, score, current_level) + hinted_words = '{}', + words_collected = COALESCE(bubble_words_progress.words_collected, 0) + $4, + no_hints_streak = CASE WHEN $5 = 1 + THEN COALESCE(bubble_words_progress.no_hints_streak, 0) + 1 ELSE 0 END, + perfect_streak = CASE WHEN $6 = 1 + THEN COALESCE(bubble_words_progress.perfect_streak, 0) + 1 ELSE 0 END + """, telegram_id, score, current_level, words_count, no_hints_clean, perfect_clean) + + # 🔧 НОВОЕ (15.10.2026): читаем актуальные счётчики для проверки достижений. + stats = await conn.fetchrow(""" + SELECT words_collected, no_hints_streak, perfect_streak, total_score + FROM bubble_words_progress WHERE user_id = $1 + """, telegram_id) + words_collected = stats["words_collected"] or 0 + no_hints_streak = stats["no_hints_streak"] or 0 + perfect_streak = stats["perfect_streak"] or 0 + bubble_total_score = stats["total_score"] or 0 # Данные для достижений total_levels = await conn.fetchval( @@ -419,10 +439,33 @@ async def complete_bubble_level(request: Request): if hints_used == 0 and not list_opened and wrong_words == 0: achievements_to_check.append(("bubble_perfect", 1)) if completion_time is not None and 0 < completion_time <= 45: - achievements_to_check.append(("bubble_speed", 45)) + achievements_to_check.append(("bubble_speed_45", 45)) if completion_time is not None and 0 < completion_time <= 30: achievements_to_check.append(("bubble_speed_30", 30)) + # 🔧 НОВОЕ (15.10.2026): триггеры новых достижений. + # bubble_words — всего слов собрано + achievements_to_check.append(("bubble_words", words_collected)) + + # bubble_no_mistakes — уровень без ошибок + if wrong_words == 0: + achievements_to_check.append(("bubble_no_mistakes", 1)) + + # bubble_streak — серия без подсказок (если > 0) + if no_hints_streak > 0: + achievements_to_check.append(("bubble_streak", no_hints_streak)) + + # bubble_xp — XP в пузырях (total_score — очки именно пузырей) + achievements_to_check.append(("bubble_xp", bubble_total_score)) + + # bubble_speed_15 — быстрее 15 сек + if completion_time is not None and 0 < completion_time <= 15: + achievements_to_check.append(("bubble_speed_15", 15)) + + # bubble_perfect_streak — серия идеальных (если > 0) + if perfect_streak > 0: + achievements_to_check.append(("bubble_perfect_streak", perfect_streak)) + # Достижения — вне транзакции from routers.achievements import check_and_award_achievements new_achievements = []