| user_memory = {} | |
| def get_user_context(user_id: str): | |
| """Возвращает историю вопросов и ответов для пользователя""" | |
| return user_memory.get(user_id, {"questions": [], "answers": []}) | |
| def update_user_context(user_id: str, question: str, answer: str): | |
| ctx = user_memory.setdefault(user_id, {"questions": [], "answers": []}) | |
| ctx["questions"].append(question) | |
| ctx["answers"].append(answer) | |
| return ctx | |
| def was_asked(user_id: str, new_question: str) -> bool: | |
| """Проверяет, повторялся ли вопрос""" | |
| ctx = get_user_context(user_id) | |
| return new_question.strip().lower() in [q.lower() for q in ctx["questions"]] | |