Skip to content

Commit

Permalink
Fix bugs with move type query and spaces in char names
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhijeetKrishnan committed Feb 16, 2024
1 parent 028e13b commit 745be6a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/framedb/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class CharacterName(enum.Enum):
LEROY = "leroy"
VICTOR = "victor"

def pretty(self) -> str:
return self.value.replace("_", " ").title()

def url_encode(self) -> str:
return self.pretty().replace(" ", " ")


CHARACTER_ALIAS: Dict[CharacterName, List[str]] = {
CharacterName.ALISA: ["ali", "als"],
Expand Down
18 changes: 11 additions & 7 deletions src/framedb/framedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_moves_by_move_type(self, character: CharacterName, move_type_query: str)
move_list = self.frames[character].movelist.values()
move_type = FrameDb._correct_move_type(move_type_query)
if move_type:
moves = list(filter(lambda x: (move_type.value in x.notes.lower()), move_list))
moves = list(filter(lambda x: (move_type.value.lower() in x.notes.lower()), move_list))
else:
moves = []

Expand Down Expand Up @@ -168,17 +168,21 @@ def get_character_by_name(self, name_query: str) -> Character | None:
"""Given a character name query, return the corresponding character"""

for character_name, character in self.frames.items():
if character_name.value == name_query:
if character_name.value == FrameDb._correct_character_name(name_query):
return character
return None

def get_move_type(self, move_type_query: str) -> MoveType | None: # TODO: overlap with get_moves_by_move_type?
def get_move_type(self, move_type_query: str) -> MoveType | None:
"""Given a move type query, return the corresponding move type"""

for move_type, aliases in MOVE_TYPE_ALIAS.items():
if move_type_query.lower() in aliases:
return move_type
return None
move_type_candidate = FrameDb._correct_move_type(move_type_query)
if move_type_candidate is None:
logger.warning(f"Could not match move type {move_type_query} to a known move type. Checking aliases...")
for move_type, aliases in MOVE_TYPE_ALIAS.items():
if move_type_query.lower() in aliases:
move_type_candidate = move_type
break
return move_type_candidate


def _get_close_matches_indices(word: str, possibilities: List[str], n: int = 5, cutoff: float = 0.7) -> List[int]:
Expand Down
6 changes: 3 additions & 3 deletions src/heihachi/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_move_list_embed(
desc_string = "\n".join(sorted([move.input for move in moves]))

embed = discord.Embed(
title=f"{character.name} {move_type.value.lower()}:\n",
title=f"{character.name.pretty()} {move_type.value.lower()}:\n",
colour=SUCCESS_COLOR,
description=desc_string,
)
Expand All @@ -58,12 +58,12 @@ def get_move_embed(frame_service: FrameService, character: Character, move: Move
title=f"**{move.input}**",
colour=SUCCESS_COLOR,
description=move.name,
url=f"{character.page}_movelist#{move.id}", # TODO: this is specific to Wavu, change it to be more generic
url=f"{character.page}_movelist#{move.id.replace(' ', '_')}", # TODO: this is specific to Wavu, change it to be more generic
)

embed.set_thumbnail(url=character.portrait)
embed.set_footer(text=frame_service.name, icon_url=frame_service.icon)
embed.set_author(name=character.name.value.title(), url=character.page)
embed.set_author(name=character.name.pretty(), url=character.page)

embed.add_field(name="Target", value=move.target)
embed.add_field(name="Damage", value=move.damage)
Expand Down

0 comments on commit 745be6a

Please sign in to comment.