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 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 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 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 ): 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 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 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
def exe(userID, sessionName, userInput): choices = None inputValid = True matchedOption = None maxRetry = False responses = [] altResponse = [] view = get_view(sessionName) altDisplay = spiel.get_display(userID, "ERR-02") if (len(view['options']) == 0 and len(view['content']) > 0): displayID = view['content'][-1] display = spiel.get_display(userID, displayID) altResponse = [{ 'type': view['optionType'], 'data': display['data'], 'options': [], 'prefix': '', 'delay': display['delay'] }] else: altResponse = spiel.text(userID, "ERR-01") altResponse += [{ 'type': view['optionType'], 'data': altDisplay['data'], 'options': view['options'], 'prefix': '', 'delay': altDisplay['delay'] }] if (userInput != None): if ('any' not in view['acceptTypes']): if (userInput['type'] not in view['acceptTypes']): inputValid = False if (len(view['options']) > 0 and inputValid): inputData = None if (userInput['type'] == 'payload'): inputData = userInput['data']['payload'].lower() if (userInput['type'] == 'text'): inputData = userInput['data']['text'].lower() if (userInput['type'] == 'attachment'): inputData = userInput['data']['urls'][0]['payload'][ 'url'].lower() optionPos = 0 if (view['optionType'] == 'quick_reply' or view['optionType'] == 'btn'): for option in view['options']: for syn in option['syns']: if (inputData == syn or ' ' + syn + ' ' in inputData): matchedOption = optionPos if (matchedOption != None): break optionPos += 1 if (matchedOption == None): inputValid = False errorLog = int(convo_data.get_item(userID, 'errorLog')) + 1 if (view['retries']): if (errorLog >= view['retries']): maxRetry = True contents = view['content'] lastContent = None if (len(contents) > 1 and len(view['options']) > 0): lastContent = contents[-1] contents = contents[:len(contents) - 1] for displayID in contents: display = spiel.get_display(userID, displayID) responses.append({ 'type': 'text', 'data': display['data'], 'options': [], 'prefix': '', 'delay': display['delay'] }) if (view['optionType'] == 'btn'): for option in view['options']: if (option['type'] == 'web_url'): matches = re.findall(r"\{{(.*?)\}}", option['url']) if (len(matches) > 0): for match in matches: new_val = convo_data.get_item(userID, match) option['url'] = option['url'].replace( '{{' + match + '}}', new_val) if (len(view['options']) == 0): for displayID in contents: display = spiel.get_display(userID, displayID) responses.append({ 'type': 'text', 'data': display['data'], 'options': [], 'prefix': '', 'delay': display['delay'] }) elif (len(contents) == 1 and lastContent != None): choices = view['options'] display = spiel.get_display(userID, lastContent) responses.append({ 'type': view['optionType'], 'data': display['data'], 'options': view['options'], 'prefix': '', 'delay': display['display'] }) elif (len(contents) == 1): choices = view['options'] display = spiel.get_display(userID, contents[0]) responses.append({ 'type': view['optionType'], 'data': display['data'], 'options': view['options'], 'prefix': '', 'delay': display['delay'] }) else: choices = view['options'] display = spiel.get_display(userID, lastContent) responses.append({ 'type': view['optionType'], 'data': display['data'], 'options': view['options'], 'prefix': '', 'delay': display['delay'] }) if (_uxy_core.environment == 'dev'): state = '[STATE]: ' + sessionName responses = spiel.free_text(state, 0) + responses return responses, altResponse, choices, matchedOption, inputValid, maxRetry