make get_intended_text handle 1 out of 1 pools correctly.

This commit is contained in:
Fabian Dill 2020-04-21 21:53:20 +02:00
parent 9291a0dbca
commit afc379f92e
1 changed files with 15 additions and 8 deletions

View File

@ -337,15 +337,22 @@ def format_hint(ctx: Context, team: int, hint: Utils.Hint) -> str:
def get_intended_text(input_text: str, possible_answers: typing.Iterable[str]= console_names) -> typing.Tuple[str, bool, str]: def get_intended_text(input_text: str, possible_answers: typing.Iterable[str]= console_names) -> typing.Tuple[str, bool, str]:
picks = fuzzy_process.extract(input_text, possible_answers, limit=2) picks = fuzzy_process.extract(input_text, possible_answers, limit=2)
dif = picks[0][1] - picks[1][1] if len(picks) > 1:
if picks[0][1] == 100: dif = picks[0][1] - picks[1][1]
return picks[0][0], True, "Perfect Match" if picks[0][1] == 100:
elif picks[0][1] < 75: return picks[0][0], True, "Perfect Match"
return picks[0][0], False, f"Didn't find something that closely matches, did you mean {picks[0][0]}?" elif picks[0][1] < 75:
elif dif > 5: return picks[0][0], False, f"Didn't find something that closely matches, " \
return picks[0][0], True, "Close Match" f"did you mean {picks[0][0]}? ({picks[0][1]}% sure)"
elif dif > 5:
return picks[0][0], True, "Close Match"
else:
return picks[0][0], False, f"Too many close matches, did you mean {picks[0][0]}? ({picks[0][1]}% sure)"
else: else:
return picks[0][0], False, f"Too many close matches, did you mean {picks[0][0]}?" if picks[0][1] > 90:
return picks[0][0], True, "Only Option Match"
else:
return picks[0][0], False, f"Did you mean {picks[0][0]}? ({picks[0][1]}% sure)"
class CommandMeta(type): class CommandMeta(type):