def main(user): action = { 'type': 'what_have_i_got', 'image_url': util.get_image('hero/hero_stand'), 'bg_image_url': util.get_image('bg/fof-map-gauss2', extension='.jpg') } paid_gem = user.paid_gem free_gem = user.free_gem original_texts = [{ 'text': 'USER_GEMS', 'kwargs': { 'paid_gem': paid_gem, 'free_gem': free_gem } }] total_gem = paid_gem + free_gem if total_gem >= 300: original_texts.append({'text': 'ASK_GANESHA'}) action['node'] = 'ask_ganesha' else: original_texts.append({'text': 'ASK_GEM_PACK'}) action['node'] = 'ask_gem_pack' action['product_name'] = 'gem_1000' action['original_texts'] = original_texts return action
def re_ask(node, turn_times, not_enough_gem=0): action = { 'type': 'ganesha', 'image_url': util.get_image('gods/ganesha'), 'bg_image_url': util.get_image('bg/ganesha-shop', extension='.jpg'), 'set_should_end_session': False } if node == 'welcome': text = nodes.recommend_ten() if node == 'recommend_gatcha': text = nodes.recommend_gatcha() if node == 'recommend_gem': text = nodes.recommend_gem(turn_times, not_enough_gem) action.update(text) return action
def ganesha(): return { 'original_texts': [{ 'text': 'WELCOME_TO_GANESHA_SHOP', }, { 'text': 'SALES_GATCHA' }, { 'text': 'RECOMMEND_TEN' }], 'turn_times': 10, 'type': 'ganesha', 'node': 'welcome', 'image_url': util.get_image('gods/ganesha'), 'bg_image_url': util.get_image('bg/ganesha-shop', extension='.jpg'), 'set_should_end_session': False }
def main(node, user, intent): if intent == 'AMAZON.NoIntent': return { 'type': 'cancel_or_stop', 'image_url': util.get_image('hero/hero_anticipation'), 'bg_image_url': util.get_image('bg/fof-map-gauss2', extension='.jpg'), 'original_texts': [{ 'text': 'APPRECIATE_ON_STOP', 'kwargs': { 'appreciate': hero.get_appreciate_message() } }, { 'text': 'PLEASE_AGAIN_ON_STOP' }] } if intent not in ['AMAZON.YesIntent', 'UseIntent']: return nodes.re_ask(user, intent) _node_map = {'launch': nodes.launch, 'use_ticket': nodes.use_ticket} node_handler = _node_map.get(node, nodes.re_ask) return node_handler(user, intent)
def action_report(destination, monster: str): if monster == 'MONSTER_PRECHAT': return { 'original_texts': { 'text': 'HERO_ACTION_REPORT_PRECHAT', 'kwargs': { 'destination': destination } }, 'image_url': util.get_image(f'reports/{monster.lower()}'), 'bg_image_url': util.get_image(f'bg/fof-map-gauss2', extension='.jpg') } return { 'original_texts': { 'text': 'HERO_ACTION_REPORT', 'kwargs': { 'destination': destination, 'monster': monster } }, 'image_url': util.get_image(f'reports/{monster.lower()}'), 'bg_image_url': util.get_image(f'bg/fof-map-gauss2', extension='.jpg') }
def main(env, alexa_user_id, intent, product_reference_name): action = { 'type': 'end' } if intent == 'CancelOrStopIntent': return { 'type': 'cancel_or_stop', 'image_url': util.get_image('hero/hero_anticipation'), 'bg_image_url': util.get_image( 'bg/fof-map-gauss2', extension='.jpg'), 'original_texts': [ { 'text': 'APPRECIATE_ON_STOP', 'kwargs': { 'appreciate': hero.get_appreciate_message() } }, {'text': 'PLEASE_AGAIN_ON_STOP'} ] } elif intent == 'Connections.Response': if not product_reference_name: return { 'type': 'ganesha', 'node': 'ask_ganesha', 'original_texts': [ { 'text': 'ASK_GO_TO_GANESHA_SHOP' } ] } with DynamoCtl(env, alexa_user_id) as dynamo_ctl: _user = user.get_user(alexa_user_id, dynamo_ctl.attr) added = _user.buy_gem(product_reference_name) if not added: return { 'type': 'ganesha', 'node': 'ask_ganesha', 'original_texts': [ { 'text': 'ASK_GO_TO_GANESHA_SHOP' } ] } dynamo_ctl.attr = _user.attr return { 'type': 'ganesha', 'node': 'ask_ganesha', 'original_texts': [ { 'text': 'ADD_GEM', 'kwargs': { 'paid_gem': added['paid_gem'], 'free_gem': added['free_gem'] } }, { 'text': 'CURRENT_GEM', 'kwargs': { 'paid_gem': _user.paid_gem, 'free_gem': _user.free_gem } }, { 'text': 'ASK_GO_TO_GANESHA_SHOP' } ] } return action
def main(turn_times, node_key, user, total_ticket_amount, intent, not_enough_gem): action = { 'type': 'ganesha', 'image_url': util.get_image('gods/ganesha'), 'bg_image_url': util.get_image('bg/ganesha-shop', extension='.jpg'), 'set_should_end_session': False } if node_key == 'launch': node = nodes.launch() elif node_key == 'welcome': if should_gatcha(turn_times): is_paid, not_enough_gem = user.pay_gem( consts.gem_amount_map[turn_times]) if is_paid: items = gatcha(turn_times) node = nodes.gatcha(turn_times, items, user) else: node = nodes.recommend_gem(turn_times, not_enough_gem) node['is_paid'] = is_paid else: node = nodes.recommend_gatcha() elif node_key == 'recommend_gatcha': if should_gatcha(turn_times): is_paid, not_enough_gem = user.pay_gem( consts.gem_amount_map[turn_times]) if is_paid: items = gatcha(turn_times) node = nodes.gatcha(turn_times, items, user) else: node = nodes.recommend_gem(turn_times, not_enough_gem) node['is_paid'] = is_paid else: node = nodes.end() elif node_key == 'gatcha': if should_gatcha(turn_times): is_paid, not_enough_gem = user.pay_gem( consts.gem_amount_map[turn_times]) if is_paid: items = gatcha(turn_times) node = nodes.gatcha(turn_times, items, user) else: node = nodes.recommend_gem(turn_times, not_enough_gem) node['is_paid'] = is_paid else: node = nodes.end() elif node_key == 'result': node = nodes.result(total_ticket_amount, turn_times, user) elif node_key == 'recommend_gem': if intent == 'AMAZON.NoIntent': node = nodes.end() else: return re_ask('recommend_gem', turn_times, not_enough_gem) else: node = {'original_texts': [{'text': ''}]} # lambdaのインプットであるturn_timesよりも、nodes.pyで指定しているturn_timesを優先する。 accept = bool(node.get('turn_times', turn_times)) is_paid = node.get('is_paid') total_ticket_amount = node.get('total_ticket_amount') if total_ticket_amount: set_gatcha_result(user, 'chronus_ticket', total_ticket_amount) node['node'] = change_node(node_key, accept, is_paid) action.update(node) action['user_attr'] = user.attr return action
def main(user, node, intent): action = { 'type': 'launch', 'image_url': util.get_image('hero/hero_stand'), 'bg_image_url': util.get_image('bg/fof-map-gauss2', extension='.jpg') } if node == 'buy_ticket': if intent in ['AMAZON.YesIntent', 'BuyIntent']: return nodes.ganesha() elif intent == 'AMAZON.NoIntent': return nodes.end() else: return nodes.re_ask() original_texts = [hero.message()] if user.is_first_launch_today: if user.destination: # 昨日の活動報告を聞く action_parts = hero.action_report(user.destination, user.content) original_texts.append(action_parts['original_texts']) action['image_url'] = action_parts['image_url'] action['bg_image_url'] = action_parts['bg_image_url'] # 信者を獲得 user.increase_follower() original_texts.append(hero.increase_follower( user.follower_increase)) original_texts.append(hero.total_followers( user.follower_total_amount)) # 昨日のお告げによって目的地へは行って帰ってきたのでクリア user.clear_destination() # 今日の目的地ガチャ user.set_event() if user.has_todays_oracle: original_texts.append({ 'text': f'本日は「{user.destination}」へ向かうお告げを完了しています。' }) if has_chronus_ticket(user): original_texts.append({ 'text': 'CONFIRM_CHRONUS_TICKET' }) action['type'] = 'use' action['node'] = 'use_ticket' else: original_texts.append({ 'text': 'RECOMMEND_CHRONUS_TICKET' }) action['type'] = 'launch' action['node'] = 'buy_ticket' action['set_should_end_session'] = False else: destinations_choice = random.sample(util.get_village_names(), 2) ask_oracle_text = hero.ask_oracle(destinations_choice) original_texts.append(ask_oracle_text) action = {'type': 'oracle', 'set_should_end_session': False, 'destinations_choice': destinations_choice, 'image_url': action.get('image_url', util.get_image('hero/hero_stand')), 'bg_image_url': action.get( 'bg_image_url', util.get_image( 'bg/fof-map-gauss2', extension='.jpg')) } action['user_attr'] = user.attr action['original_texts'] = original_texts return action