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

# Conflicts:
#	aiogram/types/message.py
This commit is contained in:
Alex Root Junior 2018-06-23 17:44:09 +03:00
commit 2f4c63c9a3
6 changed files with 31 additions and 42 deletions

View file

@ -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):

View file

@ -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()

View file

@ -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 <https://pypi.python.org/pypi/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'):

View file

@ -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

View file

@ -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)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

View file

@ -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 <https://t.me/BotFather>`_
@ -18,39 +18,39 @@ Bot token you can get from `@BotFather <https://t.me/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)