1
0
Fork 0
mirror of https://github.com/uhIgnacio/EmoteManager.git synced 2024-08-15 02:23:13 +00:00

add-archive: ignore invalid files

allows uploading, for example, a zip file with a LICENSE
This commit is contained in:
Io Mintz 2019-10-10 00:27:38 +00:00
parent e02022b245
commit 97947e61c1

View file

@ -197,7 +197,8 @@ class Emotes(commands.Cog):
"""Add several emotes from a .zip or .tar archive. """Add several emotes from a .zip or .tar archive.
You may either pass a URL to an archive or upload one as an attachment. You may either pass a URL to an archive or upload one as an attachment.
All .gif, .png, and .jpg files in the archive will be uploaded as emotes. All valid GIF, PNG, and JPEG files in the archive will be uploaded as emotes.
The rest will be ignored.
""" """
if url and context.message.attachments: if url and context.message.attachments:
raise commands.BadArgument('Either a URL or an attachment must be given, not both.') raise commands.BadArgument('Either a URL or an attachment must be given, not both.')
@ -219,6 +220,10 @@ class Emotes(commands.Cog):
async def add_from_archive(self, context, archive): async def add_from_archive(self, context, archive):
limit = 50_000_000 # prevent someone from trying to make a giant compressed file limit = 50_000_000 # prevent someone from trying to make a giant compressed file
async for name, img, error in utils.archive.extract_async(io.BytesIO(archive), size_limit=limit): async for name, img, error in utils.archive.extract_async(io.BytesIO(archive), size_limit=limit):
try:
utils.image.mime_type_for_image(img)
except errors.InvalidImageError:
continue
if error is None: if error is None:
name = self.format_emote_filename(posixpath.basename(name)) name = self.format_emote_filename(posixpath.basename(name))
async with context.typing(): async with context.typing():