diff --git a/aiogram/__init__.py b/aiogram/__init__.py index 96b5a36c..ad97a44a 100644 --- a/aiogram/__init__.py +++ b/aiogram/__init__.py @@ -10,5 +10,5 @@ except ImportError: else: asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) -__version__ = '1.3.2' +__version__ = '1.3.3.dev1' __api_version__ = '3.6' diff --git a/aiogram/dispatcher/filters.py b/aiogram/dispatcher/filters.py index 96ee47b0..fb3f04a0 100644 --- a/aiogram/dispatcher/filters.py +++ b/aiogram/dispatcher/filters.py @@ -238,12 +238,7 @@ class ExceptionsFilter(Filter): self.exception = exception def check(self, dispatcher, update, exception): - try: - raise exception - except self.exception: - return True - except: - return False + return isinstance(exception, self.exception) def generate_default_filters(dispatcher, *args, **kwargs): diff --git a/aiogram/types/message.py b/aiogram/types/message.py index 61f6188f..459091ee 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -37,9 +37,9 @@ class Message(base.TelegramObject): forward_from_chat: Chat = fields.Field(base=Chat) forward_from_message_id: base.Integer = 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') - edit_date: base.Integer = fields.Field() + edit_date: datetime.datetime = fields.DateTimeField() media_group_id: base.String = fields.Field() author_signature: base.String = fields.Field() text: base.String = fields.Field() diff --git a/aiogram/types/user.py b/aiogram/types/user.py index d27f2f87..c4c64844 100644 --- a/aiogram/types/user.py +++ b/aiogram/types/user.py @@ -1,12 +1,9 @@ +import babel + from . import base from . import fields from ..utils import markdown -try: - import babel -except ImportError: - babel = None - class User(base.TelegramObject): """ @@ -46,15 +43,12 @@ class User(base.TelegramObject): return self.full_name @property - def locale(self) -> 'babel.core.Locale' or None: + def locale(self) -> babel.core.Locale or None: """ - This property requires `Babel `_ module + Get user's 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: return None if not hasattr(self, '_locale'): diff --git a/aiogram/utils/payload.py b/aiogram/utils/payload.py index 277573c9..dac43492 100644 --- a/aiogram/utils/payload.py +++ b/aiogram/utils/payload.py @@ -54,5 +54,5 @@ def prepare_arg(value): now = datetime.datetime.now() return int((now + value).timestamp()) elif isinstance(value, datetime.datetime): - return int(value.timestamp()) + return round(value.timestamp()) return value diff --git a/docs/Makefile b/docs/Makefile index 4e50ed99..d4bd90d4 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -10,11 +10,11 @@ BUILDDIR = build # Put it first so that "make" without argument is like "make help". help: - @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) .PHONY: help Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file diff --git a/docs/source/quick_start.rst b/docs/source/quick_start.rst index bb052bb5..c05f0ca1 100644 --- a/docs/source/quick_start.rst +++ b/docs/source/quick_start.rst @@ -8,9 +8,9 @@ At first you have to import all necessary modules .. code-block:: python3 - from aiogram import Bot, types - from aiogram.dispatcher import Dispatcher - from aiogram.utils import executor + from aiogram import Bot, types + from aiogram.dispatcher import Dispatcher + from aiogram.utils import executor Then you have to initialize bot and dispatcher instances. Bot token you can get from `@BotFather `_ @@ -18,8 +18,8 @@ Bot token you can get from `@BotFather `_ .. code-block:: python3 - bot = Bot(token='BOT TOKEN HERE') - dp = Dispatcher(bot) + bot = Bot(token='BOT TOKEN HERE') + dp = Dispatcher(bot) Next step: interaction with bots starts with one command. Register your first command handler: @@ -41,12 +41,12 @@ Summary .. code-block:: python3 - from aiogram import Bot, types - from aiogram.dispatcher import Dispatcher - from aiogram.utils import executor + from aiogram import Bot, types + from aiogram.dispatcher import Dispatcher + from aiogram.utils import executor - bot = Bot(token='BOT TOKEN HERE') - dp = Dispatcher(bot) + bot = Bot(token='BOT TOKEN HERE') + dp = Dispatcher(bot) @dp.message_handler(commands=['start', 'help']) async def send_welcome(message: types.Message): diff --git a/examples/broadcast_example.py b/examples/broadcast_example.py index 468da916..40ba5e0c 100644 --- a/examples/broadcast_example.py +++ b/examples/broadcast_example.py @@ -23,7 +23,7 @@ def get_users(): 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 @@ -32,7 +32,7 @@ async def send_message(user_id: int, text: str) -> bool: :return: """ try: - await bot.send_message(user_id, 'Hello, World!') + await bot.send_message(user_id, text, disable_notification=disable_notification) except exceptions.BotBlocked: log.error(f"Target [ID:{user_id}]: blocked by user") 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.") await asyncio.sleep(e.timeout) 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: log.exception(f"Target [ID:{user_id}]: failed") else: