Merge branch 'dev-1.x' into patch-1

This commit is contained in:
Alex Root Junior 2018-07-09 21:27:45 +03:00 committed by GitHub
commit c73975a2df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 25 additions and 34 deletions

View file

@ -10,5 +10,5 @@ except ImportError:
else: else:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
__version__ = '1.3.2' __version__ = '1.3.3.dev1'
__api_version__ = '3.6' __api_version__ = '3.6'

View file

@ -238,12 +238,7 @@ class ExceptionsFilter(Filter):
self.exception = exception self.exception = exception
def check(self, dispatcher, update, exception): def check(self, dispatcher, update, exception):
try: return isinstance(exception, self.exception)
raise exception
except self.exception:
return True
except:
return False
def generate_default_filters(dispatcher, *args, **kwargs): def generate_default_filters(dispatcher, *args, **kwargs):

View file

@ -37,9 +37,9 @@ class Message(base.TelegramObject):
forward_from_chat: Chat = fields.Field(base=Chat) forward_from_chat: Chat = fields.Field(base=Chat)
forward_from_message_id: base.Integer = fields.Field() forward_from_message_id: base.Integer = fields.Field()
forward_signature: base.String = fields.Field() forward_signature: base.String = fields.Field()
forward_date: base.Integer = fields.Field() forward_date: datetime.datetime = fields.DateTimeField()
reply_to_message: 'Message' = fields.Field(base='Message') reply_to_message: 'Message' = fields.Field(base='Message')
edit_date: base.Integer = fields.Field() edit_date: datetime.datetime = fields.DateTimeField()
media_group_id: base.String = fields.Field() media_group_id: base.String = fields.Field()
author_signature: base.String = fields.Field() author_signature: base.String = fields.Field()
text: base.String = fields.Field() text: base.String = fields.Field()

View file

@ -1,12 +1,9 @@
import babel
from . import base from . import base
from . import fields from . import fields
from ..utils import markdown from ..utils import markdown
try:
import babel
except ImportError:
babel = None
class User(base.TelegramObject): class User(base.TelegramObject):
""" """
@ -46,15 +43,12 @@ class User(base.TelegramObject):
return self.full_name return self.full_name
@property @property
def locale(self) -> 'babel.core.Locale' or None: def locale(self) -> babel.core.Locale or None:
""" """
This property requires `Babel <https://pypi.python.org/pypi/Babel>`_ module Get user's locale
:return: :class:`babel.core.Locale` :return: :class:`babel.core.Locale`
:raise: ImportError: when babel is not installed.
""" """
if not babel:
raise ImportError('Babel is not installed!')
if not self.language_code: if not self.language_code:
return None return None
if not hasattr(self, '_locale'): if not hasattr(self, '_locale'):

View file

@ -54,5 +54,5 @@ def prepare_arg(value):
now = datetime.datetime.now() now = datetime.datetime.now()
return int((now + value).timestamp()) return int((now + value).timestamp())
elif isinstance(value, datetime.datetime): elif isinstance(value, datetime.datetime):
return int(value.timestamp()) return round(value.timestamp())
return value return value

View file

@ -10,11 +10,11 @@ BUILDDIR = build
# Put it first so that "make" without argument is like "make help". # Put it first so that "make" without argument is like "make help".
help: help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile .PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new # Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile %: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

View file

@ -8,9 +8,9 @@ At first you have to import all necessary modules
.. code-block:: python3 .. code-block:: python3
from aiogram import Bot, types from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor from aiogram.utils import executor
Then you have to initialize bot and dispatcher instances. Then you have to initialize bot and dispatcher instances.
Bot token you can get from `@BotFather <https://t.me/BotFather>`_ Bot token you can get from `@BotFather <https://t.me/BotFather>`_
@ -18,8 +18,8 @@ Bot token you can get from `@BotFather <https://t.me/BotFather>`_
.. code-block:: python3 .. code-block:: python3
bot = Bot(token='BOT TOKEN HERE') bot = Bot(token='BOT TOKEN HERE')
dp = Dispatcher(bot) dp = Dispatcher(bot)
Next step: interaction with bots starts with one command. Register your first command handler: Next step: interaction with bots starts with one command. Register your first command handler:
@ -41,12 +41,12 @@ Summary
.. code-block:: python3 .. code-block:: python3
from aiogram import Bot, types from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor from aiogram.utils import executor
bot = Bot(token='BOT TOKEN HERE') bot = Bot(token='BOT TOKEN HERE')
dp = Dispatcher(bot) dp = Dispatcher(bot)
@dp.message_handler(commands=['start', 'help']) @dp.message_handler(commands=['start', 'help'])
async def send_welcome(message: types.Message): async def send_welcome(message: types.Message):

View file

@ -23,7 +23,7 @@ def get_users():
yield from (61043901, 78238238, 78378343, 98765431, 12345678) yield from (61043901, 78238238, 78378343, 98765431, 12345678)
async def send_message(user_id: int, text: str) -> bool: async def send_message(user_id: int, text: str, disable_notification: bool = False) -> bool:
""" """
Safe messages sender Safe messages sender
@ -32,7 +32,7 @@ async def send_message(user_id: int, text: str) -> bool:
:return: :return:
""" """
try: try:
await bot.send_message(user_id, '<b>Hello, World!</b>') await bot.send_message(user_id, text, disable_notification=disable_notification)
except exceptions.BotBlocked: except exceptions.BotBlocked:
log.error(f"Target [ID:{user_id}]: blocked by user") log.error(f"Target [ID:{user_id}]: blocked by user")
except exceptions.ChatNotFound: except exceptions.ChatNotFound:
@ -41,6 +41,8 @@ async def send_message(user_id: int, text: str) -> bool:
log.error(f"Target [ID:{user_id}]: Flood limit is exceeded. Sleep {e.timeout} seconds.") log.error(f"Target [ID:{user_id}]: Flood limit is exceeded. Sleep {e.timeout} seconds.")
await asyncio.sleep(e.timeout) await asyncio.sleep(e.timeout)
return await send_message(user_id, text) # Recursive call return await send_message(user_id, text) # Recursive call
except exceptions.UserDeactivated:
log.error(f"Target [ID:{user_id}]: user is deactivated")
except exceptions.TelegramAPIError: except exceptions.TelegramAPIError:
log.exception(f"Target [ID:{user_id}]: failed") log.exception(f"Target [ID:{user_id}]: failed")
else: else: