def exe(userID, data, response, altResponse, choice, optionMatched, valid, maxRetry): if (not valid): if (maxRetry): return [], valid qresult = search.search_article(data['data']['text'].replace( '#search', '')) if (not qresult): response = spiel.text(userID, 'FS-02') response += router.route(userID, 'main') return response, valid response = [] topResult = qresult[0]['title'] for r in qresult: # response += spiel.free_text(''+r['title']+' - '+r['description'], 0) response += spiel.btn_menu('' + r['title'] + ' - ' + r['description'], [{ "type": "postback", "buttonName": "READ", "payload": "#read " + r['title'], "syns": [] }]) response += spiel.free_text( 'You can read more about the article by typing:\ \n#read then the article name. Example: #read ' + topResult, 0) response += router.route(userID, 'main') return response, valid
def exe(userID, data, response, altResponse, choice, optionMatched, valid, maxRetry): if (not valid): if (maxRetry): return [], valid response = [] userQuery = data['data']['text'] if (len(userQuery.split()) > 1): response = spiel.text(userID, 'FS-10') response += router.route(userID, 'dictionary.search') return response, valid result = dictionary.get(userQuery) if (result): response += spiel.free_text(result.pop(0), 0) if (len(result) > 0): response += router.route(userID, 'article.continue') convo_data.save_item(userID, 'article_cache', json.dumps(result)) else: response += router.route(userID, 'main') else: response = spiel.text(userID, 'FS-06') response += router.route(userID, 'main') return response, valid
def exe(userID, data, response, altResponse, choice, optionMatched, valid, maxRetry): if (not valid): if (maxRetry): return [], valid if (optionMatched == 0): response = router.route(userID, 'dictionary.read', data) if (optionMatched == 1): response = router.route(userID, 'main') return response, valid
def exe(userID, data, response, altResponse, choice, optionMatched, valid, maxRetry): if( not valid ): if( maxRetry ): return [], valid if( optionMatched == 0 ): response = router.route(userID, 'article.article') if( optionMatched == 1 ): response = router.route(userID, 'dictionary.search') # if( optionMatched == 2 ): # response = router.route(userID, 'reference.reference') return response, valid
def exe(userID, data, response, altResponse, choice, optionMatched, valid, maxRetry): if( not valid ): response = router.route(userID, "main") return response, valid if( optionMatched == 0 ): response = router.route(userID, "main") if( optionMatched == 1 ): print('Viewing updates') response = spiel.free_text(_uxy_core.update_notes, 0) response += router.route(userID, "main") return response, valid
def exe(userID, data, response, altResponse, choice, optionMatched, valid, maxRetry): if( not valid ): if( maxRetry ): return [], valid response += router.route(userID, 'end') return response, valid
def exe(userID, data, response, altResponse, choice, optionMatched, valid, maxRetry): if (not valid): if (maxRetry): return [], valid quizAns = int(convo_data.get_item(userID, 'nihongo_ans')) if (quizAns == optionMatched): response = spiel.free_text( 'Correct! (Just type #exit to quit practicing)', 0) else: response = spiel.free_text( 'Wrong! (Just type #exit to quit practicing)', 0) alphaChoices = ['A', 'B', 'C', 'D'] response += spiel.free_text('ANS: ' + alphaChoices[quizAns], 0) charType = convo_data.get_item(userID, 'nihongoCharType') charList = convo_data.get_item(userID, 'nihongoCharlist') quiz = generate_quiz.generate(userID, charType, charList) quizChoices = [] for item in quiz['choices']: quizChoices.append(item) quizSpiel = charType + " " + quiz['testChar'] + "\n"\ + "Choices:\n"\ + "A - " + quizChoices[0] + "\n"\ + "B - " + quizChoices[1] + "\n"\ + "C - " + quizChoices[2] + "\n"\ + "D - " + quizChoices[3] + "\n" response += spiel.free_text(quizSpiel, 0) response += router.route(userID, 'nihongo.quiz') return response, valid
def exe(userID, data, response, altResponse, choice, optionMatched, valid, maxRetry): if (not valid): if (maxRetry): return [], valid charType = convo_data.get_item(userID, 'nihongoCharType') if (optionMatched == 0): convo_data.save_item(userID, 'nihongoCharlist', 'basic') quiz = generate_quiz.generate(userID, charType, 'basic') elif (optionMatched == 1): convo_data.save_item(userID, 'nihongoCharlist', 'combo') quiz = generate_quiz.generate(userID, charType, 'combo') else: return response quizChoices = [] for item in quiz['choices']: quizChoices.append(item) quizSpiel = charType + " " + quiz['testChar'] + "\n"\ + "Choices:\n"\ + "A - " + quizChoices[0] + "\n"\ + "B - " + quizChoices[1] + "\n"\ + "C - " + quizChoices[2] + "\n"\ + "D - " + quizChoices[3] + "\n" response += spiel.free_text(quizSpiel, 0) response += router.route(userID, 'nihongo.quiz') return response, valid
def exe(userID, data, response, altResponse, choice, optionMatched, valid, maxRetry): if (not valid): if (maxRetry): return [], valid article_cache = convo_data.get_item(userID, 'article_cache') article_cache = json.loads(article_cache) response += spiel.free_text(article_cache.pop(0), 0) if (len(article_cache) > 0): response += router.route(userID, 'dictionary.continue') convo_data.save_item(userID, 'article_cache', json.dumps(article_cache)) else: response += router.route(userID, 'main') return response, valid
def exe(userID, data, response, altResponse, choice, optionMatched, valid, maxRetry): if (not valid): if (maxRetry): return [], valid if (optionMatched == 0): response = router.route(userID, 'nihongo.menu') return response, valid
def exe(userID, data, response, altResponse, choice, optionMatched,\ valid, maxRetry): """ Execute Unit """ # Catch Invalid User Input if( not valid ): if( maxRetry ): return [], valid # Route to next state response += router.route(userID, '<ROUTE TO NEXT STATE>') return response, valid
def exe(userID, data, response, altResponse, choice, optionMatched, valid, maxRetry): if (not valid): if (maxRetry): return [], valid if (optionMatched == 0): convo_data.save_item(userID, 'nihongoCharType', 'hiragana') if (optionMatched == 1): convo_data.save_item(userID, 'nihongoCharType', 'katakana') response = router.route(userID, "nihongo.charlist") return response, valid
def exe(userID, data, response, altResponse, choice, optionMatched, valid, maxRetry): if (not valid): if (maxRetry): return [], valid res = ptoe.get(data['data']['text'].lower().replace('#element', '')) if (res): response = spiel.free_text(res['header'], 0) response += spiel.btn_menu( res['info'], [{ "type": "postback", "buttonName": "Description", "payload": "#elementDesc " + res['element'], "syns": [] }]) response += router.route(userID, 'main') return response, valid