diff --git a/tg_bot/app.py b/tg_bot/app.py index 1a40e05..e995dfd 100644 --- a/tg_bot/app.py +++ b/tg_bot/app.py @@ -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' diff --git a/tg_bot/handlers/lesson_two.py b/tg_bot/handlers/lesson_two.py new file mode 100644 index 0000000..a99fb39 --- /dev/null +++ b/tg_bot/handlers/lesson_two.py @@ -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)}')