Esempio n. 1
0
def state_0(user, message):
    """
    state 0 is the initial state by default (see bot_manager) and must be defined
    This is where the bot sends the user after s/he starts the bot (or types the command /start)
    """
    bot_turn = message is None
    if bot_turn:
        reply_text = 'You are in the initial state.'
        keyboard = [['State1'], ['State2']]
        send_message(user, reply_text, keyboard)
    else:
        if message.text:
            input_text = message.text
            if input_text == 'State1':
                reply_text = "I'm sending you to state 1."
                send_message(user, reply_text)
                direct_user_to_state(user, '1')
            elif input_text == 'State2':
                reply_text = "I'm sending you to state 2."
                send_message(user, reply_text)
                direct_user_to_state(user, '2')
            else:
                reply_text = "Please use the keyboard below."
                send_message(user, reply_text)
        else:
            reply_text = 'Only text is allowed here.'
            send_message(user, reply_text)
Esempio n. 2
0
def state_patrocinio(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Vuoi che l'evento venga patrocinato dal comune di Ville d'Anaunia"
        keyboard = [['SI', 'NO']]
        send_message(user, reply_text, keyboard)
    else:
        direct_user_to_state(user, 'pubblicità')
Esempio n. 3
0
def controllo_data(user, valore_data):
    if "-" in valore_data:
        try:
            valore = valore_data.split('/')
            return True
        except:
            return False
    else:
        send_message(user, 'Formato non valido')
        return False
Esempio n. 4
0
def state_call_metodo(user, message):
    data = get_user_var_value(user, 'DATA', None)
    ora = get_user_var_value(user, 'ORA_INIZIO', None)
    oraFine = get_user_var_value(user, 'ORA_FINE', None)

    dati = asd.ritorna_date(data, ora, oraFine)
    send_message(user, dati)
    if len(dati) > 0:
        direct_user_to_state(user, 'input_scelto')
        set_user_var_value(user, 'VETTORE_DATI', dati)
    else:
        send_message(user, "DATI NON PRESENTI ")
def rimuovi_ricetta_da_preferiti(user, ricetta_id):
    r = get_ricetta(ricetta_id)
    if r is None:
        reply_text = "Nessuna ricetta trovata."
    else:
        ricette_preferite = get_user_var_value(user,
                                               'RICETTE_PREFERITE',
                                               init_value=[])
        ricette_preferite.remove(ricetta_id)
        ricette_preferite = sorted(set(ricette_preferite))
        reply_text = ('Ricetta rimossa da preferiti ({}).'.format(r['Title']))
    send_message(user, reply_text, markdown=True)
def aggiungi_ricetta_in_preferiti(user, ricetta_id):
    r = get_ricetta(ricetta_id)
    if r is None:
        reply_text = "Nessuna ricetta trovata."
    else:
        ricette_preferite = get_user_var_value(user,
                                               'RICETTE_PREFERITE',
                                               init_value=[])
        ricette_preferite.append(ricetta_id)
        ricette_preferite = sorted(set(ricette_preferite))
        reply_text = ('Ricetta aggiunta in preferiti ({}).'.format(r['Title']))
    send_message(user, reply_text, markdown=True)
Esempio n. 7
0
def controllo_ora(user, valore_ora):
    if ":" in valore_ora:
        split = valore_ora.split(':')
        try:
            int(split[0])
            int(split[1])
            return True
        except:
            return False
    else:
        send_message(user, 'Formato non valido')
        return False
Esempio n. 8
0
def state_input_scelto(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Inserisci il numero della struttura che vuoi prenotare:"
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = int(message.text)
            set_user_var_value(user, 'POS_SELEZ', input_text)
            direct_user_to_state(user, 'conferma_input')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 9
0
def state_dati_ruolo(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Inserisci il tuo ruolo : "
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = message.text
            set_user_var_value(user, 'RUOLO', input_text)
            direct_user_to_state(user, 'autorizzazione_dati')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 10
0
def state_dati_associazione(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Inserisci il nome dell'associazione : "
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = message.text
            set_user_var_value(user, 'NOME_ASSOCIAZIONE', input_text)
            direct_user_to_state(user, 'dati_ruolo')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 11
0
def state_registrazione_nome(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = 'Inserisci il tuo Nome e Cognome :'
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = message.text
            set_user_var_value(user, 'NOMECOGNOME', input_text)
            direct_user_to_state(user, 'registrazione_email')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 12
0
def state_evento_scelto(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Che tipo di evento vuoi organizzare? (es. festa privata, assemblea, attività sportiva...)"
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = message.text
            set_user_var_value(user, 'TIPO_EVENTO_SCELTO', input_text)
            direct_user_to_state(user, 'tipo_struttura')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 13
0
def state_prendi_secondo_indice(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Inserisci indice per la stanza desiderata:"
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = message.text
            set_user_var_value(user, 'DATA_INDICE_DUE', input_text)

        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 14
0
def state_registrazione_codice_fiscale(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = 'Inserisci il tuo codice fiscale :'
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = message.text
            bot_manager.set_user_var_value(user, 'CODF', input_text)
            set_user_var_value(user, "REGISTRATO", True)
            direct_user_to_state(user, '0')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 15
0
def state_autorizzazione_dati(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Autorizzo il trattamento dei miei dati personali ai sensi del Decreto Legislativo 30 giugno 2003, n. 196 “Codice in materia di protezione dei dati personali”"
        keyboard = [['Confermo']]
        send_message(user, reply_text, keyboard)
    else:
        if message.text:
            input_text = message.text
            if input_text == "Confermo":
                direct_user_to_state(user, 'scelte_utente')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 16
0
def state_tipo_struttura(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "In base a cosa vuoi cercare la struttura?"
        keyboard = [['Data/Ora'], ['Lista delle strutture']]
        send_message(user, reply_text, keyboard)
    else:
        if message.text:
            input_text = message.text
            if input_text == "Data/Ora":
                direct_user_to_state(user, 'data')
            elif input_text == "Lista delle strutture":
                direct_user_to_state(user, 'lista_strutture')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 17
0
def state_prendi_seconda_data(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Inserisci data per selezionare la stanza [gg-mm-aaaa]"
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = message.text
            if controllo_data(user, input_text):
                set_user_var_value(user, 'DATA_NUMERO_DUE', input_text)
                direct_user_to_state(user, 'prendi_secondo_indice')
            else:
                direct_user_to_state(user, 'prendi_seconda_data')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 18
0
def state_lista_strutture_ORE(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Inserisci ora iniziale per la ricerca [00:00]"
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = message.text
            if controllo_ora(user, input_text):
                set_user_var_value(user, 'DATA_RICERCA_STRUTTURA', input_text)
                direct_user_to_state(user, 'lista_strutture_ORE_finale')
            else:
                direct_user_to_state(user, 'lista_strutture_ORE')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 19
0
def state_ora_fine(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Inserisci ora di fine [00:00]"
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = message.text
            if controllo_ora(user, input_text):
                set_user_var_value(user, 'ORA_FINE', input_text)
                direct_user_to_state(user, 'call_metodo')
            else:
                direct_user_to_state(user, 'ora_fine')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 20
0
def state_data(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Inserisci data  [gg-mm-aaaa]"
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = message.text
            if controllo_data(user, input_text):
                set_user_var_value(user, 'DATA', input_text)
                direct_user_to_state(user, 'ora_inizio')
            else:
                direct_user_to_state(user, 'data')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
def send_ricetta(user, ricetta_id):
    r = get_ricetta(ricetta_id)
    if r is None:
        reply_text = "Nessuna ricetta trovata."
    else:
        ricette_preferite = get_user_var_value(user,
                                               'RICETTE_PREFERITE',
                                               init_value=[])
        aggiungi_rimuovi = '/rimuoviRicettaDaPreferiti' if r[
            'RecipeID'] in ricette_preferite else '/aggiungiRicettaInPreferiti'
        reply_text = ("*Titolo*: {}\n"
                      "*Ingredienti*: {}\n"
                      "*Preparatione*: {}\n\n"
                      "{}{}").format(r['Title'], r['Ingredient'],
                                     r['Preparation'], aggiungi_rimuovi,
                                     r['RecipeID'])
    send_message(user, reply_text, markdown=True)
Esempio n. 22
0
def state_seconda_conferma(user, message):
    bot_turn = message is None
    stanza_scelta = get_user_var_value(user, 'DATA_NUMERO_DUE', None)
    numero_stanza = get_user_var_value(user, 'DATA_INDICE_DUE', None)

    if bot_turn:
        reply_text = "Confermi di voler prenotare la stanza numero {} per il giorno {} ?:".format(
            numero_stanza, stanza_scelta)
        keyboard = [['SI'], ['NO']]
        send_message(user, reply_text, keyboard)
    else:
        if message.text:
            input_text = message.text
            if input_text == "SI":
                pass
            else:
                pass
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 23
0
def state_conferma_input(user, message):
    bot_turn = message is None
    posizioneScelta = get_user_var_value(user, 'VETTORE_DATI', None)
    data = get_user_var_value(user, 'DATA', None)
    gg = get_user_var_value(user, 'POS_SELEZ', None)
    posizioneScelta = posizioneScelta[gg]
    oreA = get_user_var_value(user, 'ORA_INIZIO', None)
    oreB = get_user_var_value(user, 'ORA_FINE', None)

    if bot_turn:
        reply_text = "Confermi di voler prenotare la stanza {} per il giorno {} dalle ore {} alle ore {}:".format(
            posizioneScelta, data, oreA, oreB)
        keyboard = [['SI'], ['NO']]
        send_message(user, reply_text, keyboard)
    else:
        if message.text:
            input_text = message.text
            if input_text == "SI":
                direct_user_to_state(user, 'valida_mail')
            else:
                send_message(user, 'Ti faccio rinserire i dati')
                direct_user_to_state(user, 'data')
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
def state_0(user, message):
    """
    state 0 is the initial state by default (see bot_manager) and must be defined
    This is where the bot sends the user after s/he starts the bot (or types the command /start)
    """
    bot_turn = message is None
    if bot_turn:
        reply_text = ('Ciao, sono il ricettario Trentino.\n'
                      'Puoi cercare le ricette per titolo o per ingredienti,'
                      'o andare alle tue ricette preferite')
        keyboard = [['Titolo', 'Ingredienti'], ['Preferiti']]
        send_message(user, reply_text, keyboard)
    else:
        if message.text:
            input_text = message.text
            if input_text == 'Titolo':
                direct_user_to_state(user, 'titolo')
            elif input_text == 'Ingredienti':
                direct_user_to_state(user, 'ingredienti')
            elif input_text == 'Preferiti':
                direct_user_to_state(user, 'preferiti')
            else:
                reply_text = "Input non riconosciuto, usa la tastiera."
                send_message(user, reply_text)
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
def state_preferiti(user, message):
    bot_turn = message is None
    if bot_turn:
        ricette_preferite = get_user_var_value(user, 'RICETTE_PREFERITE')
        if ricette_preferite:
            ricette_trovate = []
            for r_id in ricette_preferite:
                r = get_ricetta(r_id)
                ricette_trovate.append('• /ricetta{} {}'.format(
                    r['RecipeID'], r['Title']))
            ricette_trovate_str = '\n'.join(ricette_trovate)
            reply_text = "Ricette preferite:\n\n{}\n\nPremi su una ricetta per visualizzarla.".format(
                ricette_trovate_str)
            keyboard = [['🗑 Reset preferiti'], ['🔙 Indietro']]
        else:
            reply_text = 'Nessuna ricetta preferita trovata'
            keyboard = [['🔙 Indietro']]
        send_message(user, reply_text, keyboard)
    else:
        if message.text:
            input_text = message.text
            if input_text == '🔙 Indietro':
                direct_user_to_state(user, '0')
            elif input_text == '🗑 Reset preferiti':
                set_user_var_value(user, 'RICETTE_PREFERITE', [])
                reply_text = "Ricette preferite eliminate."
                send_message(user, reply_text)
                direct_user_to_state(user, '0')
            elif input_text.startswith('/aggiungiRicettaInPreferiti'):
                ricetta_id = input_text.split('/aggiungiRicettaInPreferiti')[1]
                aggiungi_ricetta_in_preferiti(user, ricetta_id)
                repeatState(user)
            elif input_text.startswith('/rimuoviRicettaDaPreferiti'):
                ricetta_id = input_text.split('/rimuoviRicettaDaPreferiti')[1]
                rimuovi_ricetta_da_preferiti(user, ricetta_id)
                repeatState(user)
            elif input_text.startswith('/ricetta'):
                ricetta_id = input_text.split('/ricetta')[1]
                send_ricetta(user, ricetta_id)
            else:
                reply_text = 'Input non riconosciuto, usa la tastiera.'
                send_message(user, reply_text)
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 26
0
def state_pubblicità(user, message):
    bot_turn = message is None
    if bot_turn:
        testo = "https://www.facebook.com/comune.ville.danaunia/?ref=page_internal"
        reply_text = "Vuoi che l'evento venga pubblicizzato sulla pagina Facebook del comune?"
        keyboard = [['SI', 'NO']]
        send_message(user, reply_text, keyboard)
        send_message(user, testo)
    else:
        reply_text = "Seconda parte in sviluppo"
        send_message(user, reply_text)
Esempio n. 27
0
def state_scelte_utente(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Cosa desideri fare? "
        keyboard = [['Organizzare un evento'], ['Partecipare ad un evento']]
        send_message(user, reply_text, keyboard)
    else:
        if message.text:
            input_text = message.text
            if input_text == "Organizzare un evento":
                direct_user_to_state(user, 'luogo')
            elif input_text == "Partecipare ad un evento":
                send_message(user, input_text)
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 28
0
def state_luogo(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = "Dove?"
        keyboard = [['In una sala/struttura comunale'],
                    ['In un luogo pubblico']]
        send_message(user, reply_text, keyboard)
    else:
        if message.text:
            input_text = message.text
            if input_text == "In una sala/struttura comunale":
                direct_user_to_state(user, 'evento_scelto')
            elif input_text == "In un luogo pubblico":
                send_message(user, input_text)
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
Esempio n. 29
0
def state_registrazione_email(user, message):
    bot_turn = message is None
    if bot_turn:
        reply_text = 'Inserisci la tua email :'
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = message.text
            if validateEmail(input_text):
                bot_manager.set_user_var_value(user, 'EMAIL', input_text)
                direct_user_to_state(user, 'registrazione_codice_fiscale')
            else:
                reply_text = "Indirizzo email non valido!"
                send_message(user, reply_text)
        else:
            reply_text = 'Input non riconosciuto, usa la tastiera.'
            send_message(user, reply_text)
def state_0(user, message):
    """
    state 0 is the initial state by default (see bot_manager) and must be defined
    This is where the bot sends the user after s/he starts the bot (or types the command /start)
    """
    bot_turn = message is None
    if bot_turn:
        reply_text = 'You are in the initial state'
        send_message(user, reply_text)
    else:
        if message.text:
            input_text = message.text
            reply_text = "Hi, {} you said: {}".format(user.first_name, input_text)
            send_message(user, reply_text)
        else:
            reply_text = "You sent me something which I cannot handle."
            send_message(user, reply_text)