mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Merge branch 'dev-1.x' into dev-2.x
# Conflicts: # examples/broadcast_example.py
This commit is contained in:
commit
2cc9720b09
2 changed files with 15 additions and 12 deletions
|
|
@ -25,16 +25,16 @@ Next step: interaction with bots starts with one command. Register your first co
|
||||||
|
|
||||||
.. code-block:: python3
|
.. code-block:: python3
|
||||||
|
|
||||||
@dp.message_handler(commands=['start', 'help'])
|
@dp.message_handler(commands=['start', 'help'])
|
||||||
async def send_welcome(message: types.Message):
|
async def send_welcome(message: types.Message):
|
||||||
await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
|
await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
|
||||||
|
|
||||||
Last step: run long polling.
|
Last step: run long polling.
|
||||||
|
|
||||||
.. code-block:: python3
|
.. code-block:: python3
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
executor.start_polling(dp)
|
executor.start_polling(dp)
|
||||||
|
|
||||||
Summary
|
Summary
|
||||||
-------
|
-------
|
||||||
|
|
@ -48,9 +48,9 @@ Summary
|
||||||
bot = Bot(token='BOT TOKEN HERE')
|
bot = Bot(token='BOT TOKEN HERE')
|
||||||
dp = Dispatcher(bot)
|
dp = Dispatcher(bot)
|
||||||
|
|
||||||
@dp.message_handler(commands=['start', 'help'])
|
@dp.message_handler(commands=['start', 'help'])
|
||||||
async def send_welcome(message: types.Message):
|
async def send_welcome(message: types.Message):
|
||||||
await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
|
await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
executor.start_polling(dp)
|
executor.start_polling(dp)
|
||||||
|
|
|
||||||
|
|
@ -23,16 +23,17 @@ def get_users():
|
||||||
yield from (61043901, 78238238, 78378343, 98765431, 12345678)
|
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
|
Safe messages sender
|
||||||
|
|
||||||
:param user_id:
|
:param user_id:
|
||||||
:param text:
|
:param text:
|
||||||
|
:param disable_notification:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
await bot.send_message(user_id, text)
|
await bot.send_message(user_id, text, disable_notification=disable_notification)
|
||||||
except exceptions.BotBlocked:
|
except exceptions.BotBlocked:
|
||||||
log.error(f"Target [ID:{user_id}]: blocked by user")
|
log.error(f"Target [ID:{user_id}]: blocked by user")
|
||||||
except exceptions.ChatNotFound:
|
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.")
|
log.error(f"Target [ID:{user_id}]: Flood limit is exceeded. Sleep {e.timeout} seconds.")
|
||||||
await asyncio.sleep(e.timeout)
|
await asyncio.sleep(e.timeout)
|
||||||
return await send_message(user_id, text) # Recursive call
|
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:
|
except exceptions.TelegramAPIError:
|
||||||
log.exception(f"Target [ID:{user_id}]: failed")
|
log.exception(f"Target [ID:{user_id}]: failed")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue