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
This commit is contained in:
Jérémie Bolduc
2025-10-04 23:39:30 -04:00
committed by GitHub
parent a2460b7fe7
commit f07fea2771
3 changed files with 17 additions and 8 deletions

View File

@@ -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]: 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: if "did you mean " in text:
for question in ("Didn't find something that closely matches", for question in ("Didn't find something that closely matches",
"Too many close matches"): "Too many close matches"):
if text.startswith(question): if text.startswith(question):
name = get_text_between(text, "did you mean '", name = get_text_between(text, "did you mean '",
"'? (") "'? (")
return f"!{command} {name}" return f"{command} {name}"
elif text.startswith("Missing: "): elif text.startswith("Missing: "):
return text.replace("Missing: ", "!hint_location ") return text.replace("Missing: ", "!hint_location ")
return None return None

View File

@@ -838,15 +838,15 @@ class GameManager(ThemedApp):
self.log_panels: typing.Dict[str, Widget] = {} self.log_panels: typing.Dict[str, Widget] = {}
# keep track of last used command to autofill on click # keep track of last used command to autofill on click
self.last_autofillable_command = "hint" self.last_autofillable_command = "!hint"
autofillable_commands = ("hint_location", "hint", "getitem") autofillable_commands = ("!hint_location", "!hint", "!getitem")
original_say = ctx.on_user_say original_say = ctx.on_user_say
def intercept_say(text): def intercept_say(text):
text = original_say(text) text = original_say(text)
if text: if text:
for command in autofillable_commands: for command in autofillable_commands:
if text.startswith("!" + command): if text.startswith(command):
self.last_autofillable_command = command self.last_autofillable_command = command
break break
return text return text

View File

@@ -16,7 +16,7 @@ class TestClient(unittest.TestCase):
item_name, usable, response = get_intended_text(input_text, possible_answers) 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") 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, self.assertIsNotNone(hint_command,
"The response to fuzzy hints is no longer recognized by the hint autofill") "The response to fuzzy hints is no longer recognized by the hint autofill")
self.assertEqual(hint_command, f"!hint {item_name}", self.assertEqual(hint_command, f"!hint {item_name}",