Files
PrimoAranaraBot/bot/utils/random_lists.py
2025-09-08 00:40:18 +07:00

19 lines
750 B
Python
Raw Permalink 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 random import choice
def get_best_response(user_text: str) -> str:
"""
Подбирает наиболее подходящий ответ на сообщение пользователя.
Сначала ищет ключевые слова и их синонимы, если совпадений нет — выдаёт случайную фразу.
:param user_text: текст сообщения пользователя
:return: строка с ответом
"""
normalized_text: str = user_text.lower()
for _, data in RESPONSES.items():
for keyword in data["keywords"]:
if keyword in normalized_text:
return choice(data["answers"])
return choice(RANDOM_PHRASES)