Refactor examples/echo_bot.py

This commit is contained in:
Suren Khorenyan 2019-07-21 11:30:33 +03:00
parent f4aafb043e
commit 3867b72df6

View file

@ -20,7 +20,7 @@ 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):
""" """
This handler will be called when client send `/start` or `/help` commands. This handler will be called when user sends `/start` or `/help` command
""" """
await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.") await message.reply("Hi!\nI'm EchoBot!\nPowered by aiogram.")
@ -28,13 +28,25 @@ async def send_welcome(message: types.Message):
@dp.message_handler(regexp='(^cat[s]?$|puss)') @dp.message_handler(regexp='(^cat[s]?$|puss)')
async def cats(message: types.Message): async def cats(message: types.Message):
with open('data/cats.jpg', 'rb') as photo: with open('data/cats.jpg', 'rb') as photo:
await bot.send_photo(message.chat.id, photo, caption='Cats is here 😺', '''
reply_to_message_id=message.message_id) # Old fashioned way:
await bot.send_photo(
message.chat.id,
photo,
caption='Cats are here 😺',
reply_to_message_id=message.message_id,
)
'''
await message.reply_photo(photo, caption='Cats are here 😺')
@dp.message_handler() @dp.message_handler()
async def echo(message: types.Message): async def echo(message: types.Message):
await bot.send_message(message.chat.id, message.text) # old style:
# await bot.send_message(message.chat.id, message.text)
await message.reply(message.text, reply=False)
if __name__ == '__main__': if __name__ == '__main__':