From 75743a71c6937c3e35d06eb74c5c4b6e8882430b Mon Sep 17 00:00:00 2001 From: Abhijeet Krishnan <abhijeet.krishnan@gmail.com> Date: Sun, 24 Mar 2024 14:44:28 -0400 Subject: [PATCH 1/3] Fix image link from Wavu --- src/frame_service/wavu/utils.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/frame_service/wavu/utils.py b/src/frame_service/wavu/utils.py index b6a5613..8cedf15 100644 --- a/src/frame_service/wavu/utils.py +++ b/src/frame_service/wavu/utils.py @@ -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 = [ @@ -128,8 +128,11 @@ 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 = "" @@ -137,7 +140,7 @@ def _convert_json_move(move_json: Any) -> WavuMove: 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 = "" From f0fa6a07042d390d66c194c889569bfcf3fcf49a Mon Sep 17 00:00:00 2001 From: Abhijeet Krishnan <abhijeet.krishnan@gmail.com> Date: Sun, 24 Mar 2024 14:54:38 -0400 Subject: [PATCH 2/3] Add image in embed --- src/heihachi/bot.py | 14 +++++++------- src/heihachi/embed.py | 3 +++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/heihachi/bot.py b/src/heihachi/bot.py index abd80db..4290ebe 100644 --- a/src/heihachi/bot.py +++ b/src/heihachi/bot.py @@ -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}" @@ -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") @@ -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 @@ -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 @@ -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? @@ -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) diff --git a/src/heihachi/embed.py b/src/heihachi/embed.py index 650e05a..94fa682 100644 --- a/src/heihachi/embed.py +++ b/src/heihachi/embed.py @@ -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 From 1fab2634ccc4fbc1d1f934ed672163d3f31a8259 Mon Sep 17 00:00:00 2001 From: Abhijeet Krishnan <abhijeet.krishnan@gmail.com> Date: Tue, 2 Apr 2024 11:50:02 -0400 Subject: [PATCH 3/3] Fix issues with non-ASCII characters in move names --- src/frame_service/wavu/utils.py | 2 +- src/framedb/const.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/frame_service/wavu/utils.py b/src/frame_service/wavu/utils.py index 65968e0..e32b535 100644 --- a/src/frame_service/wavu/utils.py +++ b/src/frame_service/wavu/utils.py @@ -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("*", "\\*") diff --git a/src/framedb/const.py b/src/framedb/const.py index 65940ee..65cf40b 100644 --- a/src/framedb/const.py +++ b/src/framedb/const.py @@ -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" @@ -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() @@ -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"], @@ -79,7 +80,6 @@ def url_encode(self) -> str: CharacterName.ZAFINA: ["zaffy", "zaf"], CharacterName.LEROY: ["ler"], CharacterName.VICTOR: ["vic"], - CharacterName.EDDY: ["ed"], }