def quiz_beginning(ready_or_not): try: info_logger('********* IN QUIZ BEGIN INTENT *************') info_logger(request) info_logger('player_num : {} and category_name: {}'.format( player_num, category_name)) print(category_name, player_num) quiz_instance = Quiz(session.attributes) if quiz_instance.track_players_name(): return question(quiz_instance.track_players_name()) info_logger('user is ready or not: ' + ready_or_not) players = int(session.attributes['total_players']) category_selected = int(session.attributes['category_selected']) difficulty_level = session.attributes['difficulty'] quiz_data = middleware(players * 5, category_selected, difficulty_level) session.attributes['quiz_data'] = quiz_data session.attributes['counter'] = 0 speech_text = quiz_instance.initial_quiz_que() session.attributes['next_intent'] = 'QuestionAnswerIntent' except Exception as e: error_logger(e) speech_text = RESPONSE['ERROR_MSG'] return question(speech_text).reprompt(speech_text).simple_card( 'Question', speech_text)
def negative_response(): try: info_logger('********* IN AMAZON NO INTENT *************') speech_text = RESPONSE['ASK_READY_MSG'] except Exception as e: error_logger(e) speech_text = RESPONSE['ERROR_MSG'] return question(speech_text).reprompt('now Are you ready?').simple_card( 'QUIZ', speech_text)
def repeat_question(): try: info_logger('********* IN REPEAT QUESTION INTENT *************') info_logger('repeat question: ' + session.attributes['question']) speech_text = session.attributes['question'] except Exception as e: error_logger(e) speech_text = RESPONSE['ERROR_MSG'] return question(speech_text).reprompt(speech_text).simple_card( 'Question', speech_text)
def count_players(players_count): try: info_logger('********* IN PLAYER COUNT INTENT *************') info_logger('players count: {}'.format(players_count)) quiz_instance = Quiz(session.attributes) speech_text = quiz_instance.count_players_responses(int(players_count)) except Exception as e: error_logger(e) speech_text = RESPONSE['ERROR_MSG'] return question(speech_text).reprompt(speech_text).simple_card( 'Quiz', speech_text)
def select_difficulty(Difficulty): try: info_logger('********* IN DIFFICULTY LEVEL INTENT *************') if Difficulty.lower() not in DIFFICULTY.keys(): speech_text = RESPONSE['INVALID_DIFFICULTY'] else: session.attributes['difficulty'] = Difficulty info_logger('difficulty selected ' + Difficulty) speech_text = RESPONSE['GET_PLAYER_COUNT'] except Exception as e: error_logger(e) speech_text = RESPONSE['ERROR_MSG'] return question(speech_text).reprompt(speech_text).simple_card( 'Quiz', speech_text)
def select_category(category): try: info_logger('********* IN CATEGORY INTENT *************') info_logger('category name: ' + category) if category.lower() not in CATEGORY.keys(): speech_text = RESPONSE['INVALID_CATEGORY'] else: players = int(session.attributes['total_players']) session.attributes['quiz_data'] = middleware( players * 5, CATEGORY[category]) quiz_instance = Quiz(session.attributes) speech_text = quiz_instance.initial_quiz_que() except Exception as e: error_logger(e) speech_text = RESPONSE['ERROR_MSG'] return question(speech_text).reprompt(speech_text).simple_card( 'Quiz', speech_text)
def handle_players_info(name): try: info_logger('********* IN PLAYER NAME INTENT *************') info_logger(request) info_logger('players name: ' + name) quiz_instance = Quiz(session.attributes) if quiz_instance.track_player_count(): return question(quiz_instance.track_player_count()) elif 'next_intent' in session.attributes.keys(): return question(RESPONSE['ALEXA_MISSUNDERSTOOD']) elif request.intent['confirmationStatus'] == "DENIED": return question(RESPONSE['ASK_NAME_AGAIN']) speech_text = quiz_instance.players_info(name) except Exception as e: error_logger(e) speech_text = RESPONSE['ERROR_MSG'] return question(speech_text).reprompt(speech_text).simple_card( 'Quiz', speech_text)
def quiz_question_answer(answer): try: info_logger('********* IN QUESTION ANSWER INTENT *************') info_logger(request) info_logger('user answer is: ' + answer) quiz_instance = Quiz(session.attributes) if quiz_instance.track_players_name(): return question(quiz_instance.track_players_name()) quiz_que = session.attributes['question'] result_text = quiz_instance.check_answer( session.attributes['quiz_data'][quiz_que], answer.lower()) speech_text = '<speak>' + quiz_instance.quiz_progress( result_text).replace('&', '') + '</speak>' info_logger(speech_text) except Exception as e: error_logger(e) speech_text = RESPONSE['ERROR_MSG'] return question(speech_text).reprompt(speech_text).simple_card( 'QUIZ', speech_text)
def quiz_beginning(ready_or_not): try: info_logger('********* IN QUIZ BEGIN INTENT *************') info_logger(request) quiz_instance = Quiz(session.attributes) if quiz_instance.track_players_name(): return question(quiz_instance.track_players_name()) info_logger('user is ready or not: ' + ready_or_not) players = int(session.attributes['total_players']) quiz_data = middleware(players * 5, 9) session.attributes['quiz_data'] = quiz_data session.attributes['counter'] = 0 speech_text = quiz_instance.initial_quiz_que() session.attributes['next_intent'] = 'QuestionAnswerIntent' except Exception as e: error_logger(e) speech_text = RESPONSE['ERROR_MSG'] return question(speech_text).reprompt(speech_text).simple_card( 'Question', speech_text)
def select_category(category): try: info_logger('********* IN CATEGORY INTENT *************') if category.lower() not in CATEGORY.keys(): speech_text = RESPONSE['INVALID_CATEGORY'] else: session.attributes['category_name'] = category session.attributes['category_selected'] = CATEGORY[category] info_logger('category_name var value: ' + category_name) speech_text = RESPONSE['GET_DIFFICULTY_LEVEL'] except Exception as e: error_logger(e) speech_text = RESPONSE['ERROR_MSG'] return question(speech_text).reprompt(speech_text).simple_card( 'Quiz', speech_text)