File size: 711 Bytes
a8bca78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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"]]