diff options
| -rw-r--r-- | bot/cogs/antimalware.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/bot/cogs/antimalware.py b/bot/cogs/antimalware.py index 156239a63..2ef61e8ad 100644 --- a/bot/cogs/antimalware.py +++ b/bot/cogs/antimalware.py @@ -17,24 +17,29 @@ class AntiMalware(Cog): @Cog.listener() async def on_message(self, message: Message) -> None: """Identify messages with prohibited attachments.""" - rejected_attachments = list() - detected_pyfile = list() + rejected_attachments = False + detected_pyfile = False for attachment in message.attachments: if not attachment.filename.lower().endswith(tuple(AntiMalwareConfig.whitelist)): - rejected_attachments.append(attachment) + rejected_attachments = True if attachment.filename.lower().endswith('.py'): - detected_pyfile.append(attachment) + detected_pyfile = True + break # Other detections irrelevant because we prioritize the .py message. if rejected_attachments: # Send a message to the user indicating the problem (with special treatment for .py) author = message.author if detected_pyfile: - msg = (f"{author.mention}, it looks like you tried to attach a Python file - please " - f"use a code-pasting service such as https://paste.pythondiscord.com/ instead.") + msg = ( + f"{author.mention}, it looks like you tried to attach a Python file - please " + f"use a code-pasting service such as https://paste.pythondiscord.com/ instead." + ) else: meta_channel = self.bot.get_channel(Channels.meta) - msg = (f"{author.mention}, it looks like you tried to attach a file type we don't " - f"allow. Feel free to ask in {meta_channel.mention} if you think this is a mistake.") + msg = ( + f"{author.mention}, it looks like you tried to attach a file type we don't " + f"allow. Feel free to ask in {meta_channel.mention} if you think this is a mistake." + ) await message.channel.send(msg) |