def handle(self, handler_input): logger.info("HAN CreateUserProfileHandler") user_name = SlotUtils.get_first_slot_value(handler_input) if not user_name: logger.info("HAN RetryUserName") ms_welcome = UserProfileUtils.get_ms_welcome(handler_input) ms_retry_name = UserProfileUtils.get_ms_did_not_hear_name() prompt, reprompt = ( UserProfileUtils.get_q_retry_name() for _ in range(2)) prompt = CardFuncs.format_prompt(prompt) speech_list = ( ms_welcome, 0.5, ms_retry_name, 1.75, prompt ) else: logger.info("HAN CreatedProfile") UserProfileUtils.set_sesh_attr(handler_input, user_name) PlayerDict.create_new_player(handler_input, user_name) ms_confirm = ConfirmUtils.get_player_confirmation(handler_input) ms_created_first_profile = UserProfileUtils.get_ms_created_first_profile(handler_input) ms_overview = HelpUtils.get_ms_act_descript() prompt, reprompt = ( HelpUtils.get_q_what_todo() for _ in range(2)) prompt = CardFuncs.format_prompt(prompt) speech_list = ( ms_confirm, 1, ms_created_first_profile, 3, ms_overview, 2.25, 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)
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)
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)
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)
def get_q_fp_setup_reprompt(handler_input) -> str: """Returns reprompt for freeplay setup handlers.""" attr = handler_input.attributes_manager.session_attributes if (attr.get('mode', None) == "free_play" and attr.get('times_tables', None) not in (None, [])): prompt = GenQuestions.get_same_question(handler_input) else: prompt = HelpUtils.get_q_what_todo() return CardFuncs.format_prompt(prompt)
def get_q_fp_setup_prompt(handler_input) -> str: """Returns prompt for freeplay setup handlers.""" attr = handler_input.attributes_manager.session_attributes if (attr.get('mode', None) == "free_play" and attr.get('times_tables', None) not in (None, [])): prompt = FPPrompts.get_fp_question(handler_input) elif (attr.get('mode', None) == "free_play"): prompt = FPTimesTables.get_ms_can_add_tables() else: prompt = FPPrompts.get_q_start_fp(handler_input) return CardFuncs.format_prompt(prompt)
def get_question( handler_input, player_object: object, practice_type: str, first_question: bool = False, ) -> str: """Asks the user a multiplication question based on custom practice type.""" attr = handler_input.attributes_manager.session_attributes if not first_question: QuestionAttr.increment_questions_answered(handler_input) flag_get_new_question = True while flag_get_new_question: new_question = CP_QuestionByType.get_question_type( handler_input, player_object, practice_type) if (not GenQuestions.check_same_question(handler_input, new_question) or practice_type == custom_practice.data.PRACT_TYPES[ 0] # can repeat on incorrect from date. ): flag_get_new_question = False ## Message Intro ms_intro = CP_Questions.get_ms_question_intro(handler_input, player_object, practice_type, first_question, new_question) ## Save Question QuestionAttr.save_question( handler_input, new_question ) # NOTE: Save question after for duplicates on incorrect-problems. ms_question = GenQuestions.format_question(new_question) ## Punct for interrogative if attr.get('interrogative_question', False): punct = '?' attr['interrogative_question'] = False else: punct = '' speech_list = (ms_intro, ' ', ms_question, punct) speech = ''.join(speech_list) return CardFuncs.format_prompt(speech)
def get_last_prompt(handler_input) -> str: """Returns the prompt used in the previous response. first checks if existing question to be asked. If so, asks the question. If function saved, uses function. Elif str prompt saved, uses cached from response interceptor. Else, uses HelpUtils.get_corresponding_message. """ attr = handler_input.attributes_manager.session_attributes ## Free Play Questions question = attr.get('question', None) flag_in_game = attr.get( 'mode', None) in aux_data.skill_data.MODE_ACT_DICT.keys() log_all(question, flag_in_game) if (question and flag_in_game): prompt_user = GenQuestions.get_same_question(handler_input) ## Don't repeat help elif is_intent_name("AMAZON.HelpIntent")(handler_input): prompt_user = HelpUtils.get_q_what_todo() ## Standard questions ## NOTE: May like to save function references in the future. # saving functions may create more variety. # elif attr.get('prompt_func', False): # prompt_user = attr['prompt_func'] # attr['prompt_func'] = None # elif attr.get('prompt_ms', False): # prompt_user = attr['prompt_ms'] # attr['prompt_ms'] = None # else: # prompt_user = HelpUtils.get_ms_corresponding_help(handler_input) else: prompt_user = HelpUtils.get_q_what_todo() return CardFuncs.format_prompt(prompt_user)
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)
def get_q_user_profile() -> str: """Returns prompt asking for the user's name.""" prompt = helper.data.MS_FIRST_PLAY_NAME_REPROMPT return CardFuncs.format_prompt(prompt)
def get_q_what_todo() -> str: """Returns prompt asking the user what they want to do.""" ms_what_todo = random.choice(helper.data.MT_WHAT_TODO) ms_what_todo = CardFuncs.format_prompt(ms_what_todo) return ms_what_todo