From edf6aa58ce8afb6837d448a6c17915ed7dfcc102 Mon Sep 17 00:00:00 2001 From: winston Date: Mon, 12 Jun 2023 01:49:28 +0200 Subject: [PATCH] fix: don't add embed image if none are set --- hornytimer/hornytimer.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/hornytimer/hornytimer.py b/hornytimer/hornytimer.py index c67f995..74c07c8 100644 --- a/hornytimer/hornytimer.py +++ b/hornytimer/hornytimer.py @@ -44,15 +44,17 @@ class HornyTimer(commands.Cog): (await self.config.guild(interaction.guild).reset_count()) + 1 ) - random_bonk_image = await self._get_random_bonk_image(interaction.guild) - - await interaction.response.send_message( - embed=discord.Embed( - title="Timer reset.", - description=f"Timer reset. This discord managed to not be horny for {self._get_time_diff(prev_timestamp)}.", - ).set_image(url=random_bonk_image["url"]) + embed = discord.Embed( + title="Timer reset.", + description=f"Timer reset. This discord managed to not be horny for {self._get_time_diff(prev_timestamp)}.", ) + image = await self._get_random_bonk_image(interaction.guild) + if image: + embed.set_image(url=image["url"]) + + await interaction.response.send_message(embed=embed) + @app_commands.command(name="checkhornytimer") @app_commands.guild_only() async def check_timer(self, interaction: Interaction) -> None: @@ -68,7 +70,7 @@ class HornyTimer(commands.Cog): @commands.group() @commands.guild_only() @commands.mod_or_permissions(manage_channels=True) - async def bonkimage(self, ctx: commands.Context): + async def bonkimage(self, _: commands.Context): """Manage bonk images.""" @bonkimage.command(name="add") @@ -131,6 +133,6 @@ class HornyTimer(commands.Cog): async def _get_bonk_images(self, guild: Guild) -> List[BonkImage]: return await self.config.guild(guild).bonk_images() - async def _get_random_bonk_image(self, guild: Guild) -> BonkImage: + async def _get_random_bonk_image(self, guild: Guild) -> BonkImage | None: bonk_images = await self._get_bonk_images(guild) return bonk_images[random.randint(0, len(bonk_images) - 1)]