Esempio n. 1
0
def next_day(update, context):
    username = update.effective_chat.username
    user_data = load_all()
    if username not in user_data:
        user_data[username] = {'answers': {}}
    if 'archive' not in user_data[username]:
        user_data[username]['archive'] = {}
    user_data[username]['archive'][datetime.now()] = user_data[username]['answers']
    user_data[username]['answers'] = {}
    save_all(user_data)
    start(update, context)
Esempio n. 2
0
def questionnaire(update, context):
    username = update.effective_chat.username
    user_data = load_all()
    if username not in user_data:
        user_data[username] = {'answers': {}, "mood_score": 0, "mood_diff": 0}
    current_answer_num = len(user_data[username]['answers'].keys()) - 1
    logging.info(f'current_answer_num {current_answer_num}')
    user_data[username]['answers'][questions[current_answer_num -
                                             1]] = update.message.text
    if username in is_in_mood:
        answer = update.message.text
        is_in_mood.remove(username)
        user_emotion = emotionizer(answer)
        logging.info(f'emotion score is {user_emotion}')
        emotions = user_data[username].get("emotions", [])
        emotions.append(user_emotion)
        user_data[username]["emotions"] = emotions
        user_data[username]["mood_score"] += user_emotion
        user_data[username]["mood_diff"] = user_emotion
        if len(emotions) >= BAD_EMOTION_THRESHOLD:
            state_bad = is_everything_bad(emotions)
            if state_bad:
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text=
                    "Hey! You've been constantly in a bad mood for 4 days. Maybe you should talk to your relatives or seek some aid?"
                )
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text=
                    "There are 14 professionals in your neighbourhood, should I give you the numbers for the ones with best reviews?"
                )
    answers = user_data[username]['answers']

    save_all(user_data)

    if current_answer_num + 2 >= len(questions):
        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text=
            'You have answered all questions for today. Here is your updated portrait:'
        )
        update_photo(f'{username}.gif', user_data[username], username)
        #context.bot.sendAnimation(chat_id=update.effective_chat.id, animation=open(f'{username}.gif', 'rb'))
        context.bot.send_document(chat_id=update.effective_chat.id,
                                  document=open(f'{username}.gif', 'rb'))
        return
    if len(answers) < len(questions):
        bot_question = questions[len(answers)]
        if bot_question.split()[3] == "mood":
            is_in_mood.add(username)
        context.bot.send_message(chat_id=update.effective_chat.id,
                                 text=bot_question)
    logging.info(f'{username} {user_data}')
Esempio n. 3
0
def questionnaire(update, context):
    username = update.effective_chat.username
    user_data = load_all()
    if username not in user_data:
        user_data[username] = {'answers': {}}
    current_answer_num = len(user_data[username]['answers'].keys()) - 1
    logging.info(f'current_answer_num {current_answer_num}')
    user_data[username]['answers'][questions[current_answer_num -
                                             1]] = update.message.text
    if username in is_in_mood:
        answer = update.message.text
        is_in_mood.remove(username)
        user_emotion = emotionizer(answer)
        logging.info(f'emotion score is {user_emotion}')
        emotions = user_data[username].get("emotions", [])
        emotions.append(user_emotion)
        user_data[username]["emotions"] = emotions
        if len(emotions) >= BAD_EMOTION_THRESHOLD:
            state_bad = is_everything_bad(emotions)
            if state_bad:
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text=
                    "Hey! You've been constantly in a bad mood for 4 days. Maybe you should talk to your relatives or seek some aid?"
                )
    answers = user_data[username]['answers']
    save_all(user_data)

    if current_answer_num + 2 >= len(questions):
        context.bot.send_message(
            chat_id=update.effective_chat.id,
            text=
            'You have answered all the questions for today. Here is how your portrait look like'
        )
        update_photo(f'{username}.jpg')
        context.bot.send_photo(chat_id=update.effective_chat.id,
                               photo=open(f'{username}.jpg', 'rb'))
        return
    if len(answers) < len(questions):
        bot_question = questions[len(answers)]
        if bot_question.split()[3] == "mood":
            is_in_mood.add(username)
        context.bot.send_message(chat_id=update.effective_chat.id,
                                 text=bot_question)
    logging.info(f'{username} {user_data}')