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 6ed0a7f9..e4f3e4b1 100644 --- a/aiogram/types/message.py +++ b/aiogram/types/message.py @@ -39,9 +39,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() @@ -69,7 +69,7 @@ class Message(base.TelegramObject): channel_chat_created: base.Boolean = fields.Field() migrate_to_chat_id: base.Integer = fields.Field() migrate_from_chat_id: base.Integer = fields.Field() - pinned_message: 'Message' = fields.Field(base='Message') + pinned_message: Message = fields.Field(base='Message') invoice: Invoice = fields.Field(base=Invoice) successful_payment: SuccessfulPayment = fields.Field(base=SuccessfulPayment) connected_website: 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 9f35c45a..6ce619be 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,39 +18,39 @@ 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: .. code-block:: python3 - @dp.message_handler(commands=['start', 'help']) - async def send_welcome(message: types.Message): - await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.") + @dp.message_handler(commands=['start', 'help']) + async def send_welcome(message: types.Message): + await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.") Last step: run long polling. .. code-block:: python3 - if __name__ == '__main__': - executor.start_polling(dp) + if __name__ == '__main__': + executor.start_polling(dp) 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): - await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.") + @dp.message_handler(commands=['start', 'help']) + async def send_welcome(message: types.Message): + await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.") - if __name__ == '__main__': - executor.start_polling(dp) + if __name__ == '__main__': + executor.start_polling(dp)