ДЗ 2
parent
062caa416d
commit
9dba5b26f3
|
@ -9,7 +9,7 @@ from aiogram.filters import CommandStart
|
|||
from aiogram.types import Message
|
||||
from aiogram.utils.markdown import hbold
|
||||
|
||||
from tg_bot.handlers.lesson_one import router as router_one
|
||||
from tg_bot.handlers.lesson_two import router as router_one
|
||||
|
||||
TOKEN: str = getenv('BOT_TOKEN') or 'Your TG_BOT token'
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
from aiogram import F, Router
|
||||
from aiogram.filters import Command
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.fsm.state import State, StatesGroup
|
||||
from aiogram.types import Message
|
||||
from aiogram.utils.markdown import hbold
|
||||
|
||||
router = Router()
|
||||
|
||||
greatings = ['привет', 'добрый день', 'добрый вечер', 'доброе утро', 'здравствуйте']
|
||||
|
||||
|
||||
class OrderReverse(StatesGroup):
|
||||
string = State()
|
||||
|
||||
|
||||
@router.message(Command('reverse'))
|
||||
async def reverse_request(message: Message, state: FSMContext):
|
||||
await state.set_state(OrderReverse.string)
|
||||
await message.answer(
|
||||
text='Введите строку для разворота',
|
||||
)
|
||||
|
||||
|
||||
@router.message(OrderReverse.string, F.text)
|
||||
async def reversing(message: Message, state: FSMContext):
|
||||
string = message.text
|
||||
if string is not None:
|
||||
string = string[::-1]
|
||||
await message.answer(
|
||||
text=f'Ваша строка наоборот:\n{string}',
|
||||
)
|
||||
await state.clear()
|
||||
|
||||
|
||||
@router.message(F.text.func(lambda m: m.lower() in greatings))
|
||||
async def greating(message: Message):
|
||||
await message.answer(f'Здравствуй, {hbold(message.from_user.first_name)}')
|
Loading…
Reference in New Issue