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:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
__version__ = '1.3.2'
__version__ = '1.3.3.dev1'
__api_version__ = '3.6'

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

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

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,8 +18,8 @@ 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:
@ -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):

View file

@ -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, '<b>Hello, World!</b>')
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: