From 6db39f0d5178eb2c49bee6e43efe580b176a3a54 Mon Sep 17 00:00:00 2001 From: Nyan404 Date: Sun, 16 Aug 2026 20:37:59 +0300 Subject: [PATCH] Fixes for dialoge --- .gitlab-ci.yml | 4 ++-- app/belki/vk_bot.py | 24 ++++++++++++++++-------- tests/test_vk_conversation.py | 10 +++++++++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fabf56c..82c86c1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -74,9 +74,9 @@ deploy: --from-literal=BELKI_ADMIN_PASSWORD="$BELKI_ADMIN_PASSWORD" \ --dry-run=client -o yaml | kubectl apply -f - - > - sed -E "s#(image: reg.nyan404.ru/cwshed-clone/belki:)[^[:space:]]+#\\1$DOCKER_IMAGE_REPOSITORY:$CI_COMMIT_SHORT_SHA#g" deploy/k8s/production.yaml | kubectl apply -f - + sed -E "s#image: reg.nyan404.ru/cwshed-clone/belki:[^[:space:]]+#image: $DOCKER_IMAGE_REPOSITORY:$CI_COMMIT_SHORT_SHA#g" deploy/k8s/production.yaml | kubectl apply -f - - > - sed -E "s#(image: reg.nyan404.ru/cwshed:)[^[:space:]]+#\\1$GATEWAY_IMAGE_REPOSITORY:$CI_COMMIT_SHORT_SHA#g" deploy/k8s/gateway.yaml | kubectl apply -f - + sed -E "s#image: reg.nyan404.ru/cwshed:[^[:space:]]+#image: $GATEWAY_IMAGE_REPOSITORY:$CI_COMMIT_SHORT_SHA#g" deploy/k8s/gateway.yaml | kubectl apply -f - - kubectl -n "$KUBE_NAMESPACE" rollout status deployment/belki-postgres --timeout=180s - kubectl -n "$KUBE_NAMESPACE" rollout status deployment/belki-web --timeout=180s - kubectl -n "$KUBE_NAMESPACE" rollout status deployment/belki-bot --timeout=180s diff --git a/app/belki/vk_bot.py b/app/belki/vk_bot.py index b8f8341..4130222 100644 --- a/app/belki/vk_bot.py +++ b/app/belki/vk_bot.py @@ -605,8 +605,10 @@ class BelkiDialog: return "Похоже, здесь данные для ЛУ или ЗУ. Укажите навык: ЛУ или ЗУ." return None if command.lower() in ("/лу", "/зу"): - self._states[peer_id] = {"mode": "coaching", "skill": "ЛУ" if command.lower() == "/лу" else "ЗУ"} - return self._ask_next(self._states[peer_id]) + state = {"mode": "coaching", "skill": "ЛУ" if command.lower() == "/лу" else "ЗУ"} + self._apply_known_profile(peer_id, state) + self._states[peer_id] = state + return self._ask_next(state) if command.lower().startswith(("/лу ", "/лазание ", "/зу ", "/зоркость ")): try: parsed = parse_text_command(command) @@ -621,8 +623,10 @@ class BelkiDialog: self._states[peer_id] = {**parsed, "awaiting_attachments": True} return "Пришлите сюда скриншоты для этого отчёта. После загрузки всех фотографий нажмите «Готово»." if command.lower() in ("/урок", "/тренировка"): - self._states[peer_id] = {"mode": "training"} - return self._ask_next(self._states[peer_id]) + state = {"mode": "training"} + self._apply_known_profile(peer_id, state) + self._states[peer_id] = state + return self._ask_next(state) if command.lower() in ("/осмотр", "/осмотры"): state = {"mode": "inspection"} self._apply_known_profile(peer_id, state) @@ -639,11 +643,15 @@ class BelkiDialog: return None def _apply_known_profile(self, actor_id: int, state: dict[str, Any]) -> None: - """Use the author's saved character for self-referential inspections.""" - if state.get("mode") != "inspection" or self._has_field(state, "character"): - return + """Use the author's saved character as the default report participant.""" profile = self.identity_directory.profile(actor_id=actor_id) - if profile: + if not profile: + return + if state.get("mode") in ("coaching", "training") and not self._has_field(state, "escort"): + state["escort_name"] = profile.name + state["escort_id"] = profile.character_id + state["escort"] = True + elif state.get("mode") == "inspection" and not self._has_field(state, "character"): state["character_name"] = profile.name state["character_id"] = profile.character_id diff --git a/tests/test_vk_conversation.py b/tests/test_vk_conversation.py index 0d3a0f6..219b864 100644 --- a/tests/test_vk_conversation.py +++ b/tests/test_vk_conversation.py @@ -177,10 +177,18 @@ class VkConversationTests(unittest.TestCase): self.assertIn("Привет, Дикая Вишня", welcome) self.assertIn("/осмотр", welcome) self.assertIn("дат", dialog.handle(500, "/лу", user_id=700).lower()) - restarted = BelkiDialog(IdentityDirectory(db_path=f"{directory}/identities.sqlite3"), onboarding=True) self.assertIn("дат", restarted.handle(500, "/лу", user_id=700).lower()) + def test_saved_author_is_used_as_coaching_escort(self): + identities = IdentityDirectory() + identities.remember_profile(actor_id=700, name="Дикая Вишня", character_id=1604614) + dialog = BelkiDialog(identities) + response = dialog.handle(501, "/лу", user_id=700) + self.assertIn("дат", response.lower()) + self.assertNotIn("сопровождающего", response.lower()) + self.assertEqual(dialog._states[700]["escort_id"], 1604614) + def test_inspection_reuses_onboarded_author_character(self): with TemporaryDirectory() as directory: identities = IdentityDirectory(db_path=f"{directory}/identities.sqlite3")