From b25f18c7fbe12665dcb878f285a7652b1a71e328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Tue, 21 Jan 2025 18:54:21 +0100 Subject: [PATCH] Remove unused functions --- discord_reminder_bot/interaction_responses.py | 68 ------------------- 1 file changed, 68 deletions(-) delete mode 100644 discord_reminder_bot/interaction_responses.py diff --git a/discord_reminder_bot/interaction_responses.py b/discord_reminder_bot/interaction_responses.py deleted file mode 100644 index 5a2b30d..0000000 --- a/discord_reminder_bot/interaction_responses.py +++ /dev/null @@ -1,68 +0,0 @@ -from __future__ import annotations - -import logging - -import discord - -logger: logging.Logger = logging.getLogger(__name__) - - -async def send_error_response(interaction: discord.Interaction, msg: str, *, ephemeral: bool = False) -> None: - """Handle the error. - - Args: - interaction (discord.Interaction): The interaction object for the command. - msg (str): The message to send. - ephemeral (bool, optional): Whether the message should be ephemeral. Defaults to False. - """ - logger.exception(msg) - await interaction.response.send_message(msg, ephemeral=ephemeral) - - -async def followup_msg( - interaction: discord.Interaction, - *, # So that the following arguments are keyword-only - msg: str | None = None, - ephemeral: bool = False, - embed: discord.Embed | None = None, - view: discord.ui.View | None = None, -) -> None: - """Send a followup message to the interaction. - - Handles the exceptions that may occur when sending a followup message. - - Args: - interaction (discord.Interaction): The interaction object for the command. - msg (str): The message to send. - ephemeral (bool, optional): Whether the message should be ephemeral. Defaults to False. - embed (discord.Embed | None, optional): The embed to send. Defaults to no embed. - view (discord.ui.View | None, optional): The view to send. Defaults to no view. - """ - if not msg: - msg = "No message was provided." - try: - if embed and view: - log_msg: str = f"Sending followup message with embed and view to the interaction.\n{msg=}.\n{ephemeral=}\n{embed.to_dict()=}" - for view_item in view.children: - log_msg += f"\n{view_item=}" - - logger.info(log_msg) - await interaction.followup.send(embed=embed, ephemeral=ephemeral, view=view) - else: - logger.info("Sending followup message to the interaction.\nMessage: %s.\nEphemeral: %s", msg, ephemeral) - await interaction.followup.send(content=msg, ephemeral=ephemeral) - - except (discord.NotFound, discord.Forbidden, discord.HTTPException, TypeError, ValueError) as e: - error_messages: dict[type[discord.HTTPException | TypeError | ValueError], str] = { - discord.NotFound: "The original message was not found.", - discord.Forbidden: "The authorization token for the webhook is incorrect.", - discord.HTTPException: "Failed to send followup message.", - TypeError: "We specified both embed and embeds or file and files, or thread and threads.", - ValueError: ( - "The length of embeds was invalid, there was no token associated with this webhook or " - "ephemeral was passed with the improper webhook type or there was no state attached with " - "this webhook when giving it a view." - ), - } - assert_msg: str = error_messages[type(e)] - await send_error_response(interaction=interaction, msg=assert_msg, ephemeral=ephemeral)