-
Notifications
You must be signed in to change notification settings - Fork 18
Create admin_block_exe.py #459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: Development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" | ||
Listener to scan for exe or zip files. | ||
""" | ||
import logging | ||
|
||
from discord.ext import commands | ||
|
||
from zorak.utilities.cog_helpers._embeds import embed_cant_do_that | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class FiletypeChecker(commands.Cog): | ||
""" | ||
Listener to check if a exe file or a zip file is attached in | ||
a user's message to prevent malicious files from being sent. | ||
""" | ||
|
||
def __init__(self, bot): | ||
self.bot = bot | ||
|
||
@commands.Cog.listener() | ||
async def on_message(self, message): | ||
for attachment in message.attachments: | ||
print(f"content type: {attachment.content_type}") | ||
if attachment.content_type in [ | ||
"application/x-msdownload", | ||
"application/x-dosexec", | ||
"application/x-msdos-program", | ||
"application/octet-stream", | ||
"application/x-binary", | ||
"application/x-mach-binary", | ||
"application/x-apple-diskimage", | ||
"application/java-archive", | ||
"application/x-java-class", | ||
"application/zip", | ||
"application/x-zip-compressed", | ||
"multipart/x-zip", | ||
"application/x-compressed", | ||
"application/x-compress", | ||
"application/x-zip", | ||
"application/zip-compressed", | ||
"multipart/x-compressed", | ||
]: | ||
await message.delete() | ||
await message.channel.send( | ||
embed=embed_cant_do_that( | ||
"You cannot send executable files or zip files." | ||
), | ||
delete_after=10, | ||
) | ||
logger.info( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, it's good that we log this on the server, but perhaps we should have a more permanent log in the moderation logs to let us know what user, and what file was being uploaded. I'm not sure it would be necessary to actually log the file itself, but if it's a link, that would be useful to know about false positives / positive positives. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: Add permanent logging here in Mod Logs |
||
f"Blocked attachment from {message.author}:\n{message.clean_content}\nAttachment:{attachment.filename}" | ||
) | ||
return | ||
|
||
|
||
def setup(bot): | ||
""" | ||
required. | ||
""" | ||
bot.add_cog(FiletypeChecker(bot)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Love the idea of blocking lots of different file types, As most of these are not really necessary.