Первый коммит
This commit is contained in:
32
bot/handlers/messages/ping_test.py
Normal file
32
bot/handlers/messages/ping_test.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from aiogram import Router
|
||||
from aiogram.types import Message
|
||||
|
||||
router: Router = Router(name=__name__)
|
||||
|
||||
# Словарь с ответами по ключам
|
||||
RESPONSE_DICT: dict[str, str] = {
|
||||
"пинг": "Понг! 🏓",
|
||||
"понг": "Пинг!",
|
||||
"бот": "На месте! 🤖",
|
||||
}
|
||||
|
||||
|
||||
@router.message()
|
||||
async def auto_response_handler(message: Message) -> None:
|
||||
"""Обработчик автоматических ответов по ключевым словам."""
|
||||
if not message.text:
|
||||
return
|
||||
|
||||
text_lower: str = message.text.casefold().strip()
|
||||
|
||||
# Поиск точного совпадения
|
||||
if text_lower in RESPONSE_DICT:
|
||||
response: str = RESPONSE_DICT[text_lower]
|
||||
await message.answer(response)
|
||||
return
|
||||
|
||||
# Поиск частичного совпадения (если хотите расширенную функциональность)
|
||||
for key, response in RESPONSE_DICT.items():
|
||||
if key in text_lower and len(key) > 3: # Только для ключей длиннее 3 символов
|
||||
await message.answer(response)
|
||||
return
|
||||
Reference in New Issue
Block a user