From 672579a7eb55ce3c5ada25570be479fce5054b02 Mon Sep 17 00:00:00 2001 From: electron271 <66094410+electron271@users.noreply.github.com> Date: Thu, 28 Mar 2024 21:05:06 -0500 Subject: [PATCH 1/2] [Events] Ghost ping notifier If a ghost ping is found it will send a message saying who sent it and who it pings. --- tux/cogs/events/message.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tux/cogs/events/message.py b/tux/cogs/events/message.py index c11ca9b..735eeef 100644 --- a/tux/cogs/events/message.py +++ b/tux/cogs/events/message.py @@ -14,6 +14,27 @@ class MessageEventsCog(commands.Cog, name="Message Events Handler"): @commands.Cog.listener() async def on_message_delete(self, message: discord.Message) -> None: logger.trace(f"Message deleted: {message}") + + # if sender is a bot, ignore, some bots delete their own messages + if message.author.bot: + return + + # check if message has a ping (role, user, etc.) + if message.mentions or message.role_mentions: + embed = discord.Embed( + title="Ghost Ping!", + color=discord.Color.red() + ) + embed.add_field(name="Sender", value=message.author.mention, inline=True) + # if mentions add mentions field, if role_mentions add role_mentions field + if message.mentions: + embed.add_field(name="Mentions", value=", ".join([mention.mention for mention in message.mentions]), inline=True) + if message.role_mentions: + embed.add_field(name="Role Mentions", value=", ".join([role.mention for role in message.role_mentions]), inline=True) + elif not message.mentions and not message.role_mentions: + # this will (probably) never happen, but just in case + embed.add_field(name="whgar?", value="something is wrong here, no mentions found", inline=True) + await message.channel.send(embed=embed) @commands.Cog.listener() async def on_message_edit(self, before: discord.Message, after: discord.Message) -> None: From be06cabfcd5a322b12b4126aec71733151158d7b Mon Sep 17 00:00:00 2001 From: electron271 Date: Fri, 29 Mar 2024 02:05:26 +0000 Subject: [PATCH 2/2] [Fix] Linting and formatting via Ruff --- tux/cogs/events/message.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tux/cogs/events/message.py b/tux/cogs/events/message.py index 735eeef..1e0ea56 100644 --- a/tux/cogs/events/message.py +++ b/tux/cogs/events/message.py @@ -14,26 +14,33 @@ class MessageEventsCog(commands.Cog, name="Message Events Handler"): @commands.Cog.listener() async def on_message_delete(self, message: discord.Message) -> None: logger.trace(f"Message deleted: {message}") - + # if sender is a bot, ignore, some bots delete their own messages if message.author.bot: return # check if message has a ping (role, user, etc.) if message.mentions or message.role_mentions: - embed = discord.Embed( - title="Ghost Ping!", - color=discord.Color.red() - ) + embed = discord.Embed(title="Ghost Ping!", color=discord.Color.red()) embed.add_field(name="Sender", value=message.author.mention, inline=True) # if mentions add mentions field, if role_mentions add role_mentions field if message.mentions: - embed.add_field(name="Mentions", value=", ".join([mention.mention for mention in message.mentions]), inline=True) + embed.add_field( + name="Mentions", + value=", ".join([mention.mention for mention in message.mentions]), + inline=True, + ) if message.role_mentions: - embed.add_field(name="Role Mentions", value=", ".join([role.mention for role in message.role_mentions]), inline=True) + embed.add_field( + name="Role Mentions", + value=", ".join([role.mention for role in message.role_mentions]), + inline=True, + ) elif not message.mentions and not message.role_mentions: # this will (probably) never happen, but just in case - embed.add_field(name="whgar?", value="something is wrong here, no mentions found", inline=True) + embed.add_field( + name="whgar?", value="something is wrong here, no mentions found", inline=True + ) await message.channel.send(embed=embed) @commands.Cog.listener()