aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar bendiller <[email protected]>2019-10-16 17:42:48 -0600
committerGravatar bendiller <[email protected]>2019-10-16 17:42:48 -0600
commitd9b4f391f914b680bdf4d5b93882abe11b8dc9d4 (patch)
treeb982f56c74e73b9848b91f775fe0f9773560fed6
parentImprove code readability and docstring (diff)
Improve code readability and provide early exit from loop
-rw-r--r--bot/cogs/antimalware.py21
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)