mirror of
https://github.com/uhIgnacio/EmoteManager.git
synced 2024-08-15 02:23:13 +00:00
add-zip: fix error message for invalid files
This commit is contained in:
parent
bf668e10b9
commit
4828a4ff52
3 changed files with 8 additions and 9 deletions
|
@ -235,9 +235,11 @@ class Emotes(commands.Cog):
|
|||
"""Try to add an emote from bytes. On error, return a string that should be sent to the user."""
|
||||
try:
|
||||
emote = await self.create_emote_from_bytes(guild, name, author_id, image_data, reason=reason)
|
||||
except discord.InvalidArgument:
|
||||
return discord.utils.escape_mentions(f'{name}: The file supplied was not a valid GIF, PNG, or JPEG file.')
|
||||
except discord.HTTPException as ex:
|
||||
return (
|
||||
'An error occurred while creating the emote:\n'
|
||||
return discord.utils.escape_mentions(
|
||||
f'{name}: An error occurred while creating the the emote:\n'
|
||||
+ utils.format_http_exception(ex))
|
||||
return f'Emote {emote} successfully created.'
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class InvalidFileError(EmoteManagerError):
|
|||
class InvalidImageError(InvalidFileError):
|
||||
"""The image is not a GIF, PNG, or JPG"""
|
||||
def __init__(self):
|
||||
super().__init__('The image supplied was not a GIF, PNG, or JPG.')
|
||||
super(Exception, self).__init__('The image supplied was not a GIF, PNG, or JPG.')
|
||||
|
||||
class PermissionDeniedError(EmoteManagerError):
|
||||
"""Raised when a user tries to modify an emote without the Manage Emojis permission"""
|
||||
|
|
|
@ -68,13 +68,10 @@ def scale_resolution(old_res, new_res):
|
|||
def mime_type_for_image(data):
|
||||
if data.startswith(b'\x89PNG\r\n\x1a\n'):
|
||||
return 'image/png'
|
||||
elif data.startswith(b'\xFF\xD8') and data.rstrip(b'\0').endswith(b'\xFF\xD9'):
|
||||
if data.startswith(b'\xFF\xD8') and data.rstrip(b'\0').endswith(b'\xFF\xD9'):
|
||||
return 'image/jpeg'
|
||||
elif data.startswith((b'GIF87a', b'GIF89a')):
|
||||
if data.startswith((b'GIF87a', b'GIF89a')):
|
||||
return 'image/gif'
|
||||
elif data.startswith(b'RIFF') and data[8:12] == b'WEBP':
|
||||
return 'image/webp'
|
||||
else:
|
||||
raise errors.InvalidImageError
|
||||
|
||||
def image_to_base64_url(data):
|
||||
|
|
Loading…
Reference in a new issue