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:
11
Utils.py
11
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]:
|
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
|
||||||
|
|||||||
6
kvui.py
6
kvui.py
@@ -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
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ from Utils import get_intended_text, get_input_text_from_response
|
|||||||
class TestClient(unittest.TestCase):
|
class TestClient(unittest.TestCase):
|
||||||
def test_autofill_hint_from_fuzzy_hint(self) -> None:
|
def test_autofill_hint_from_fuzzy_hint(self) -> None:
|
||||||
tests = (
|
tests = (
|
||||||
("item", ["item1", "item2"]), # Multiple close matches
|
("item", ["item1", "item2"]), # Multiple close matches
|
||||||
("itm", ["item1", "item21"]), # No close match, multiple option
|
("itm", ["item1", "item21"]), # No close match, multiple option
|
||||||
("item", ["item1"]), # No close match, single option
|
("item", ["item1"]), # No close match, single option
|
||||||
("item", ["\"item\" 'item' (item)"]), # Testing different special characters
|
("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)
|
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}",
|
||||||
|
|||||||
Reference in New Issue
Block a user