Ejemplo n.º 1
0
def confirm_suggested_film_response(bot, message, User):
    """Stage 8 Response. Checking the user's outcome of the suggested film
  @param {Bot} bot
  @param {String} message
  @param {Person} User"""
    negative_film_responses.extend(negatives)
    if check_for_expected_input(message, positives):
        db.updateSuggestedFilmStatus(User.id, 1)
        db.updateSuggestedFilmIndex(User.id, 0)
        db.removeQueryInfo(User.id)
        bot.send_message(
            User.id,
            "Ok, have fun watching the film! Let me know what you thought of it!"
        )
        setUserContextAndStage(User.id, contexts['ChitChat'],
                               stages['ChitChat'])
    elif check_for_expected_input(message, negative_film_responses):
        bot.send_message(
            User.id, "Ok I am finding a new film that I think you will like.")
        new_index = User.suggested_film_index + 1
        generate_film(bot, User, new_index)
        db.updateSuggestedFilmIndex(User.id, new_index)
    else:
        bot.send_message(User.id,
                         "Sorry I don't understand, is this film fine?")
Ejemplo n.º 2
0
def confirm_crew_response(bot, message, User):
    """Stage 6 Response. Confirming the extracted crew information was correct.
  @param {Bot} bot
  @param {String} message
  @param {Person} User"""
    skipFlag = False
    if check_for_expected_input(message, skip):
        skipFlag = True
    if skipFlag or check_for_expected_input(message, positives):
        generate_film(bot, User, 0)
        db.updateSuggestedFilmIndex(User.id, 0)
    elif check_for_expected_input(message, negatives):
        next_question_message = "Ok so did you want any specific people to have been involved with the film?"
        bot.send_message(User.id, next_question_message)
        setUserContextAndStage(User.id, contexts['FilmSuggestion'],
                               stages['filmSuggestion']['AskCrew'])
        db.removeQueryInfo(User.id, 3)
    else:
        db_query = db.getQueryInfo(User.id, 3)
        crew_names = []
        if db_query:
            for result in db_query:
                crew_names.append(
                    db.getCrewByID(result['Information'])['Name'])
            crew_names = format_query_info(crew_names)
        next_question_message = "Sorry I don't understand."
        if crew_names:
            next_question_message = next_question_message + " Did you want a film with {}?".format(
                crew_names)
        bot.send_message(User.id, next_question_message)
Ejemplo n.º 3
0
def extract_data(bot, message, User):
    """Stage 1 Response. Calls the functions to search for the genre, film and
  crew information and inserts the relevant information into the database.
  @param {Bot} bot
  @param {String} message
  @param {Person} User"""
    #TODO Noun chunks for <bad>/<funny> etc
    db.removeQueryInfo(User.id)
    next_stage = 'AskFilm'
    extract_genres(User.id, message)
    extract_crew(User.id, message)
    films = extract_film(User.id, message)
    if films:
        next_stage = 'ConfirmFilm'

    setUserContextAndStage(User.id, contexts['FilmSuggestion'],
                           stages['filmSuggestion'][next_stage])
    if next_stage == 'AskFilm':
        bot.send_message(
            User.id,
            "Do you want the film I suggest to be similar to another film?")
    else:
        filmTitles = format_query_info([film for film in films])
        bot.send_message(
            User.id, "So you want a film similar to {}?".format(filmTitles))
Ejemplo n.º 4
0
def cancel_film_suggestion(bot, User):
    """Gets the user out of the film suggestion conversation
  @param {Bot} bot
  @param {Person} User"""
    db.updateSuggestedFilmStatus(User.id, 0)
    db.updateSuggestedFilmIndex(User.id, 0)
    db.removeQueryInfo(User.id)
    setUserContextAndStage(User.id, contexts['ChitChat'], stages['ChitChat'])
    bot.send_message(
        User.id,
        "Ok, that's fine. Just let me know if you do want me to suggest a film for you later."
    )
Ejemplo n.º 5
0
def confirm_film_response(bot, message, User):
    """Stage 2 Response. Confirming the extracted film information was correct.
  @param {Bot} bot
  @param {String} message
  @param {Person} User"""
    skipFlag = False
    db_query = db.getQueryInfo(User.id, 1)
    film_names = set()
    if db_query:
        for result in db_query:
            FilmName = db.getFilmByID(result['Information'])
            if FilmName:
                film_names.add(FilmName['Title'])
    next_question_message = "Sorry I'm not sure I understand."
    if film_names:
        film_names = format_query_info(list(film_names))
        next_question_message = next_question_message + " Did you want a film similar to {}".format(
            film_names)
    next_stage = 'ConfirmFilm'
    if check_for_expected_input(message, skip):
        skipFlag = True
    if check_for_expected_input(message, positives) or skipFlag:
        #TODO CHECK FOR ADDING OF FILMS/REMOVING OF FILMS
        genres_query_info = db.getQueryInfo(User.id, 2)
        if genres_query_info:
            genres = format_query_info(
                [genre['Information'] for genre in genres_query_info])
            if skipFlag:
                next_question_message = "Ok let's skip choosing a similar film. I just want to confirm that you did want a film that was a {}".format(
                    genres)
            else:
                next_question_message = "Alright that sounds good! I just want to confirm that you did want a film that was a {}".format(
                    genres)
            next_stage = 'ConfirmGenre'
        else:
            if skipFlag:
                next_question_message = "Ok let's skip choosing a similar film. Did you want the film to have any specific genres?"
            else:
                next_question_message = "Alright that sounds good! Did you want the film to have any specific genres?"
            next_stage = 'AskGenre'
    elif check_for_expected_input(message, negatives):
        next_stage = 'AskFilm'
        next_question_message = "Ok, so do you want the film I suggest to be similar to another film?"
        db.removeQueryInfo(User.id, 1)

    bot.send_message(User.id, next_question_message)
    setUserContextAndStage(User.id, contexts['FilmSuggestion'],
                           stages['filmSuggestion'][next_stage])
Ejemplo n.º 6
0
def confirm_genre_response(bot, message, User):
    """Stage 4 Response. Confirming the extracted genre information was correct.
  @param {Bot} bot
  @param {String} message
  @param {Person} User"""
    db_query = db.getQueryInfo(User.id, 2)
    genre = ''
    if db_query:
        genre = [query['Information'] for query in db_query]
    next_question_message = "Sorry I'm not sure I understand."
    if genre:
        next_question_message = next_question_message + " Did you want the film to be a {}".format(
            format_query_info(genre))
    next_stage = 'ConfirmGenre'
    skipFlag = False
    if check_for_expected_input(message, skip):
        skipFlag = True
    if skipFlag or check_for_expected_input(message, positives):
        crew_query_info = db.getQueryInfo(User.id, 3)
        if crew_query_info:
            crewIDs = [crew['Information'] for crew in crew_query_info]
            crew_names = []
            for crewID in crewIDs:
                crew_names.append(db.getCrewByID(crewID)['Name'])
            crew = format_query_info(crew_names)
            if skipFlag:
                next_question_message = "Ok, let's skip choosing a genre. From what you said earlier, you wanted {} to have been involved with the film?".format(
                    crew)
            else:
                next_question_message = "Right, I'll note that down. From what you said earlier, you wanted {} to have been involved with the film?".format(
                    crew)
            next_stage = 'ConfirmCrew'
        else:
            if skipFlag:
                next_question_message = "Ok let's skip choosing a genre. Are there any people you want to have been involved with the film?"
            else:
                next_question_message = "Right, I'll note that down. Are there any people you want to have been involved with the film?"
            next_stage = "AskCrew"
    elif check_for_expected_input(message, negatives):
        next_stage = 'AskGenre'
        next_question_message = "Ok, so are there any genres that you want the film to be of?"
        db.removeQueryInfo(User.id, 2)

    bot.send_message(User.id, next_question_message)
    setUserContextAndStage(User.id, contexts['FilmSuggestion'],
                           stages['filmSuggestion'][next_stage])