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 to add an emote from bytes. On error, return a string that should be sent to the user."""
|
||||||
try:
|
try:
|
||||||
emote = await self.create_emote_from_bytes(guild, name, author_id, image_data, reason=reason)
|
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:
|
except discord.HTTPException as ex:
|
||||||
return (
|
return discord.utils.escape_mentions(
|
||||||
'An error occurred while creating the emote:\n'
|
f'{name}: An error occurred while creating the the emote:\n'
|
||||||
+ utils.format_http_exception(ex))
|
+ utils.format_http_exception(ex))
|
||||||
return f'Emote {emote} successfully created.'
|
return f'Emote {emote} successfully created.'
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ class InvalidFileError(EmoteManagerError):
|
||||||
class InvalidImageError(InvalidFileError):
|
class InvalidImageError(InvalidFileError):
|
||||||
"""The image is not a GIF, PNG, or JPG"""
|
"""The image is not a GIF, PNG, or JPG"""
|
||||||
def __init__(self):
|
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):
|
class PermissionDeniedError(EmoteManagerError):
|
||||||
"""Raised when a user tries to modify an emote without the Manage Emojis permission"""
|
"""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):
|
def mime_type_for_image(data):
|
||||||
if data.startswith(b'\x89PNG\r\n\x1a\n'):
|
if data.startswith(b'\x89PNG\r\n\x1a\n'):
|
||||||
return 'image/png'
|
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'
|
return 'image/jpeg'
|
||||||
elif data.startswith((b'GIF87a', b'GIF89a')):
|
if data.startswith((b'GIF87a', b'GIF89a')):
|
||||||
return 'image/gif'
|
return 'image/gif'
|
||||||
elif data.startswith(b'RIFF') and data[8:12] == b'WEBP':
|
|
||||||
return 'image/webp'
|
|
||||||
else:
|
|
||||||
raise errors.InvalidImageError
|
raise errors.InvalidImageError
|
||||||
|
|
||||||
def image_to_base64_url(data):
|
def image_to_base64_url(data):
|
||||||
|
|
Loading…
Reference in a new issue