Skip to content

Commit

Permalink
Merge pull request #24 from hwsuk/bug/fix-rate-limiter-exception-hand…
Browse files Browse the repository at this point in the history
…ling

bug(message_rate_limiter): Fix exception handling on message rate limiter
  • Loading branch information
emberdex authored Mar 18, 2024
2 parents 7b64693 + e65bc3f commit 67e45c2
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions harmony_cogs/message_rate_limiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,24 @@ async def on_message(self, message: discord.Message) -> typing.NoReturn:

guild_channel = message.guild.get_channel(message.channel.id)

await message.author.send(embed=harmony_ui.message_rate_limiter.create_message_limited_embed(
author_name=message.author.name,
guild_name=message.guild.name,
guild_channel_name=guild_channel.name,
guild_channel_url=guild_channel.jump_url,
original_message_timestamp=rate_limiter_data.message_timestamp,
rate_limit_seconds=channel_limit.rate_limit_seconds,
deleted_message_content=message.clean_content
))

await message.delete()

try:
await message.author.send(
embed=harmony_ui.message_rate_limiter.create_message_limited_embed(
author_name=message.author.name,
guild_name=message.guild.name,
guild_channel_name=guild_channel.name,
guild_channel_url=guild_channel.jump_url,
original_message_timestamp=rate_limiter_data.message_timestamp,
rate_limit_seconds=channel_limit.rate_limit_seconds,
deleted_message_content=message.clean_content()
)
)
except discord.errors.DiscordException as e:
logger.warning(f"Failed to PM user {message.author.name} with message rate-limit, "
f"got exception: {str(e)}")

else:
# Delete their existing data and move on.
rate_limiter_data.delete()

0 comments on commit 67e45c2

Please sign in to comment.