Merge pull request #53 from surik00/dev-1.x

Fix broadcast example
This commit is contained in:
Alex Root Junior 2018-07-02 21:54:11 +03:00 committed by GitHub
commit 6dc5d77bb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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: