2018-03-30 19:32:23 +03:00
|
|
|
"""
|
|
|
|
|
TelegramAPIError
|
|
|
|
|
ValidationError
|
|
|
|
|
Throttled
|
|
|
|
|
BadRequest
|
|
|
|
|
MessageError
|
|
|
|
|
MessageNotModified
|
|
|
|
|
MessageToForwardNotFound
|
|
|
|
|
MessageToDeleteNotFound
|
|
|
|
|
MessageIdentifierNotSpecified
|
2018-05-02 18:09:01 +03:00
|
|
|
MessageTextIsEmpty
|
2018-07-15 21:49:53 +03:00
|
|
|
MessageCantBeEdited
|
2018-07-31 11:51:03 +03:00
|
|
|
MessageCantBeDeleted
|
2018-07-15 21:49:53 +03:00
|
|
|
MessageToEditNotFound
|
2018-05-04 13:47:02 +03:00
|
|
|
ToMuchMessages
|
2018-07-15 21:49:53 +03:00
|
|
|
ObjectExpectedAsReplyMarkup
|
|
|
|
|
InlineKeyboardExpected
|
2018-03-30 19:32:23 +03:00
|
|
|
ChatNotFound
|
2018-07-15 21:49:53 +03:00
|
|
|
ChatDescriptionIsNotModified
|
2018-03-30 19:32:23 +03:00
|
|
|
InvalidQueryID
|
|
|
|
|
InvalidPeerID
|
|
|
|
|
InvalidHTTPUrlContent
|
2018-05-27 21:49:52 +03:00
|
|
|
ButtonURLInvalid
|
|
|
|
|
URLHostIsEmpty
|
|
|
|
|
StartParamInvalid
|
|
|
|
|
ButtonDataInvalid
|
2018-03-30 19:32:23 +03:00
|
|
|
WrongFileIdentifier
|
|
|
|
|
GroupDeactivated
|
|
|
|
|
BadWebhook
|
|
|
|
|
WebhookRequireHTTPS
|
|
|
|
|
BadWebhookPort
|
2018-05-11 02:00:32 +03:00
|
|
|
BadWebhookAddrInfo
|
2018-03-30 19:32:23 +03:00
|
|
|
CantParseUrl
|
|
|
|
|
NotFound
|
|
|
|
|
MethodNotKnown
|
2018-04-08 18:16:52 +03:00
|
|
|
PhotoAsInputFileRequired
|
2018-04-16 00:36:14 +03:00
|
|
|
InvalidStickersSet
|
2018-07-15 21:49:53 +03:00
|
|
|
NoStickerInRequest
|
2018-04-22 22:02:58 +03:00
|
|
|
ChatAdminRequired
|
2018-07-15 21:49:53 +03:00
|
|
|
NotEnoughRightsToPinMessage
|
|
|
|
|
CantDemoteChatCreator
|
2018-05-26 01:13:04 +03:00
|
|
|
CantRestrictSelf
|
2018-05-02 17:02:20 +03:00
|
|
|
PhotoDimensions
|
|
|
|
|
UnavailableMembers
|
|
|
|
|
TypeOfFileMismatch
|
2018-07-15 21:49:53 +03:00
|
|
|
WrongRemoteFileIdSpecified
|
|
|
|
|
PaymentProviderInvalid
|
|
|
|
|
CurrencyTotalAmountInvalid
|
|
|
|
|
CantParseUrl
|
|
|
|
|
CantParseEntities
|
2018-03-30 19:32:23 +03:00
|
|
|
ConflictError
|
|
|
|
|
TerminatedByOtherGetUpdates
|
|
|
|
|
CantGetUpdates
|
|
|
|
|
Unauthorized
|
|
|
|
|
BotKicked
|
|
|
|
|
BotBlocked
|
|
|
|
|
UserDeactivated
|
2018-04-14 02:40:16 +03:00
|
|
|
CantInitiateConversation
|
2018-07-15 21:49:53 +03:00
|
|
|
CantTalkWithBots
|
2018-03-30 19:32:23 +03:00
|
|
|
NetworkError
|
|
|
|
|
RetryAfter
|
|
|
|
|
MigrateToChat
|
2018-05-11 02:00:32 +03:00
|
|
|
RestartingTelegram
|
2018-03-30 19:32:23 +03:00
|
|
|
|
|
|
|
|
AIOGramWarning
|
|
|
|
|
TimeoutWarning
|
|
|
|
|
"""
|
2017-12-02 01:03:56 +02:00
|
|
|
import time
|
|
|
|
|
|
2018-05-27 21:49:52 +03:00
|
|
|
# TODO: Use exceptions detector from `aiograph`.
|
|
|
|
|
|
2018-03-30 19:32:23 +03:00
|
|
|
_PREFIXES = ['Error: ', '[Error]: ', 'Bad Request: ', 'Conflict: ', 'Not Found: ']
|
2017-08-15 05:48:56 +03:00
|
|
|
|
|
|
|
|
|
2017-08-11 05:58:27 +03:00
|
|
|
def _clean_message(text):
|
2017-08-15 05:48:56 +03:00
|
|
|
for prefix in _PREFIXES:
|
|
|
|
|
if text.startswith(prefix):
|
|
|
|
|
text = text[len(prefix):]
|
2017-08-22 20:28:22 +03:00
|
|
|
return (text[0].upper() + text[1:]).strip()
|
2017-07-25 02:52:20 +03:00
|
|
|
|
|
|
|
|
|
2017-08-11 05:58:27 +03:00
|
|
|
class TelegramAPIError(Exception):
|
2018-03-30 19:32:23 +03:00
|
|
|
def __init__(self, message=None):
|
2017-08-11 05:58:27 +03:00
|
|
|
super(TelegramAPIError, self).__init__(_clean_message(message))
|
|
|
|
|
|
|
|
|
|
|
2018-03-30 19:32:23 +03:00
|
|
|
class _MatchErrorMixin:
|
|
|
|
|
match = ''
|
|
|
|
|
text = None
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
__subclasses = []
|
|
|
|
|
|
|
|
|
|
def __init_subclass__(cls, **kwargs):
|
|
|
|
|
super(_MatchErrorMixin, cls).__init_subclass__(**kwargs)
|
|
|
|
|
# cls.match = cls.match.lower() if cls.match else ''
|
|
|
|
|
if not hasattr(cls, f"_{cls.__name__}__group"):
|
|
|
|
|
cls.__subclasses.append(cls)
|
|
|
|
|
|
2018-03-30 19:32:23 +03:00
|
|
|
@classmethod
|
2018-05-02 18:08:36 +03:00
|
|
|
def check(cls, message) -> bool:
|
|
|
|
|
"""
|
|
|
|
|
Compare pattern with message
|
|
|
|
|
|
|
|
|
|
:param message: always must be in lowercase
|
|
|
|
|
:return: bool
|
|
|
|
|
"""
|
|
|
|
|
return cls.match.lower() in message
|
2018-03-30 19:32:23 +03:00
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
@classmethod
|
|
|
|
|
def detect(cls, description):
|
|
|
|
|
description = description.lower()
|
|
|
|
|
for err in cls.__subclasses:
|
|
|
|
|
if err is cls:
|
|
|
|
|
continue
|
|
|
|
|
if err.check(description):
|
2018-07-15 21:49:53 +03:00
|
|
|
raise err(cls.text or description)
|
2018-05-02 18:08:36 +03:00
|
|
|
raise cls(description)
|
|
|
|
|
|
2018-03-30 19:32:23 +03:00
|
|
|
|
2017-08-23 22:23:57 +03:00
|
|
|
class AIOGramWarning(Warning):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TimeoutWarning(AIOGramWarning):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2018-03-30 19:32:23 +03:00
|
|
|
class FSMStorageWarning(AIOGramWarning):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2017-08-11 05:58:27 +03:00
|
|
|
class ValidationError(TelegramAPIError):
|
2017-05-19 21:20:59 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class BadRequest(TelegramAPIError, _MatchErrorMixin):
|
|
|
|
|
__group = True
|
2017-08-11 05:58:27 +03:00
|
|
|
|
|
|
|
|
|
2018-03-30 19:32:23 +03:00
|
|
|
class MessageError(BadRequest):
|
2018-05-02 18:08:36 +03:00
|
|
|
__group = True
|
2018-03-30 19:32:23 +03:00
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class MessageNotModified(MessageError):
|
2018-04-08 18:16:52 +03:00
|
|
|
"""
|
|
|
|
|
Will be raised when you try to set new text is equals to current text.
|
|
|
|
|
"""
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'message is not modified'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class MessageToForwardNotFound(MessageError):
|
2018-04-08 18:16:52 +03:00
|
|
|
"""
|
|
|
|
|
Will be raised when you try to forward very old or deleted or unknown message.
|
|
|
|
|
"""
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'message to forward not found'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class MessageToDeleteNotFound(MessageError):
|
2018-04-08 18:16:52 +03:00
|
|
|
"""
|
|
|
|
|
Will be raised when you try to delete very old or deleted or unknown message.
|
|
|
|
|
"""
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'message to delete not found'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class MessageIdentifierNotSpecified(MessageError):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'message identifier is not specified'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:09:01 +03:00
|
|
|
class MessageTextIsEmpty(MessageError):
|
|
|
|
|
match = 'Message text is empty'
|
|
|
|
|
|
|
|
|
|
|
2018-07-15 21:49:53 +03:00
|
|
|
class MessageCantBeEdited(MessageError):
|
|
|
|
|
match = 'message can\'t be edited'
|
2018-07-31 11:51:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class MessageCantBeDeleted(MessageError):
|
|
|
|
|
match = 'message can\'t be deleted'
|
2018-07-15 21:49:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class MessageToEditNotFound(MessageError):
|
|
|
|
|
match = 'message to edit not found'
|
|
|
|
|
|
|
|
|
|
|
2018-06-25 03:55:52 +03:00
|
|
|
class MessageIsTooLong(MessageError):
|
|
|
|
|
match = 'message is too long'
|
|
|
|
|
|
|
|
|
|
|
2018-05-04 13:47:02 +03:00
|
|
|
class ToMuchMessages(MessageError):
|
|
|
|
|
"""
|
|
|
|
|
Will be raised when you try to send media group with more than 10 items.
|
|
|
|
|
"""
|
|
|
|
|
match = 'Too much messages to send as an album'
|
|
|
|
|
|
|
|
|
|
|
2018-07-15 21:49:53 +03:00
|
|
|
class ObjectExpectedAsReplyMarkup(BadRequest):
|
|
|
|
|
match = 'object expected as reply markup'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class InlineKeyboardExpected(BadRequest):
|
|
|
|
|
match = 'inline keyboard expected'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:09:01 +03:00
|
|
|
class ChatNotFound(BadRequest):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'chat not found'
|
|
|
|
|
|
|
|
|
|
|
2018-07-15 21:49:53 +03:00
|
|
|
class ChatDescriptionIsNotModified(BadRequest):
|
|
|
|
|
match = 'chat description is not modified'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class InvalidQueryID(BadRequest):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'QUERY_ID_INVALID'
|
|
|
|
|
text = 'Invalid query ID'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class InvalidPeerID(BadRequest):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'PEER_ID_INVALID'
|
|
|
|
|
text = 'Invalid peer ID'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class InvalidHTTPUrlContent(BadRequest):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'Failed to get HTTP URL content'
|
|
|
|
|
|
|
|
|
|
|
2018-05-27 21:49:52 +03:00
|
|
|
class ButtonURLInvalid(BadRequest):
|
|
|
|
|
match = 'BUTTON_URL_INVALID'
|
|
|
|
|
text = 'Button URL invalid'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class URLHostIsEmpty(BadRequest):
|
|
|
|
|
match = 'URL host is empty'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StartParamInvalid(BadRequest):
|
|
|
|
|
match = 'START_PARAM_INVALID'
|
|
|
|
|
text = 'Start param invalid'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ButtonDataInvalid(BadRequest):
|
|
|
|
|
match = 'BUTTON_DATA_INVALID'
|
|
|
|
|
text = 'Button data invalid'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class WrongFileIdentifier(BadRequest):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'wrong file identifier/HTTP URL specified'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class GroupDeactivated(BadRequest):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'group is deactivated'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class PhotoAsInputFileRequired(BadRequest):
|
2018-04-08 18:16:52 +03:00
|
|
|
"""
|
|
|
|
|
Will be raised when you try to set chat photo from file ID.
|
|
|
|
|
"""
|
2018-04-08 17:31:58 +03:00
|
|
|
match = 'Photo should be uploaded as an InputFile'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class InvalidStickersSet(BadRequest):
|
2018-04-16 00:36:14 +03:00
|
|
|
match = 'STICKERSET_INVALID'
|
|
|
|
|
text = 'Stickers set is invalid'
|
|
|
|
|
|
|
|
|
|
|
2018-07-15 21:49:53 +03:00
|
|
|
class NoStickerInRequest(BadRequest):
|
|
|
|
|
match = 'there is no sticker in the request'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class ChatAdminRequired(BadRequest):
|
2018-04-22 22:02:58 +03:00
|
|
|
match = 'CHAT_ADMIN_REQUIRED'
|
|
|
|
|
text = 'Admin permissions is required!'
|
|
|
|
|
|
2018-05-27 21:49:52 +03:00
|
|
|
|
2018-07-15 21:49:53 +03:00
|
|
|
class NotEnoughRightsToPinMessage(BadRequest):
|
|
|
|
|
match = 'not enough rights to pin a message'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CantDemoteChatCreator(BadRequest):
|
|
|
|
|
match = 'can\'t demote chat creator'
|
|
|
|
|
|
|
|
|
|
|
2018-05-26 01:13:04 +03:00
|
|
|
class CantRestrictSelf(BadRequest):
|
|
|
|
|
match = "can't restrict self"
|
|
|
|
|
text = "Admin can't restrict self."
|
2018-04-22 22:02:58 +03:00
|
|
|
|
2018-05-27 21:49:52 +03:00
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class PhotoDimensions(BadRequest):
|
2018-05-02 17:02:20 +03:00
|
|
|
match = 'PHOTO_INVALID_DIMENSIONS'
|
|
|
|
|
text = 'Invalid photo dimensions'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class UnavailableMembers(BadRequest):
|
2018-05-02 17:02:20 +03:00
|
|
|
match = 'supergroup members are unavailable'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class TypeOfFileMismatch(BadRequest):
|
2018-05-02 17:02:20 +03:00
|
|
|
match = 'type of file mismatch'
|
|
|
|
|
|
|
|
|
|
|
2018-07-15 21:49:53 +03:00
|
|
|
class WrongRemoteFileIdSpecified(BadRequest):
|
|
|
|
|
match = 'wrong remote file id specified'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PaymentProviderInvalid(BadRequest):
|
|
|
|
|
match = 'PAYMENT_PROVIDER_INVALID'
|
|
|
|
|
text = 'payment provider invalid'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CurrencyTotalAmountInvalid(BadRequest):
|
|
|
|
|
match = 'currency_total_amount_invalid'
|
|
|
|
|
text = 'currency total amount invalid'
|
|
|
|
|
|
|
|
|
|
|
2018-03-30 19:32:23 +03:00
|
|
|
class BadWebhook(BadRequest):
|
2018-05-02 18:08:36 +03:00
|
|
|
__group = True
|
2018-03-30 19:32:23 +03:00
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class WebhookRequireHTTPS(BadWebhook):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'HTTPS url must be provided for webhook'
|
|
|
|
|
text = 'bad webhook: ' + match
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class BadWebhookPort(BadWebhook):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'Webhook can be set up only on ports 80, 88, 443 or 8443'
|
|
|
|
|
text = 'bad webhook: ' + match
|
|
|
|
|
|
|
|
|
|
|
2018-05-11 02:00:32 +03:00
|
|
|
class BadWebhookAddrInfo(BadWebhook):
|
|
|
|
|
match = 'getaddrinfo: Temporary failure in name resolution'
|
|
|
|
|
text = 'bad webhook: ' + match
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class CantParseUrl(BadRequest):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'can\'t parse URL'
|
|
|
|
|
|
|
|
|
|
|
2018-07-15 21:49:53 +03:00
|
|
|
class CantParseEntities(BadRequest):
|
|
|
|
|
match = 'can\'t parse entities'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class NotFound(TelegramAPIError, _MatchErrorMixin):
|
|
|
|
|
__group = True
|
2018-03-30 19:32:23 +03:00
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class MethodNotKnown(NotFound):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'method not found'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class ConflictError(TelegramAPIError, _MatchErrorMixin):
|
|
|
|
|
__group = True
|
2017-08-22 20:28:22 +03:00
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class TerminatedByOtherGetUpdates(ConflictError):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'terminated by other getUpdates request'
|
|
|
|
|
text = 'Terminated by other getUpdates request; ' \
|
|
|
|
|
'Make sure that only one bot instance is running'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class CantGetUpdates(ConflictError):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'can\'t use getUpdates method while webhook is active'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class Unauthorized(TelegramAPIError, _MatchErrorMixin):
|
|
|
|
|
__group = True
|
2017-08-11 05:58:27 +03:00
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class BotKicked(Unauthorized):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'Bot was kicked from a chat'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class BotBlocked(Unauthorized):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'bot was blocked by the user'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class UserDeactivated(Unauthorized):
|
2018-03-30 19:32:23 +03:00
|
|
|
match = 'user is deactivated'
|
|
|
|
|
|
|
|
|
|
|
2018-05-02 18:08:36 +03:00
|
|
|
class CantInitiateConversation(Unauthorized):
|
2018-04-14 02:40:16 +03:00
|
|
|
match = 'bot can\'t initiate conversation with a user'
|
|
|
|
|
|
|
|
|
|
|
2018-07-15 21:49:53 +03:00
|
|
|
class CantTalkWithBots(Unauthorized):
|
|
|
|
|
match = 'bot can\'t send messages to bots'
|
|
|
|
|
|
|
|
|
|
|
2017-08-11 05:58:27 +03:00
|
|
|
class NetworkError(TelegramAPIError):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2018-05-11 02:00:32 +03:00
|
|
|
class RestartingTelegram(TelegramAPIError):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super(RestartingTelegram, self).__init__('The Telegram Bot API service is restarting. Wait few second.')
|
|
|
|
|
|
|
|
|
|
|
2017-08-11 05:58:27 +03:00
|
|
|
class RetryAfter(TelegramAPIError):
|
|
|
|
|
def __init__(self, retry_after):
|
2017-08-14 22:16:41 +03:00
|
|
|
super(RetryAfter, self).__init__(f"Flood control exceeded. Retry in {retry_after} seconds.")
|
2017-08-11 05:58:27 +03:00
|
|
|
self.timeout = retry_after
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MigrateToChat(TelegramAPIError):
|
|
|
|
|
def __init__(self, chat_id):
|
2017-08-14 22:16:41 +03:00
|
|
|
super(MigrateToChat, self).__init__(f"The group has been migrated to a supergroup. New id: {chat_id}.")
|
2017-08-11 05:58:27 +03:00
|
|
|
self.migrate_to_chat_id = chat_id
|
2017-12-02 01:03:56 +02:00
|
|
|
|
|
|
|
|
|
2018-03-30 19:32:23 +03:00
|
|
|
class Throttled(TelegramAPIError):
|
2017-12-02 01:03:56 +02:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
|
from ..dispatcher.storage import DELTA, EXCEEDED_COUNT, KEY, LAST_CALL, RATE_LIMIT, RESULT
|
|
|
|
|
self.key = kwargs.pop(KEY, '<None>')
|
|
|
|
|
self.called_at = kwargs.pop(LAST_CALL, time.time())
|
|
|
|
|
self.rate = kwargs.pop(RATE_LIMIT, None)
|
|
|
|
|
self.result = kwargs.pop(RESULT, False)
|
|
|
|
|
self.exceeded_count = kwargs.pop(EXCEEDED_COUNT, 0)
|
|
|
|
|
self.delta = kwargs.pop(DELTA, 0)
|
|
|
|
|
self.user = kwargs.pop('user', None)
|
|
|
|
|
self.chat = kwargs.pop('chat', None)
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return f"Rate limit exceeded! (Limit: {self.rate} s, " \
|
|
|
|
|
f"exceeded: {self.exceeded_count}, " \
|
|
|
|
|
f"time delta: {round(self.delta, 3)} s)"
|