From f07fea2771c2fe5092570e9da417c163fe6f87bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Bolduc?= <16137441+Jouramie@users.noreply.github.com> Date: Sat, 4 Oct 2025 23:39:30 -0400 Subject: [PATCH] CommonClient: Move command marker to last_autofillable_command (#4907) * handle autocomplete command when press question * fix test * add docstring to get_input_text_from_response * fix line lenght --- Utils.py | 11 ++++++++++- kvui.py | 6 +++--- test/general/test_client_server_interaction.py | 8 ++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Utils.py b/Utils.py index a14e737c..08e5dba8 100644 --- a/Utils.py +++ b/Utils.py @@ -721,13 +721,22 @@ def get_intended_text(input_text: str, possible_answers) -> typing.Tuple[str, bo def get_input_text_from_response(text: str, command: str) -> typing.Optional[str]: + """ + Parses the response text from `get_intended_text` to find the suggested input and autocomplete the command in + arguments with it. + + :param text: The response text from `get_intended_text`. + :param command: The command to which the input text should be added. Must contain the prefix used by the command + (`!` or `/`). + :return: The command with the suggested input text appended, or None if no suggestion was found. + """ if "did you mean " in text: for question in ("Didn't find something that closely matches", "Too many close matches"): if text.startswith(question): name = get_text_between(text, "did you mean '", "'? (") - return f"!{command} {name}" + return f"{command} {name}" elif text.startswith("Missing: "): return text.replace("Missing: ", "!hint_location ") return None diff --git a/kvui.py b/kvui.py index 013cd336..86297c49 100644 --- a/kvui.py +++ b/kvui.py @@ -838,15 +838,15 @@ class GameManager(ThemedApp): self.log_panels: typing.Dict[str, Widget] = {} # keep track of last used command to autofill on click - self.last_autofillable_command = "hint" - autofillable_commands = ("hint_location", "hint", "getitem") + self.last_autofillable_command = "!hint" + autofillable_commands = ("!hint_location", "!hint", "!getitem") original_say = ctx.on_user_say def intercept_say(text): text = original_say(text) if text: for command in autofillable_commands: - if text.startswith("!" + command): + if text.startswith(command): self.last_autofillable_command = command break return text diff --git a/test/general/test_client_server_interaction.py b/test/general/test_client_server_interaction.py index 17de9151..209ef92a 100644 --- a/test/general/test_client_server_interaction.py +++ b/test/general/test_client_server_interaction.py @@ -6,9 +6,9 @@ from Utils import get_intended_text, get_input_text_from_response class TestClient(unittest.TestCase): def test_autofill_hint_from_fuzzy_hint(self) -> None: tests = ( - ("item", ["item1", "item2"]), # Multiple close matches - ("itm", ["item1", "item21"]), # No close match, multiple option - ("item", ["item1"]), # No close match, single option + ("item", ["item1", "item2"]), # Multiple close matches + ("itm", ["item1", "item21"]), # No close match, multiple option + ("item", ["item1"]), # No close match, single option ("item", ["\"item\" 'item' (item)"]), # Testing different special characters ) @@ -16,7 +16,7 @@ class TestClient(unittest.TestCase): item_name, usable, response = get_intended_text(input_text, possible_answers) self.assertFalse(usable, "This test must be updated, it seems get_fuzzy_results behavior changed") - hint_command = get_input_text_from_response(response, "hint") + hint_command = get_input_text_from_response(response, "!hint") self.assertIsNotNone(hint_command, "The response to fuzzy hints is no longer recognized by the hint autofill") self.assertEqual(hint_command, f"!hint {item_name}",