Files
PrimoGuardBot-/bot/handlers/messages/ping_test.py
2026-02-17 11:24:55 +07:00

33 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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