2020-05-12 23:55:08 +00:00
|
|
|
|
# © 2018–2020 io mintz <io@mintz.cc>
|
|
|
|
|
#
|
|
|
|
|
# Emote Manager is free software: you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# Emote Manager is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
# along with Emote Manager. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
2019-06-10 23:42:44 +00:00
|
|
|
|
import asyncio
|
2018-07-30 04:34:27 +00:00
|
|
|
|
|
2018-07-31 07:38:14 +00:00
|
|
|
|
from discord.ext import commands
|
2018-07-30 04:34:27 +00:00
|
|
|
|
|
2018-07-31 07:38:14 +00:00
|
|
|
|
import utils
|
2018-07-30 04:34:27 +00:00
|
|
|
|
|
2018-07-31 07:38:14 +00:00
|
|
|
|
class MissingManageEmojisPermission(commands.MissingPermissions):
|
|
|
|
|
"""The invoker or the bot doesn't have permissions to manage server emojis."""
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(Exception, self).__init__(
|
2018-08-22 15:27:35 +00:00
|
|
|
|
f'{utils.SUCCESS_EMOJIS[False]} '
|
2018-07-31 07:38:14 +00:00
|
|
|
|
"Sorry, you don't have enough permissions to run this command. "
|
|
|
|
|
'You and I both need the Manage Emojis permission.')
|
|
|
|
|
|
|
|
|
|
class EmoteManagerError(commands.CommandError):
|
2018-07-30 04:34:27 +00:00
|
|
|
|
"""Generic error with the bot. This can be used to catch all bot errors."""
|
|
|
|
|
pass
|
|
|
|
|
|
2019-10-10 00:24:12 +00:00
|
|
|
|
class ImageProcessingTimeoutError(EmoteManagerError, asyncio.TimeoutError):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
class ImageResizeTimeoutError(ImageProcessingTimeoutError):
|
2019-06-10 23:42:44 +00:00
|
|
|
|
"""Resizing the image took too long."""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__('Error: resizing the image took too long.')
|
|
|
|
|
|
2019-10-10 00:24:12 +00:00
|
|
|
|
class ImageConversionTimeoutError(ImageProcessingTimeoutError):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__('Error: converting the image to a GIF took too long.')
|
|
|
|
|
|
2018-07-30 04:42:27 +00:00
|
|
|
|
class HTTPException(EmoteManagerError):
|
2018-07-30 04:34:27 +00:00
|
|
|
|
"""The server did not respond with an OK status code."""
|
|
|
|
|
def __init__(self, status):
|
|
|
|
|
super().__init__(f'URL error: server returned error code {status}')
|
|
|
|
|
|
2018-07-30 04:42:27 +00:00
|
|
|
|
class EmoteNotFoundError(EmoteManagerError):
|
|
|
|
|
"""An emote with that name was not found"""
|
2018-07-30 04:34:27 +00:00
|
|
|
|
def __init__(self, name):
|
2018-07-30 04:42:27 +00:00
|
|
|
|
super().__init__(f'An emote called `{name}` does not exist in this server.')
|
2018-07-30 04:34:27 +00:00
|
|
|
|
|
2019-08-04 10:15:15 +00:00
|
|
|
|
class FileTooBigError(EmoteManagerError):
|
|
|
|
|
def __init__(self, size, limit):
|
|
|
|
|
self.size = size
|
|
|
|
|
self.limit = limit
|
|
|
|
|
|
|
|
|
|
class InvalidFileError(EmoteManagerError):
|
2020-05-18 02:03:31 +00:00
|
|
|
|
"""The file is not a zip, tar, GIF, PNG, JPG, or WEBP file."""
|
2018-07-30 04:34:27 +00:00
|
|
|
|
def __init__(self):
|
2019-08-04 10:15:15 +00:00
|
|
|
|
super().__init__('Invalid file given.')
|
2018-07-30 04:34:27 +00:00
|
|
|
|
|
2019-08-04 10:15:15 +00:00
|
|
|
|
class InvalidImageError(InvalidFileError):
|
|
|
|
|
"""The image is not a GIF, PNG, or JPG"""
|
2018-07-30 04:34:27 +00:00
|
|
|
|
def __init__(self):
|
2020-05-18 02:03:31 +00:00
|
|
|
|
super(Exception, self).__init__('The image supplied was not a GIF, PNG, JPG, or WEBP file.')
|
2018-07-30 04:34:27 +00:00
|
|
|
|
|
2018-07-30 04:42:27 +00:00
|
|
|
|
class PermissionDeniedError(EmoteManagerError):
|
|
|
|
|
"""Raised when a user tries to modify an emote without the Manage Emojis permission"""
|
2018-07-30 04:34:27 +00:00
|
|
|
|
def __init__(self, name):
|
|
|
|
|
super().__init__(f"You're not authorized to modify `{name}`.")
|
|
|
|
|
|
|
|
|
|
class DiscordError(Exception):
|
|
|
|
|
"""Usually raised when the client cache is being baka"""
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__('Discord seems to be having issues right now, please try again later.')
|