Skip to content

Commit

Permalink
Merge pull request #14 from AbhijeetKrishnan/master
Browse files Browse the repository at this point in the history
Fix handling of image link
  • Loading branch information
TLNBS2405 authored Apr 3, 2024
2 parents ebb1915 + 1fab263 commit d97ae84
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
11 changes: 7 additions & 4 deletions src/frame_service/wavu/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from framedb.const import CharacterName

WAVU_API_URL = "https://wavu.wiki/w/api.php"
WAVU_VIDEO_LINK = "https://wavu.wiki/t/Special:Redirect/file/"
WAVU_FILE_LINK = "https://wavu.wiki/t/Special:Redirect/file/"

"""Available fields for the Move table in the Wavu DB"""
FIELDS = [
Expand Down Expand Up @@ -96,7 +96,7 @@ def _convert_json_move(move_json: Any) -> WavuMove:
id = _normalize_data(move_json["id"])
parent = _normalize_data(move_json["parent"])

name = html.unescape(_normalize_data(_process_links(move_json["name"])))
name = html.unescape(_process_links(move_json["name"]))

input = html.unescape(html.unescape(_normalize_data(move_json["input"]))).replace("*", "\\*")

Expand Down Expand Up @@ -128,16 +128,19 @@ def _convert_json_move(move_json: Any) -> WavuMove:
else:
alt = ()

if "image" in move_json:
if "image" in move_json and move_json["image"]:
image = _process_links(move_json["image"])
image_name = image.split(":")[-1]
image_name = image_name.replace(" ", "_")
image = WAVU_FILE_LINK + image_name
else:
image = ""

if "video" in move_json and move_json["video"]:
video = _process_links(move_json["video"])
video_name = video.split(":")[-1]
video_name = video_name.replace(" ", "_")
video = WAVU_VIDEO_LINK + video_name
video = WAVU_FILE_LINK + video_name
else:
video = ""

Expand Down
4 changes: 2 additions & 2 deletions src/framedb/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CharacterName(enum.Enum):
CLAUDIO = "claudio"
DEVIL_JIN = "devil_jin"
DRAGUNOV = "dragunov"
EDDY = "eddy"
FENG = "feng"
HWOARANG = "hwoarang"
JACK_8 = "jack-8"
Expand All @@ -37,7 +38,6 @@ class CharacterName(enum.Enum):
ZAFINA = "zafina"
LEROY = "leroy"
VICTOR = "victor"
EDDY = "eddy"

def pretty(self) -> str:
return self.value.replace("_", " ").title()
Expand All @@ -54,6 +54,7 @@ def url_encode(self) -> str:
CharacterName.CLAUDIO: ["cld", "cla"],
CharacterName.DEVIL_JIN: ["dj", "deviljin", "dvj", "djin"],
CharacterName.DRAGUNOV: ["drag", "sergei", "dragu"],
CharacterName.EDDY: ["ed"],
CharacterName.FENG: ["fen"],
CharacterName.HWOARANG: ["hwo"],
CharacterName.JACK_8: ["j8", "jack8", "jack"],
Expand All @@ -79,7 +80,6 @@ def url_encode(self) -> str:
CharacterName.ZAFINA: ["zaffy", "zaf"],
CharacterName.LEROY: ["ler"],
CharacterName.VICTOR: ["vic"],
CharacterName.EDDY: ["ed"],
}


Expand Down
14 changes: 7 additions & 7 deletions src/heihachi/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ async def on_ready(self) -> None:
self.add_view(button.DoneButton(action_channel))
logger.info(f"Logged on as {self.user}")

def _character_command_factory(self, name: str) -> Callable[[Interaction, str], Coroutine[Any, Any, None]]:
async def command(interaction: discord.Interaction, move: str) -> None:
def _character_command_factory(self, name: str) -> Callable[[Interaction["FrameDataBot"], str], Coroutine[Any, Any, None]]:
async def command(interaction: discord.Interaction["FrameDataBot"], move: str) -> None:
if not (self._is_user_blacklisted(str(interaction.user.id)) or self._is_author_newly_created(interaction)):
logger.info(
f"Received character command from {interaction.user.name} in {interaction.guild}: /fd {name} {move}"
Expand All @@ -78,7 +78,7 @@ def _is_user_blacklisted(self, user_id: str | int) -> bool:
else:
return False

def _is_author_newly_created(self, interaction: discord.Interaction) -> bool:
def _is_author_newly_created(self, interaction: discord.Interaction["FrameDataBot"]) -> bool:
"Check if author of an interaction is newly created"

today = datetime.datetime.strptime(datetime.datetime.now().isoformat(), "%Y-%m-%dT%H:%M:%S.%f")
Expand All @@ -98,7 +98,7 @@ async def on_message(self, message: discord.Message) -> None:
logger.debug(f"Message from {message.author.name} in {message.guild} is not a valid command")

async def _character_name_autocomplete(
self, interaction: discord.Interaction, current: str
self, interaction: discord.Interaction["FrameDataBot"], current: str
) -> List[discord.app_commands.Choice[str]]:
"""
Autocomplete function for character names
Expand All @@ -117,7 +117,7 @@ def _add_bot_commands(self) -> None:

@self.tree.command(name="fd", description="Frame data from a character move")
@discord.app_commands.autocomplete(character=self._character_name_autocomplete)
async def _frame_data_cmd(interaction: discord.Interaction, character: str, move: str) -> None:
async def _frame_data_cmd(interaction: discord.Interaction["FrameDataBot"], character: str, move: str) -> None:
logger.info(f"Received command from {interaction.user.name} in {interaction.guild}: /fd {character} {move}")
character_name_query = character
move_query = move
Expand All @@ -128,7 +128,7 @@ async def _frame_data_cmd(interaction: discord.Interaction, character: str, move
if self.config.feedback_channel_id and self.config.action_channel_id:

@self.tree.command(name="feedback", description="Send feedback to the authors in case of incorrect data")
async def _feedback_cmd(interaction: discord.Interaction, message: str) -> None:
async def _feedback_cmd(interaction: discord.Interaction["FrameDataBot"], message: str) -> None:
logger.info(f"Received command from {interaction.user.name} in {interaction.guild}: /feedback {message}")
if not (self._is_user_blacklisted(str(interaction.user.id)) or self._is_author_newly_created(interaction)):
# TODO: possible way to refactor these checks using discord.py library?
Expand Down Expand Up @@ -159,7 +159,7 @@ async def _feedback_cmd(interaction: discord.Interaction, message: str) -> None:
logger.warning("Feedback or Action channel ID is not set. Disabling feedback command.")

@self.tree.command(name="help", description="Show help")
async def _help_command(interaction: discord.Interaction) -> None:
async def _help_command(interaction: discord.Interaction["FrameDataBot"]) -> None:
logger.info(f"Received command from {interaction.user.name} in {interaction.guild}: /help")
if not (self._is_user_blacklisted(str(interaction.user.id)) or self._is_author_newly_created(interaction)):
help_embed = embed.get_help_embed(self.frame_service)
Expand Down
3 changes: 3 additions & 0 deletions src/heihachi/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def get_move_embed(frame_service: FrameService, character: Character, move: Move
if move.video:
embed.add_field(name="Video", value=f"[Link]({move.video})", inline=False)

if move.image:
embed.set_image(url=move.image)

return embed


Expand Down

0 comments on commit d97ae84

Please sign in to comment.