Exemplo n.º 1
0
    def handle(self, handler_input):
        logger.info("HAN  FP_SetNumberQuestionsHandler")
        speech_list = []

        FreePlayAttr.set_attr_free_play(
            handler_input)  # reset questions asked.
        num_questions = SlotUtils.get_slot_val_by_name(handler_input,
                                                       'num_questions')

        if num_questions is None:
            ms_can_set_questions = FPNumQuestions.get_ms_can_set_num_questions(
            )
            prompt, reprompt = (FPNumQuestions.get_q_num_questions()
                                for _ in range(2))
            speech_list += Pauser.make_ms_pause_level_list(
                ms_can_set_questions, 2, prompt)

        else:
            FreePlayAttr.set_attr_num_questions(handler_input, num_questions)

            ms_confirm = ConfirmUtils.get_random_confirmation(handler_input)
            ms_ask_num_questions = FPNumQuestions.get_ms_ask_num_questions(
                handler_input)
            prompt = FPPrompts.get_q_fp_setup_prompt(handler_input)
            reprompt = FPPrompts.get_q_fp_setup_reprompt(handler_input)

            speech_list += Pauser.make_ms_pause_level_list(
                ms_confirm, ms_ask_num_questions, 2, prompt)

        ModeStats.translate_mode_stats_to_sesh(handler_input)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Exemplo n.º 2
0
    def handle(self, handler_input):
        logger.info("HAN    SM_CorrectQuestionHandler")
        speech_list = []

        player_obj = PlayerDict.load_player_obj(handler_input)
        UserStats.update_player_stats(handler_input, correct = True, player_obj= player_obj)
        SM_Attr.increment_sm_upper(handler_input)
        
        ms_congrats = CongratUtils.get_answer_congrats(
            handler_input, player_obj= player_obj, survival_mode=True)

        logger.debug(ms_congrats)

        ms_question = SMQuestions.get_question(
            handler_input, first_question= False, player_obj= player_obj)
        reprompt = GenQuestions.get_same_question(handler_input)
        
        if len(ms_congrats):
            sm_pause = Pauser.get_sm_pause_length(handler_input)
            speech_list += Pauser.make_ms_pause_level_list(ms_congrats, sm_pause)
        speech_list.append( ms_question)
        
        SessionStats.update_consecutive_correct(handler_input, True)
        ModeStats.update_mode_stats(handler_input, True)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (
            handler_input.response_builder
                .speak(speech)
                .ask(reprompt)
                .set_card( SimpleCard( card_title, card_text))
                .response)
Exemplo n.º 3
0
    def handle(self, handler_input):
        logger.info("HAN  FP_SetTimesTablesHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []

        ## Get & Set slots
        lower_table, upper_table, tables_query = (
            FreePlayAttr.get_times_table_input_slots(handler_input))

        ## Logic checks
        retry_query = attr.get('inform_query_tables_format', False)
        tables_provided = FreePlayLogic.check_tables_provided(
            lower_table, upper_table, tables_query)

        if tables_provided:
            FreePlayAttr.set_attr_free_play(handler_input)
            FreePlayAttr.set_attr_times_tables(handler_input, lower_table,
                                               upper_table, tables_query)

            if retry_query:
                ms_potential_mistake = FPTimesTables.get_ms_potential_mistake_parsing_query(
                )
                speech_list += Pauser.make_ms_pause_level_list(
                    ms_potential_mistake, 2)
            else:
                ms_confirm = ConfirmUtils.get_random_confirmation(
                    handler_input)
                speech_list.append(ms_confirm)

            ms_using_tables = (FPTimesTables.get_ms_using_tables_from_input(
                lower_table, upper_table, tables_query))
            speech_list += Pauser.make_ms_pause_level_list(ms_using_tables, 2)

            if retry_query:
                ms_retry_query = FPTimesTables.get_ms_can_retry_query_format()
                speech_list += Pauser.make_ms_pause_level_list(
                    ms_retry_query, 3.5)
                FreePlayAttr.reset_attr_query_format(handler_input)

            prompt = FPPrompts.get_q_fp_setup_prompt(handler_input)
            reprompt = FPPrompts.get_q_fp_setup_reprompt(handler_input)
            speech_list.append(prompt)

        ## Ask for times_tables slots
        else:
            q_times_tables, reprompt = (
                FPTimesTables.get_q_times_tables_input() for _ in range(2))
            q_times_tables = CardFuncs.format_prompt(q_times_tables)
            speech_list.append(q_times_tables)
            reprompt = LastPrompt.get_last_prompt(handler_input)

        ModeStats.translate_mode_stats_to_sesh(handler_input)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Exemplo n.º 4
0
    def get_clause(tup_data) -> str:
        """Helper func: returns clause from tup_data using recursion."""
        if not tup_data:
            return ''

        elif isinstance(tup_data, str):
            return tup_data

        elif isinstance(tup_data, (int, float)):
            return Pauser.get_p_level(tup_data)

        elif isinstance(tup_data, (tuple, list)):

            if isinstance(tup_data[0], str):
                ## List of strings, return choice.
                return random.choice(tup_data)

            else:
                # Use Tuples in tuple to create message
                speech_list = []
                for clause_list in tup_data:
                    clause = get_clause(clause_list)
                    speech_list.append(clause)

                return str_joiner.join(speech_list)
        else:
            logger.warning(f"get_clause: Unrecognized data type {tup_data}")
Exemplo n.º 5
0
    def handle(self, handler_input):
        logger.info("HAN    ActDescriptHandler")
        speech_list = []

        activity = SlotUtils.get_resolved_value( handler_input, "activity")

        if not activity:
            logger.info("ActDescriptHandler: Non-resolved activity.")
            ms_overall_descript = DescriptUtils.get_ms_overall_act_descript()
            speech_list.append( ms_overall_descript)
        
        else:
            DescriptUtils.set_attr(handler_input, activity)
            ms_act_descript = DescriptUtils.get_ms_corresponding_descript(activity)
            speech_list.append( ms_act_descript)
        
        prompt, reprompt = (
            DescriptUtils.get_q_play_activity(activity) for _ in range(2))
        prompt = CardFuncs.format_prompt(prompt)
        speech_list.append( Pauser.get_p_level(4))
        speech_list.append(prompt)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)

        return (
            handler_input.response_builder
                .speak( speech)
                .ask( reprompt)
                .set_card( SimpleCard( card_title, card_text))
                .response)
Exemplo n.º 6
0
    def handle(self, handler_input):
        logger.info("HAN    RepeatHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []

        if 'recent_response' in attr:
            return RepeatUtils.get_recent_response(handler_input)


        ms_help = HelpUtils.get_ms_corresponding_help(handler_input)
        ms_prompt, reprompt = (
            HelpUtils.get_ms_corresponding_help(handler_input) for _ in range(2))
                
        speech_list.append( fallback.data.MS_FALLBACK)
        speech_list.append( Pauser.get_p_level(1))

        ## NOTE: This will need refinement if there are callbacks. 
        ## Develop relevant methods from FallbackUtils.
        speech_list.append( ms_help)
        speech_list.append( ms_prompt)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (
            handler_input.response_builder
                .speak( speech)
                .ask( reprompt)
                .set_card( SimpleCard(
                    card_title, card_text))
                .response)
Exemplo n.º 7
0
    def handle(self, handler_input):
        logger.info("HAN  FP_CorrectAnswerHandler")
        speech_list = []

        player_obj = PlayerDict.load_player_obj(handler_input)
        UserStats.update_player_stats(handler_input,
                                      correct=True,
                                      player_obj=player_obj)

        ms_congrats = CongratUtils.get_answer_congrats(handler_input,
                                                       player_obj=player_obj)
        ms_question = FPQuestions.get_question(handler_input)
        reprompt = FPQuestions.get_rephrased_question(handler_input)

        logger.debug(ms_congrats)

        if ms_congrats != "":
            speech_list += Pauser.make_ms_pause_level_list(
                ms_congrats, 1, ms_question)
        else:
            speech_list.append(ms_question)

        SessionStats.update_consecutive_correct(handler_input, correct=True)
        ModeStats.update_mode_stats(handler_input, correct=True)

        logger.debug(speech_list)
        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Exemplo n.º 8
0
    def handle(self, handler_input):
        logger.info("HAN  FP_AnsweredRequestedQuestionsHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []

        correct = QuestionChecker.check_answer(handler_input)
        UserStats.update_player_stats(handler_input, correct)

        ms_congrats = CongratUtils.get_player_congrats(handler_input, 2)

        num_questions = attr.get('num_questions', '')
        ms_answered_all_questions = FPSpeech.get_ms_answered_all_questions(
            num_questions)

        prompt, reprompt = (HelpUtils.get_q_what_todo() for _ in range(2))
        prompt = CardFuncs.format_prompt(prompt)

        speech_list += Pauser.make_ms_pause_level_list(
            ms_congrats, 1, ms_answered_all_questions, 3, prompt)

        SessionStats.update_consecutive_correct(handler_input, correct)
        ModeStats.update_mode_stats(handler_input, correct)
        ModeStats.translate_mode_stats_to_sesh(handler_input)
        FreePlayAttr.set_attr_end_fp(handler_input)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)

        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Exemplo n.º 9
0
    def handle(self, handler_input):
        logger.info("HAN  FP_WrongAnswerHandler")
        speech_list = []

        player_obj = PlayerDict.load_player_obj(handler_input)
        UserStats.update_player_stats(handler_input,
                                      correct=False,
                                      player_obj=player_obj)

        WrongAnswer.record_wrong_question(handler_input)
        ms_incorrect = IncorrectAnsUtils.get_buzz_and_incorrect()
        ms_retry_question = AllQuestionIntros.get_retry_question(handler_input)
        reprompt = GenQuestions.get_same_question(handler_input)

        speech_list += Pauser.make_ms_pause_level_list(ms_incorrect, 1,
                                                       ms_retry_question)

        SessionStats.update_consecutive_correct(handler_input, correct=False)
        ModeStats.update_mode_stats(handler_input, correct=False)

        logger.debug(speech_list)
        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
    def get_q_times_tables_input() -> str:
        """Returns prompt asking what times tables to practice.
        
        NOTE: Should add handler_input so can change example b/w prompt & reprompt,
        and depending on num logins, etc.
        """
        q_what_tables = get_linear_nlg(free_play.data.MMT_WHAT_TABLES_PRACTICE)
        if random.random() < 0.0:  ## TODO: Change chance of prompt.
            ms_example = FPTimesTables.get_example_tables_query()
        else:
            ms_example = FPTimesTables.get_example_table_range()

        speech_list = (q_what_tables,
                       Pauser.get_p_level(2), get_ms_try_saying(),
                       Pauser.get_p_level(0.75), ms_example)
        speech = ' '.join(speech_list)
        return MW_SLOW1.format(speech)
Exemplo n.º 11
0
    def handle(self, handler_input):
        logger.info("HAN  FP_AddTimesTablesHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []

        lower_table, upper_table, tables_query = (
            FreePlayAttr.get_times_table_input_slots(handler_input))
        retry_query = attr.get('inform_query_tables_format', False)

        if not tables_query:
            ms_can_add = FPTimesTables.get_ms_can_add_tables()
            speech_list += Pauser.make_ms_pause_level_list(ms_can_add, 2.5)

        else:
            FreePlayAttr.add_to_attr_times_tables(handler_input, lower_table,
                                                  upper_table, tables_query)

            if retry_query:
                ms_potential_mistake = FPTimesTables.get_ms_potential_mistake_parsing_query(
                )
                speech_list += Pauser.make_ms_pause_level_list(
                    ms_potential_mistake, 2)

            ms_added_tables = FPTimesTables.get_ms_added_tables(tables_query)
            speech_list += Pauser.make_ms_pause_level_list(
                ms_added_tables, 1.5)

            if retry_query:
                ms_retry_query = FPTimesTables.get_ms_can_retry_query_format()
                speech_list += Pauser.make_ms_pause_level_list(
                    ms_retry_query, 3.5)
                FreePlayAttr.reset_attr_query_format(handler_input)

        ## May like to add only if tables query??
        prompt = FPPrompts.get_q_fp_setup_prompt(handler_input)
        reprompt = FPPrompts.get_q_fp_setup_reprompt(handler_input)
        speech_list.append(prompt)

        ModeStats.translate_mode_stats_to_sesh(handler_input)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
    def get_ms_use_query_times_tables(times_tables: list) -> str:
        """Returns message that will use queried times tables."""
        ms_use_problems = FPTimesTables.get_ms_use_problems_start()
        times_tables = get_str_from_list(times_tables)

        speech_list = (
            ms_use_problems,
            free_play.data.MS_FROM,
            free_play.data.MT_USE_TABLES,
            Pauser.get_p_level(1),
            times_tables,
        )
        return get_linear_nlg(speech_list)
Exemplo n.º 13
0
    def handle(self, handler_input):
        logger.info("HAN    SC_StartHandler")
        speech_list = []

        SC_Attr.set_attr_start_sc(handler_input)
        player_obj = PlayerDict.load_player_obj(handler_input)
        difficulty = SlotUtils.get_resolved_value(handler_input, 'difficulty')

        if not difficulty:
            ms_welcome = SC_WelcomeUtils.get_ms_welcome(player_obj)
            q_difficulty, reprompt = (
                SC_Difficulty.get_q_sc_difficulty(player_obj)
                for _ in range(2))

            speech_list += Pauser.make_ms_pause_level_list(
                ms_welcome, 2, q_difficulty)

        elif difficulty:
            SC_Attr.set_sc_diff(handler_input, difficulty)
            ms_confirmation = ConfirmUtils.get_confirmation(True)
            ms_use_difficulty = SC_Difficulty.get_ms_using_difficulty(
                difficulty)

            SC_Questions.load_sc_questions(handler_input)
            ms_start_timer = SC_WelcomeUtils.get_ms_starting_time()
            question = SC_Questions.get_question(handler_input,
                                                 first_question=True)
            reprompt = question

            speech_list += Pauser.make_ms_pause_level_list(
                ms_confirmation, 0.5, ms_use_difficulty, 2, ms_start_timer,
                question)

            SC_Attr.save_start_time(handler_input)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Exemplo n.º 14
0
    def get_ms_fp_table_input() -> str:
        """Returns helps message for providing freeplay table parameters."""
        speech_list = [
            helper.data.MS_FP_TIMES_TABLES,
            Pauser.get_p_level(1),
            get_ms_try_saying(),
        ]
        if random.random() < 0.25:
            speech_list.append(FPTimesTables.get_example_tables_query())
        else:
            speech_list.append(FPTimesTables.get_example_table_range())

        return ' '.join(speech_list)
Exemplo n.º 15
0
    def handle(self, handler_input):
        logger.info("HAN  FP_SetTableBoundsHandler")
        speech_list = []

        lower_bound, upper_bound = FreePlayAttr.get_table_bound_slots(
            handler_input)
        FreePlayAttr.set_table_bounds(handler_input, lower_bound, upper_bound)
        bounds_provided = FreePlayLogic.check_table_bounds_provided(
            lower_bound, upper_bound)

        if bounds_provided:
            confirm = ConfirmUtils.get_random_confirmation(handler_input)
            ms_adjusted_table_bounds = FPUpperLowerBounds.get_ms_set_table_bounds(
                lower_bound, upper_bound)
            prompt = FPPrompts.get_q_fp_setup_prompt(handler_input)
            reprompt = FPPrompts.get_q_fp_setup_reprompt(handler_input)

            # QuestionAttr.increment_questions_answered(handler_input, increase=False)
            ## New question, but not counted as answered.

            speech_list += Pauser.make_ms_pause_level_list(
                confirm, 1, ms_adjusted_table_bounds, 2, prompt)

        else:
            ms_can_change_bounds = FPUpperLowerBounds.get_ms_can_change_table_bounds(
            )
            prompt, reprompt = (FPUpperLowerBounds.get_q_change_bounds()
                                for _ in range(2))
            speech_list += Pauser.make_ms_pause_level_list(
                ms_can_change_bounds, 2.5, prompt)

        ModeStats.translate_mode_stats_to_sesh(handler_input)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
    def get_q_sc_difficulty(player_object, ) -> str:
        """Master method to return what difficulty prompt."""
        sc_plays = player_object.sc_plays
        speech_list = []

        if sc_plays < 2:
            ms_difficulty_list = SC_Difficulty.get_ms_difficulty_list()
            ms_get_help = SC_Difficulty.h_get_ms_can_ask_help()

            speech_list += Pauser.make_ms_pause_level_list(
                ms_difficulty_list, 2.1, ms_get_help, 1.75)

        q_what_difficulty = SC_Difficulty.h_get_ms_what_difficulty()
        speech_list.append(q_what_difficulty)

        return ' '.join(speech_list)
    def get_example_tables_query() -> str:
        """Returns example of providing for times tables query."""
        speech_list = list(free_play.data.MMT_QUERY_TABLES_SETUP)

        random_tables = set()
        while len(random_tables) < 3:
            rand_num = random.randint(2, 10)
            random_tables.add(str(rand_num))

        random_tables = list(random_tables)
        random_tables.sort()

        sample_tables = ', and '.join(random_tables) + '.'
        sample_tables = MW_SLOW3.format(sample_tables)

        speech_list += Pauser.make_ms_pause_level_list(1, sample_tables)
        return MW_SLOW1.format(get_linear_nlg(speech_list))
Exemplo n.º 18
0
    def handle(self, handler_input):
        logger.info("HAN  FP_ParametersIntent")
        speech_list = []

        ms_confirm = ConfirmUtils.get_confirmation(True)
        ms_fp_params = FPSpeech.get_ms_fp_parameters(handler_input)

        prompt, reprompt = (LastPrompt.get_last_prompt(handler_input)
                            for _ in range(2))

        speech_list += Pauser.make_ms_pause_level_list(ms_confirm, 1,
                                                       ms_fp_params, 2.5,
                                                       prompt)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Exemplo n.º 19
0
    def handle(self, handler_input):
        logger.info("HAN    ModeStatsHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []
        player_obj = PlayerDict.load_player_obj(handler_input)

        mode = attr.get('mode', None)
        activity = SlotUtils.get_resolved_value(handler_input, 'activity')
        activity = activity if activity else mode
        difficulty = True

        if activity == 'survival':
            speech_list += ModeSpeech.get_ms_sm_stats(player_obj, activity)

        elif activity == 'speed':
            difficulty = SlotUtils.get_resolved_value(handler_input,
                                                      'difficulty')
            sc_difficulty = difficulty if difficulty else attr.get(
                'sc_difficulty', None)

            if (difficulty in speed_challenge.data.SC_DIFFICULTIES):
                speech_list += ModeSpeech.get_ms_sc_stats(
                    player_obj, sc_difficulty, activity)
            else:
                reprompt = ModeSpeech.get_ms_sc_what_difficulty()
                speech_list += reprompt
                reprompt = get_linear_nlg(reprompt)

        else:
            ms_can_tell_record = ModeSpeech.get_ms_can_tell_record()
            ms_example_saying = ModeSpeech.get_example_hear_records()
            speech_list = [ms_can_tell_record, 2, ms_example_saying]

            reprompt = HelpUtils.get_q_what_todo()

        if activity in ('survival', 'speed') and (difficulty):
            prompt, reprompt = (LastPrompt.get_last_prompt(handler_input)
                                for _ in range(2))
            speech_list += Pauser.make_ms_pause_level_list(3, prompt)

        speech = get_linear_nlg(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Exemplo n.º 20
0
    def handle(self, handler_input):
        logger.info("HAN    GetAnswerHandler")
        speech_list = []

        ms_answer = GetAnswerSpeech.get_ms_answer(handler_input)
        next_question = FPQuestions.get_question(handler_input)
        QuestionAttr.increment_questions_answered(handler_input,
                                                  False)  # undo increment.
        ## NOTE: would not need to de-increment with better modulation.

        speech_list += Pauser.make_ms_pause_level_list(ms_answer, 2,
                                                       next_question)

        reprompt = next_question

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Exemplo n.º 21
0
    def handle(self, handler_input):
        speech_list = []

        ms_confirm = ConfirmUtils.get_random_confirmation(handler_input)
        prompt, reprompt = (HelpUtils.get_q_what_todo() for _ in range(2))

        speech_list += Pauser.make_ms_pause_level_list(ms_confirm, 2, prompt)

        ModeStats.translate_mode_stats_to_sesh(handler_input)

        ## Set end all attr
        FreePlayAttr.set_attr_end_fp(handler_input)
        SM_Attr.set_attr_end_survival_mode(handler_input)
        SC_Attr.set_attr_end_sc(handler_input)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Exemplo n.º 22
0
    def handle(self, handler_input):
        logger.info("HAN    FallbackHandler")
        FallbackUtils.log_fallback_intent(handler_input)
        speech_list = []

        # ms_help = HelpUtils.get_ms_corresponding_help(handler_input)
        ms_prompt, reprompt = (LastPrompt.get_last_prompt(handler_input)
                               for _ in range(2))

        speech_list.append(data.MS_FALLBACK)
        speech_list.append(Pauser.get_p_level(1))

        ## NOTE: ms_help needs refinement if help after fallback handler.
        ## Develop relevant methods from FallbackUtils.
        # speech_list.append( ms_help)
        speech_list.append(ms_prompt)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Exemplo n.º 23
0
    def handle(self, handler_input):
        # type (HandlerInput) -> Response
        logger.info("HAN    HelpHandler")
        speech_list = []

        ms_help = HelpUtils.get_ms_corresponding_help(handler_input)
        prompt, reprompt = (
            LastPrompt.get_last_prompt(handler_input) for _ in range(2))

        speech_list += Pauser.make_ms_pause_level_list( ms_help, 3, prompt)

        speech = ' '.join(speech_list)
        
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (
            handler_input.response_builder
                .speak(speech)
                .ask(reprompt)
                .set_card( SimpleCard(
                    card_title, card_text))
                .response)
Exemplo n.º 24
0
    def handle(self, handler_input):
        logger.info("HAN    NumQuestionsAnsweredHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []

        questions_answered = attr.get('questions_answered', 0)
        ms_confirm = ConfirmUtils.get_player_confirmation(handler_input)

        ms_ans_questions = random.choice(
            mult_questions.data.MT_NUM_QUESTIONS_ANS).format(
                questions_answered)

        prompt, reprompt = (LastPrompt.get_last_prompt(handler_input)
                            for _ in range(2))
        speech_list += Pauser.make_ms_pause_level_list(ms_confirm, 1,
                                                       ms_ans_questions, 2,
                                                       prompt)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Exemplo n.º 25
0
    def handle(self, handler_input):
        logger.info("HAN    SM_StartHandler")
        speech_list = []

        SM_Attr.set_attr_start_survival_mode(handler_input)
        ModeStats.translate_mode_stats_to_sesh(handler_input)

        ms_welcome = SM_WelcomeUtils.get_ms_welcome(handler_input)
        ms_question = SMQuestions.get_question(handler_input, first_question= True)
        reprompt = GenQuestions.get_same_question(handler_input)
        
        speech_list += Pauser.make_ms_pause_level_list( 
            ms_welcome, 2, ms_question)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (
            handler_input.response_builder
                .speak( speech)
                .ask( reprompt)
                .set_card( SimpleCard( card_title, card_text))
                .response)
    def return_unknown_slot_response(handler_input) -> object:
        """If cannot find answer slot, returns same response prompt.
        
        NOTE: Can probably just return last response object.
        """
        speech_list = []
        attr = handler_input.attributes_manager.session_attributes

        ms_not_understand = get_linear_nlg(fallback.data.MMT_NOT_UNDERSTAND)

        if attr.get('mode', None) == 'free_play':
            prompt, reprompt = (GenQuestions.get_same_question(handler_input)
                                for _ in range(2))
        else:
            prompt, reprompt = (LastPrompt.get_last_prompt(handler_input)
                                for _ in range(2))

        speech_list += Pauser.make_ms_pause_level_list(ms_not_understand, 2,
                                                       prompt)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Exemplo n.º 27
0
 def get_ms_free_play() -> str:
     """Returns helps message for freeplay game mode."""
     speech_list = (helper.data.MS_FP_OVERVIEW, Pauser.get_p_level(0.5),
                    helper.data.MS_FP_STD_PARAMS, Pauser.get_p_level(1.5),
                    FPUpperLowerBounds.get_ms_can_change_table_bounds())
     return ' '.join(speech_list)
Exemplo n.º 28
0
    def handle(self, handler_input):
        logger.info("HAN  FP_StartHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []

        ## Set attr & get slots
        FreePlayAttr.set_attr_free_play(handler_input)

        ## Get table_input to start game.
        lower_table, upper_table, tables_query = (
            FreePlayAttr.get_times_table_input_slots(handler_input))
        FreePlayAttr.set_attr_times_tables(handler_input, lower_table,
                                           upper_table, tables_query)

        ## Logic check
        retry_query = attr.get('inform_query_tables_format', False)
        tables_provided = FreePlayLogic.check_tables_provided(
            lower_table, upper_table, tables_query)
        tables_exist = FreePlayLogic.check_tables_exist(handler_input)

        log_all(retry_query, tables_exist)

        ## Confirmation
        if tables_provided or tables_exist:

            if retry_query:
                ms_potential_mistake = FPTimesTables.get_ms_potential_mistake_parsing_query(
                )
                speech_list += Pauser.make_ms_pause_level_list(
                    ms_potential_mistake, 2)
            else:
                ms_confirm = ConfirmUtils.get_confirmation(punct=True)
                speech_list += Pauser.make_ms_pause_level_list(ms_confirm, 1)

            if tables_provided:
                ms_using_tables = (
                    FPTimesTables.get_ms_using_tables_from_input(
                        lower_table, upper_table, tables_query))
            elif tables_exist:
                ms_using_tables = None  # Create method to use existing tables.
            speech_list += Pauser.make_ms_pause_level_list(ms_using_tables, 2)

            if retry_query:
                ms_retry_query = FPTimesTables.get_ms_can_retry_query_format()
                speech_list += Pauser.make_ms_pause_level_list(
                    ms_retry_query, 3.5)
                FreePlayAttr.reset_attr_query_format(handler_input)

            ms_first_problem = FPQuestions.get_question(handler_input,
                                                        first_question=True)
            speech_list.append(ms_first_problem)

            reprompt = FPQuestions.get_rephrased_question(handler_input)

        if not tables_provided:
            ms_welcome = FPSpeech.get_ms_welcome(handler_input)
            q_times_tables, reprompt = (
                FPTimesTables.get_q_times_tables_input() for _ in range(2))
            q_times_tables = CardFuncs.format_prompt(q_times_tables)

            speech_list += Pauser.make_ms_pause_level_list(
                ms_welcome, 1.5, q_times_tables)

        ModeStats.translate_mode_stats_to_sesh(handler_input)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)