mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-16 04:05:47 +00:00
Merge branch 'dev-1.x'
# Conflicts: # aiogram/__init__.py
This commit is contained in:
commit
1e03e6f80a
4 changed files with 26 additions and 8 deletions
|
|
@ -20,7 +20,7 @@ else:
|
|||
|
||||
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
|
||||
|
||||
VERSION = Version(1, 2, 2, stage=Stage.FINAL, build=0)
|
||||
VERSION = Version(1, 2, 3, stage=Stage.FINAL, build=0)
|
||||
API_VERSION = Version(3, 6)
|
||||
|
||||
__version__ = VERSION.version
|
||||
|
|
|
|||
|
|
@ -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,23 +94,27 @@ 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):
|
||||
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()
|
||||
elif exceptions.CantInitiateConversation.check(description):
|
||||
exceptions.UserDeactivated.throw()
|
||||
raise exceptions.Unauthorized(description)
|
||||
elif response.status == HTTPStatus.REQUEST_ENTITY_TOO_LARGE:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
4
setup.py
4
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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue