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

# Conflicts:
#	examples/broadcast_example.py
This commit is contained in:
Alex Root Junior 2018-07-14 16:30:26 +03:00
commit 2cc9720b09
2 changed files with 15 additions and 12 deletions

View file

@ -25,16 +25,16 @@ Next step: interaction with bots starts with one command. Register your first co
.. 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
-------
@ -48,9 +48,9 @@ Summary
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)

View file

@ -23,16 +23,17 @@ 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
:param user_id:
:param text:
:param disable_notification:
:return:
"""
try:
await bot.send_message(user_id, text)
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 +42,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: