aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/antimalware.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/bot/cogs/antimalware.py b/bot/cogs/antimalware.py
index 72db5bc11..745dd8082 100644
--- a/bot/cogs/antimalware.py
+++ b/bot/cogs/antimalware.py
@@ -1,12 +1,11 @@
import logging
-from discord import Embed, Message
+from discord import Embed, Message, NotFound
from discord.ext.commands import Bot, Cog
-from bot.constants import AntiMalware as AntiMalwareConfig, Channels
+from bot.constants import AntiMalware as AntiMalwareConfig, Channels, URLs
log = logging.getLogger(__name__)
-PASTE_URL = "https://paste.pydis.com/"
class AntiMalware(Cog):
@@ -18,32 +17,35 @@ class AntiMalware(Cog):
@Cog.listener()
async def on_message(self, message: Message) -> None:
"""Identify messages with prohibited attachments."""
- if len(message.attachments) == 0:
+ if not message.attachments:
return
embed = Embed()
for attachment in message.attachments:
- if attachment.filename.lower().endswith('.py'):
+ filename = attachment.filename.lower()
+ if filename.endswith('.py'):
embed.description = (
- "It looks like you tried to attach a Python file - please "
- f"use a code-pasting service such as [{PASTE_URL}]"
- f"({PASTE_URL}) instead."
+ f"It looks like you tried to attach a Python file - please "
+ f"use a code-pasting service such as {URLs.paste_service}"
)
break # Other detections irrelevant because we prioritize the .py message.
- if not attachment.filename.lower().endswith(tuple(AntiMalwareConfig.whitelist)):
+ if not filename.endswith(tuple(AntiMalwareConfig.whitelist)):
+ whitelisted_types = ', '.join(AntiMalwareConfig.whitelist)
meta_channel = self.bot.get_channel(Channels.meta)
embed.description = (
- "It looks like you tried to attach a file type that we "
- "do not allow. We currently allow the following file "
- f"types: **{', '.join(AntiMalwareConfig.whitelist)}**. \n\n"
- f"Feel free to ask in {meta_channel.mention} if you think "
- "this is a mistake."
+ f"It looks like you tried to attach a file type that we "
+ f"do not allow. We currently allow the following file "
+ f"types: **{whitelisted_types}**. \n\n Feel free to ask "
+ f"in {meta_channel.mention} if you think this is a mistake."
)
if embed.description:
await message.channel.send(f"Hey {message.author.mention}!", embed=embed)
# Delete the offending message:
- await message.delete()
+ try:
+ await message.delete()
+ except NotFound:
+ log.info(f"Tried to delete message `{message.id}`, but message could not be found.")
def setup(bot: Bot) -> None: