From 67d505f4f2477aaf674455309f2933ff5d1ca66c Mon Sep 17 00:00:00 2001 From: Nyan404 Date: Sat, 10 Oct 2026 22:01:05 +0300 Subject: [PATCH] feat: add clickable points activity menu --- MEMORY.md | 2 ++ app/belki/vk_bot.py | 14 +++++++++++--- structure_and_data.md | 1 + tests/test_vk_bot.py | 19 +++++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/MEMORY.md b/MEMORY.md index 8441b3e..8262adb 100644 --- a/MEMORY.md +++ b/MEMORY.md @@ -1,5 +1,7 @@ # MEMORY +- 2026-10-10: VK points calculator activity selection has a clickable keyboard (`points:coaching`, `points:training`, `points:inspection`) and accepts both `прокачка`/`прокачку` and `тренировка`/`тренировку`. + - 2026-10-10 live: manually deployed VK Callback API migration from the local checkout. Belki image `reg.nyan404.ru/cwshed-clone/belki:df5dd4e` has digest `sha256:bd0abf5ef86565534e9455a628c276fe49a39eca28c0581d581ea2c5a4b0dcf1`; gateway `reg.nyan404.ru/cwshed:df5dd4e` has digest `sha256:b274cfd43710fa7def9048601ad4de3da0895e2744e230cb0348f19b347a6eaa`. Callback secret and confirmation were read from ignored `.secrets/VK_CALLBACK_*` files and applied only to the cluster Secret. Callback confirmation returned HTTP 200 both on `belki-bot:8081` and through cwshed `/api/vk/callback` via port-forward. - 2026-09-01: `docs/Новая Крыланы. [Памятка].md` is the searchable Markdown wiki version of the supplied Krylan memo. It is a convenience index rather than rule authority: resolve drift against the Krylan blog, current leadership announcements, and inter-faction agreement. diff --git a/app/belki/vk_bot.py b/app/belki/vk_bot.py index 8d1b861..5b9b32f 100644 --- a/app/belki/vk_bot.py +++ b/app/belki/vk_bot.py @@ -956,6 +956,7 @@ class BelkiBot: return { "menu:lu": "/лу", "menu:zu": "/зу", "menu:training": "/урок", "menu:inspection": "/осмотр", "menu:goal": "/цель", "menu:help": "/help", "menu:cancel": "/отмена", "menu:application": "/заявка", + "points:coaching": "прокачка", "points:training": "тренировка", "points:inspection": "осмотр", "application:feathers": "/перо", "application:kitten": "/бельчонок", "application:flying": "/летяга", "application:curator": "/куратор", "application:skip-vk": "нет", "application:practice-yes": "да", "application:practice-no": "нет", @@ -1188,6 +1189,13 @@ class BelkiDialog: [self._button("Отмена", "menu:cancel", "negative")]], } return {"one_time": False, "buttons": [[self._button("Отмена", "menu:cancel", "negative")]]} + if state and state.get("mode") == "points_choice": + return {"one_time": True, "buttons": [ + [self._button("Прокачка", "points:coaching", "primary")], + [self._button("Тренировка", "points:training", "secondary")], + [self._button("Осмотр", "points:inspection", "secondary")], + [self._button("Отмена", "menu:cancel", "negative")], + ]} if state and state.get("mode") == "inspection": next_key = next((key for key, _ in self._ORDERS["inspection"] if not self._has_field(state, key)), None) if next_key == "place": @@ -1475,12 +1483,12 @@ class BelkiDialog: """ key = next((key for key, _ in self._ORDERS[state["mode"]] if not self._has_field(state, key)), None) if state["mode"] == "points_choice" and key == "activity": - activity = text.lower() - if activity in ("прокачка", "лу", "зу"): + activity = text.strip().lower() + if activity in ("прокачка", "прокачку", "лу", "зу"): state["mode"] = "points_coaching" if activity in ("лу", "зу"): state["skill"] = activity.upper() - elif activity in ("тренировка", "урок"): + elif activity in ("тренировка", "тренировку", "урок"): state["mode"] = "points_training" elif activity in ("осмотр", "осмотры"): state["mode"] = "points_inspection" diff --git a/structure_and_data.md b/structure_and_data.md index 3b6dfd6..43a1d95 100644 --- a/structure_and_data.md +++ b/structure_and_data.md @@ -20,6 +20,7 @@ - [`CONTRIBUTING.md`](./CONTRIBUTING.md): contribution and verification rules. ## Runtime / Deployment +- 2026-10-10: the VK points calculator now shows clickable `Прокачка`, `Тренировка`, and `Осмотр` buttons at the activity prompt. Text input accepts both nominative and accusative forms (`прокачка`/`прокачку`, `тренировка`/`тренировку`). - 2026-10-10: performed a manual production rollout from the local checkout. The amd64 images `reg.nyan404.ru/cwshed-clone/belki:df5dd4e` (digest `sha256:bd0abf5ef86565534e9455a628c276fe49a39eca28c0581d581ea2c5a4b0dcf1`) and `reg.nyan404.ru/cwshed:df5dd4e` (digest `sha256:b274cfd43710fa7def9048601ad4de3da0895e2744e230cb0348f19b347a6eaa`) were built on `root@10.3.1.168` and applied to namespace `belki`. `VK_CALLBACK_SECRET` and `VK_CALLBACK_CONFIRMATION` came from ignored `.secrets/` files and were applied to `Secret/belki-runtime`; their values are not stored here. Direct callback and the cwshed `/api/vk/callback` proxy both returned HTTP 200 for the confirmation payload through an admin port-forward. The old bot ReplicaSet pod was still terminating during the final snapshot; the new pod was Running with zero restarts. - 2026-10-08: hardened `belki-bot` VK Long Poll against transient `OSError`/SSL/timeout failures. The poll loop logs the failure, waits, obtains a fresh `groups.getLongPollServer` lease, and continues without exiting the process. - 2026-10-08: `BelkiDialog` now persists unfinished per-actor state and queued VK photos in `vk_dialog_states` through the existing `BELKI_DATABASE_URL`/`BELKI_HISTORY_DB` store. State is written after each text/photo event and restored lazily after a bot restart; completed/cancelled dialogs are deleted. diff --git a/tests/test_vk_bot.py b/tests/test_vk_bot.py index a3f9d44..d6418b2 100644 --- a/tests/test_vk_bot.py +++ b/tests/test_vk_bot.py @@ -144,11 +144,30 @@ class VkBotTests(unittest.TestCase): def test_button_payload_maps_to_command(self): self.assertEqual(BelkiBot._button_text({"payload": "menu:lu"}), "/лу") + self.assertEqual(BelkiBot._button_text({"payload": '{"command":"points:coaching"}'}), "прокачка") + self.assertEqual(BelkiBot._button_text({"payload": '{"command":"points:training"}'}), "тренировка") + self.assertEqual(BelkiBot._button_text({"payload": '{"command":"points:inspection"}'}), "осмотр") self.assertEqual(BelkiBot._button_text({"payload": '{"command":"confirm:yes"}'}), "да") self.assertEqual(BelkiBot._button_text({"payload": '{"command":"quick:inscription"}'}), "+1 надпись") self.assertEqual(BelkiBot._button_text({"payload": '{"command":"application:flying"}'}), "/летяга") self.assertEqual(BelkiBot._button_text({"payload": '{"command":"application:practice-no"}'}), "нет") + def test_points_choice_has_clickable_activity_menu_and_accepts_cases(self): + dialog = BelkiDialog() + dialog.handle(901, "/цель") + keyboard = dialog.keyboard_for(901) + payloads = [ + json.loads(button["action"]["payload"])["command"] + for row in keyboard["buttons"] for button in row + ] + self.assertEqual(payloads[:3], ["points:coaching", "points:training", "points:inspection"]) + + for activity in ("прокачка", "прокачку", "тренировка", "тренировку"): + current = BelkiDialog() + current.handle(902, "/цель") + response = current.handle(902, activity) + self.assertNotIn("Выберите: прокачка, тренировка или осмотр.", response) + def test_keyboard_button_payloads_are_valid_json(self): keyboard = BelkiDialog().keyboard_for(503) for row in keyboard["buttons"]: