1
0

FIX: KeyError when returning a mistyped spell with Levenshtein distance

This commit is contained in:
Kwarde 2024-01-18 17:03:21 +01:00
parent fc8bee2f73
commit 1dff4f524b
2 changed files with 5 additions and 5 deletions

View File

@ -47,12 +47,12 @@ def get_player_spell_from_input(player: Player):
continue continue
elif player_input.find("help", 0) != -1: elif player_input.find("help", 0) != -1:
find_what = player_input[5:] find_what = player_input[5:]
spell = spells.get(find_spell_by_name(find_what)[0][0], None) spell_name, spell_obj = find_spell_by_name(find_what)[0]
if spell is spells[_INVALID_SPELL]: if spell_obj is spells[_INVALID_SPELL]:
print("<!> Spell '{what}' does not exist!".format(what=find_what)) print("<!> Spell '{what}' does not exist!".format(what=spell_name))
else: else:
print("'{spell_name}':{spell_desc}".format(spell_name=find_what, spell_desc=spells[find_what])) print("'{spell_name}':{spell_desc}".format(spell_name=spell_name, spell_desc=spell_obj))
continue continue
else: else:
return find_spell_by_name(player_input) return find_spell_by_name(player_input)

View File

@ -107,7 +107,7 @@ def find_spell_by_name(input: str): # Returns a multidimensional tuple: ( ('spel
for i in spells.items(): for i in spells.items():
dist = distance(i[0].title(), input.title()) dist = distance(i[0].title(), input.title())
if dist <= MAX_LEVENSHTEIN_DISTANCE: if dist <= MAX_LEVENSHTEIN_DISTANCE:
ret[1] = i ret = (i[0], i[1])
break break
return (ret, dist) return (ret, dist)