From 9dba5b26f3b172a9b2345ba15acecd2ea16f7eb9 Mon Sep 17 00:00:00 2001 From: pi3c Date: Thu, 15 Feb 2024 01:19:29 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=97=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tg_bot/app.py | 2 +- tg_bot/handlers/lesson_two.py | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tg_bot/handlers/lesson_two.py 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)}')