From c15fc81178b47fc32ad9ef322713127c87beff25 Mon Sep 17 00:00:00 2001 From: Nyan404 Date: Sun, 16 Aug 2026 17:06:53 +0300 Subject: [PATCH] fix: reuse saved character in inspections --- app/belki/vk_bot.py | 15 ++++++++++++++- tests/test_vk_conversation.py | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/belki/vk_bot.py b/app/belki/vk_bot.py index cfbc937..b8f8341 100644 --- a/app/belki/vk_bot.py +++ b/app/belki/vk_bot.py @@ -598,6 +598,7 @@ class BelkiDialog: natural = parse_natural_bulk(command) if natural is not None: fields, _ = natural + self._apply_known_profile(peer_id, fields) self._states[peer_id] = fields return "Я нашёл часть данных. " + self._ask_next(self._states[peer_id]) if self._bulk_hint(command): @@ -623,17 +624,29 @@ class BelkiDialog: self._states[peer_id] = {"mode": "training"} return self._ask_next(self._states[peer_id]) if command.lower() in ("/осмотр", "/осмотры"): - self._states[peer_id] = {"mode": "inspection"} + state = {"mode": "inspection"} + self._apply_known_profile(peer_id, state) + self._states[peer_id] = state return self._ask_next(self._states[peer_id]) if command.lower().startswith(("/урок ", "/тренировка ", "/осмотр ", "/осмотры ")): try: parsed = parse_text_command(command) except (ValueError, IndexError) as exc: return f"Не удалось распознать данные скопом: {exc}. Проверьте запись или начните ввод по одному вопросу." + self._apply_known_profile(peer_id, parsed) self._states[peer_id] = parsed return self._ask_next(self._states[peer_id]) 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 + profile = self.identity_directory.profile(actor_id=actor_id) + if profile: + state["character_name"] = profile.name + state["character_id"] = profile.character_id + def _consume_field(self, state: dict[str, Any], text: str) -> str: key = next((key for key, _ in self._ORDERS[state["mode"]] if not self._has_field(state, key)), None) if key == "date": diff --git a/tests/test_vk_conversation.py b/tests/test_vk_conversation.py index 8e02139..0d3a0f6 100644 --- a/tests/test_vk_conversation.py +++ b/tests/test_vk_conversation.py @@ -181,6 +181,18 @@ class VkConversationTests(unittest.TestCase): restarted = BelkiDialog(IdentityDirectory(db_path=f"{directory}/identities.sqlite3"), onboarding=True) self.assertIn("дат", restarted.handle(500, "/лу", user_id=700).lower()) + def test_inspection_reuses_onboarded_author_character(self): + with TemporaryDirectory() as directory: + identities = IdentityDirectory(db_path=f"{directory}/identities.sqlite3") + dialog = BelkiDialog(identities, onboarding=True) + dialog.handle(510, "/осмотр", user_id=710) + dialog.handle(510, "Дикая Вишня [1604614]", user_id=710) + + self.assertIn("место", dialog.handle(510, "/осмотр", user_id=710).lower()) + dialog.handle(510, "дупло", user_id=710) + self.assertIn("ресурс", dialog.handle(510, "1", user_id=710).lower()) + self.assertNotIn("персонаж", dialog.handle(510, "без ресурсов", user_id=710).lower()) + def test_independence_accepts_adjectival_forms(self): dialog = BelkiDialog() dialog.handle(501, "/лу")