From 15c85c53db5f387c766ecc712e77b46d2fd2bc4d Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sun, 8 Apr 2018 18:43:41 +0300 Subject: [PATCH 1/4] Bump version --- aiogram/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiogram/__init__.py b/aiogram/__init__.py index 30e8ebd8..49193bed 100644 --- a/aiogram/__init__.py +++ b/aiogram/__init__.py @@ -20,7 +20,7 @@ else: asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) -VERSION = Version(1, 2, 2, stage=Stage.DEV, build=0) +VERSION = Version(1, 2, 3, stage=Stage.DEV, build=0) API_VERSION = Version(3, 6) __version__ = VERSION.version From ca3aa504cf6169966855f3ab7a8e1efe77fced0f Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Mon, 9 Apr 2018 00:30:38 +0300 Subject: [PATCH 2/4] Wow. Fail. Wrong method name. --- aiogram/bot/api.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/aiogram/bot/api.py b/aiogram/bot/api.py index 123c5359..4ef89d68 100644 --- a/aiogram/bot/api.py +++ b/aiogram/bot/api.py @@ -99,17 +99,17 @@ async def _check_result(method_name, response): exceptions.MethodNotKnown.throw() raise exceptions.NotFound(description) elif response.status == HTTPStatus.CONFLICT: - if exceptions.TerminatedByOtherGetUpdates.match(description): + if exceptions.TerminatedByOtherGetUpdates.check(description): exceptions.TerminatedByOtherGetUpdates.throw() - if exceptions.CantGetUpdates.match(description): + if exceptions.CantGetUpdates.check(description): exceptions.CantGetUpdates.throw() raise exceptions.ConflictError(description) elif response.status in [HTTPStatus.UNAUTHORIZED, HTTPStatus.FORBIDDEN]: - if exceptions.BotKicked.match(description): + if exceptions.BotKicked.check(description): exceptions.BotKicked.throw() - elif exceptions.BotBlocked.match(description): + elif exceptions.BotBlocked.check(description): exceptions.BotBlocked.throw() - elif exceptions.UserDeactivated.match(description): + elif exceptions.UserDeactivated.check(description): exceptions.UserDeactivated.throw() raise exceptions.Unauthorized(description) elif response.status == HTTPStatus.REQUEST_ENTITY_TOO_LARGE: From 77867fe109b4034a968039facb7f56ce191b67a2 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Mon, 9 Apr 2018 00:31:28 +0300 Subject: [PATCH 3/4] Use setuptools instead of distutils. (no) --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index be9694df..390a4d79 100755 --- a/setup.py +++ b/setup.py @@ -1,11 +1,10 @@ #!/usr/bin/env python3 import sys -from distutils.core import setup from warnings import warn from pip.req import parse_requirements -from setuptools import PackageFinder +from setuptools import PackageFinder, setup from aiogram import Stage, VERSION @@ -47,6 +46,7 @@ setup( name='aiogram', version=VERSION.version, packages=PackageFinder.find(exclude=('tests', 'tests.*', 'examples.*', 'docs',)), + requires_python='>=3.6', url='https://github.com/aiogram/aiogram', license='MIT', author='Alex Root Junior', From c0fcaa6f456bfd690e26610eb4922d6d2c2e61a7 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Sat, 14 Apr 2018 02:40:16 +0300 Subject: [PATCH 4/4] More API Exceptions. --- aiogram/bot/api.py | 5 +++++ aiogram/utils/exceptions.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/aiogram/bot/api.py b/aiogram/bot/api.py index 4ef89d68..7c4b35b7 100644 --- a/aiogram/bot/api.py +++ b/aiogram/bot/api.py @@ -60,6 +60,7 @@ async def _check_result(method_name, response): description = result_json.get('description') or body + # TODO: refactor the detection of error types if HTTPStatus.OK <= response.status <= HTTPStatus.IM_USED: return result_json.get('result') elif 'retry_after' in result_json: @@ -93,6 +94,8 @@ async def _check_result(method_name, response): exceptions.CantParseUrl.throw() elif exceptions.PhotoAsInputFileRequired.check(description): exceptions.PhotoAsInputFileRequired.throw() + elif exceptions.ToMuchMessages.check(description): + exceptions.ToMuchMessages.throw() raise exceptions.BadRequest(description) elif response.status == HTTPStatus.NOT_FOUND: if exceptions.MethodNotKnown.check(description): @@ -111,6 +114,8 @@ async def _check_result(method_name, response): exceptions.BotBlocked.throw() elif exceptions.UserDeactivated.check(description): exceptions.UserDeactivated.throw() + elif exceptions.CantInitiateConversation.check(description): + exceptions.UserDeactivated.throw() raise exceptions.Unauthorized(description) elif response.status == HTTPStatus.REQUEST_ENTITY_TOO_LARGE: raise exceptions.NetworkError('File too large for uploading. ' diff --git a/aiogram/utils/exceptions.py b/aiogram/utils/exceptions.py index b7bacb1e..7b52091e 100644 --- a/aiogram/utils/exceptions.py +++ b/aiogram/utils/exceptions.py @@ -21,6 +21,7 @@ TelegramAPIError NotFound MethodNotKnown PhotoAsInputFileRequired + ToMuchMessages ConflictError TerminatedByOtherGetUpdates CantGetUpdates @@ -28,6 +29,7 @@ TelegramAPIError BotKicked BotBlocked UserDeactivated + CantInitiateConversation NetworkError RetryAfter MigrateToChat @@ -147,6 +149,13 @@ class PhotoAsInputFileRequired(BadRequest, _MatchErrorMixin): match = 'Photo should be uploaded as an InputFile' +class ToMuchMessages(BadRequest, _MatchErrorMixin): + """ + Will be raised when you try to send media group with more than 10 items. + """ + match = 'Too much messages to send as an album' + + class BadWebhook(BadRequest): pass @@ -203,6 +212,10 @@ class UserDeactivated(Unauthorized, _MatchErrorMixin): match = 'user is deactivated' +class CantInitiateConversation(Unauthorized, _MatchErrorMixin): + match = 'bot can\'t initiate conversation with a user' + + class NetworkError(TelegramAPIError): pass