Пример #1
0
def def_knowledge(bot, update):
    global Fibot
    chat_id = update.message.chat_id
    message = update.message.text
    Fibot.nlg.give_feedback(chat_id, correct=False, correct_statement=message)
    Fibot.send_preset_message(chat_id, "corrected_message")
    Fibot.send_preset_message(chat_id, "send_me_message")
    return TRAINING
Пример #2
0
def training_off(bot, update):
    global Fibot
    chat_id = update.message.chat_id
    if Fibot.chats.get_chat(chat_id)['training']:
        Fibot.chats.update_info(chat_id, 'training', False, overwrite=True)
        Fibot.send_preset_message(chat_id, "training_inactive")
    else:
        Fibot.send_preset_message(chat_id, "training_already_inactive")
    return MESSAGE_INCOME
Пример #3
0
def feedback_info(bot, update):
    global Fibot
    chat_id = update.message.chat_id
    message = update.message.text
    if message == "Sí":
        Fibot.nlg.give_feedback(chat_id, correct=True)
        return TRAINING
    elif message == "No":
        Fibot.send_preset_message(chat_id, "request_good_answer")
        return GET_CORRECT
    else:
        update.message.reply_text("¿Fué coherente la última respuesta?",
                                  reply_markup=markup)
        return CORR_INCORR
Пример #4
0
def logout(bot, update):
    global Fibot
    chat_id = update.message.chat_id
    user_name = Fibot.chats.get_chat(chat_id)['name']
    if Fibot.chats.get_chat(chat_id)['logged']:
        data = {
            'name': user_name,
            'language': Fibot.chats.get_chat(chat_id)['language'],
            'access_token': None,
            'refresh_token': None,
            'current_state': Fibot.state_machine['MessageHandler'],
            'expire_time_end': None,
            'logged': False,
            'notifications': False
        }
        Fibot.chats.update_chat(chat_id, data)
        Fibot.send_preset_message(chat_id, "logout_done", user_name)
    else:
        Fibot.send_preset_message(chat_id, "logout_failed", user_name)
Пример #5
0
def authenticate(bot, update):
    global Fibot
    chat_id = update.message.chat_id
    user_name = Fibot.chats.get_chat(chat_id)['name']
    url = update.message.text
    urls = re.findall(
        'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
        url)
    if not urls:
        Fibot.send_preset_message(chat_id, "request_oauth_url")
        Fibot.chats.update_info(chat_id,
                                'current_state',
                                Fibot.state_machine['Wait_authorisation'],
                                overwrite=True)
        return MESSAGE_INCOME
    auth_code = url.split('=')[1]
    callback = Fibot.oauth.authenticate(auth_code)
    if isinstance(callback, dict):
        Fibot.chats.update_chat(chat_id, callback, full_data=False)
        Fibot.send_preset_message(chat_id, "login_done", user_name)
        Fibot.chats.update_info(chat_id,
                                'current_state',
                                Fibot.state_machine['MessageHandler'],
                                overwrite=True)
    else:
        Fibot.send_preset_message(chat_id, "url_error")
        Fibot.chats.update_info(
            chat_id,
            'current_state',
            Fibot.state_machine_nodes['Wait_authorisation'],
            overwrite=True)
    return MESSAGE_INCOME
Пример #6
0
def training_on(bot, update):
    global Fibot
    chat_id = update.message.chat_id
    if not Fibot.chats.get_chat(chat_id)['training']:
        Fibot.chats.update_info(chat_id, 'training', True, overwrite=True)
        Fibot.send_preset_message(chat_id, "training_active")
        Fibot.send_preset_message(chat_id, "send_me_message")
    else:
        Fibot.send_preset_message(chat_id, "training_already_active")
        return TRAINING
Пример #7
0
def updates_on(bot, update):
    global Fibot
    chat_id = update.message.chat_id
    if Fibot.chats.get_chat(chat_id)['logged'] and not Fibot.chats.get_chat(
            chat_id)['notifications']:
        Fibot.chats.update_info(chat_id, 'notifications', True, overwrite=True)
        Fibot.send_preset_message(chat_id, "notif_active")
    elif Fibot.chats.get_chat(chat_id)['logged'] and Fibot.chats.get_chat(
            chat_id)['notifications']:
        Fibot.send_preset_message(chat_id, "notif_already_active")
    else:
        Fibot.send_preset_message(chat_id, "notif_active_failed")
Пример #8
0
def set_lang(bot, update):
    global Fibot
    languages = ['ca', 'es', 'en']
    chat_id = update.message.chat_id
    text = update.message.text
    if len(text.split(' ')) > 1:
        lang = text.split(' ')[1]
        if lang in languages:
            Fibot.chats.update_info(chat_id, 'language', lang, overwrite=True)
            Fibot.send_preset_message(chat_id, "language_change_ok")
        else:
            Fibot.send_preset_message(chat_id, "select_language")
    else:
        Fibot.send_preset_message(chat_id, "wrong_lang_format")
Пример #9
0
def start(bot, update, args):
    global Fibot
    chat_id = update.message.chat_id
    if Fibot.chats.user_has_data(chat_id):
        Fibot.send_preset_message(chat_id, "start_known",
                                  Fibot.chats.get_chat(chat_id)['name'])
    else:
        user_name = update.message.from_user.first_name
        data = {
            'name': user_name,
            'language': 'ca',
            'access_token': None,
            'refresh_token': None,
            'current_state': Fibot.state_machine['MessageHandler'],
            'expire_time_end': None,
            'logged': False,
            'notifications': False
        }
        Fibot.chats.update_chat(chat_id, data, compulsory=True)
        Fibot.send_preset_message(chat_id, "start_unknown_1", user_name)
        Fibot.send_preset_message(chat_id, "start_unknown_2")
        Fibot.send_preset_message(chat_id, "start_unknown_3")
    return MESSAGE_INCOME
Пример #10
0
def start_authentication(bot, update):
    global Fibot
    print(colored("LOG: Empezando autenticación", 'cyan'))
    chat_id = update.message.chat_id
    user_name = Fibot.chats.get_chat(chat_id)['name']
    logged = Fibot.chats.get_chat(chat_id)['logged']
    if (not logged):
        Fibot.send_preset_message(chat_id, "send_oauth_url",
                                  Fibot.oauth.get_autho_full_page())
        Fibot.send_preset_message(chat_id, "inform_oauth_procedure")
        Fibot.chats.update_info(chat_id,
                                'current_state',
                                Fibot.state_machine['Wait_authorisation'],
                                overwrite=True)
    else:
        Fibot.send_preset_message(chat_id, "already_login", user_name)
    return MESSAGE_INCOME