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

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