diff --git a/core/skills-endpoints.json b/core/skills-endpoints.json index c104505c..76b9168d 100644 --- a/core/skills-endpoints.json +++ b/core/skills-endpoints.json @@ -20,11 +20,6 @@ "route": "/api/action/games/rochambeau/start", "params": [] }, - { - "method": "GET", - "route": "/api/action/games/rochambeau/setup", - "params": [] - }, { "method": "GET", "route": "/api/action/games/rochambeau/play", diff --git a/server/src/core/nlu.js b/server/src/core/nlu.js index d2130173..029e8dd6 100644 --- a/server/src/core/nlu.js +++ b/server/src/core/nlu.js @@ -225,30 +225,34 @@ class Nlu { return null } - const processedData = await this.brain.execute(this.nluResultObj, { mute: opts.mute }) - // Reprocess with the original utterance that triggered the context at first - if (processedData.core?.restart === true) { - const { originalUtterance } = this.conv.activeContext + try { + const processedData = await this.brain.execute(this.nluResultObj, { mute: opts.mute }) + // Reprocess with the original utterance that triggered the context at first + if (processedData.core?.restart === true) { + const { originalUtterance } = this.conv.activeContext - this.conv.cleanActiveContext() - await this.process(originalUtterance, opts) + this.conv.cleanActiveContext() + await this.process(originalUtterance, opts) + return null + } + + // In case there is no next action to prepare anymore + if (!processedData.action.next_action) { + this.conv.cleanActiveContext() + return null + } + + // Break the action loop and prepare for the next action if necessary + if (processedData.core?.isInActionLoop === false) { + this.conv.activeContext.isInActionLoop = !!processedData.action.loop + this.conv.activeContext.actionName = processedData.action.next_action + this.conv.activeContext.intent = `${processedData.classification.skill}.${processedData.action.next_action}` + } + + return processedData + } catch (e) /* istanbul ignore next */ { return null } - - // In case there is no next action to prepare anymore - if (!processedData.action.next_action) { - this.conv.cleanActiveContext() - return null - } - - // Break the action loop and prepare for the next action if necessary - if (processedData.core?.isInActionLoop === false) { - this.conv.activeContext.isInActionLoop = !!processedData.action.loop - this.conv.activeContext.actionName = processedData.action.next_action - this.conv.activeContext.intent = `${processedData.classification.skill}.${processedData.action.next_action}` - } - - return processedData } /** diff --git a/skills/games/guess_the_number/src/lib/db.py b/skills/games/guess_the_number/src/lib/db.py index 879a2d74..f7603f10 100644 --- a/skills/games/guess_the_number/src/lib/db.py +++ b/skills/games/guess_the_number/src/lib/db.py @@ -5,7 +5,7 @@ import utils # Skill database db = utils.db()['db'] -# Owner table +# Game table game_table = db.table('game') # Time stamp diff --git a/skills/games/rochambeau/nlu/en.json b/skills/games/rochambeau/nlu/en.json index 62b193ab..b5eb9aa4 100644 --- a/skills/games/rochambeau/nlu/en.json +++ b/skills/games/rochambeau/nlu/en.json @@ -8,44 +8,9 @@ "Can we play paper rock scissors?", "I want to play rochambeau" ], - "slots": [ - { - "name": "rounds_nb", - "item": { - "type": "entity", - "name": "number" - }, - "questions": [ - "How many rounds would you like to play?", - "How many rounds should I set?", - "Sure, how many rounds should I prepare?" - ] - }, - { - "name": "testo_email", - "item": { - "type": "entity", - "name": "email" - }, - "questions": [ - "Testo?" - ] - }, - { - "name": "testo_nb", - "item": { - "type": "entity", - "name": "number" - }, - "questions": [ - "Testo2?" - ] - } + "answers": [ + "Alright, let's get started!" ], - "next_action": "setup" - }, - "setup": { - "type": "logic", "next_action": "play" }, "play": { @@ -62,8 +27,8 @@ "type": "logic", "loop": { "expected_item": { - "type": "entity", - "name": "number" + "type": "resolver", + "name": "affirmation_denial" } } } @@ -73,27 +38,36 @@ }, "answers": { "ready": [ - "Alright, let's get started!" + "Let's get started!" + ], + "leon_emoji": [ + "%leon_emoji%" ], "equal": [ - "No point." + "No point.", + "It's a tie." ], "point_for_leon": [ "I got you. The %handsign_1% beats the %handsign_2%.", - "Yeaaah! The %handsign_1% beats the %handsign_2%.", - "Gotcha! The %handsign_1% beats the %handsign_2%." + "Yeaaah, I won! The %handsign_1% beats the %handsign_2%.", + "Gotcha! I got the point because the %handsign_1% beats the %handsign_2%." ], "point_for_player": [ "You got me. The %handsign_1% beats the %handsign_2%.", - "Aargh no. The %handsign_1% beats the %handsign_2%.", - "Well played! The %handsign_1% beats the %handsign_2%." + "Aargh no, you got the point. The %handsign_1% beats the %handsign_2%.", + "Well played! You got the point because the %handsign_1% beats the %handsign_2%." ], - "win": [ - "I won! Would you like a rematch?" + "ask_for_rematch": [ + "Do you want a rematch?", + "Should we go for another round?" ], - "lose": [ - "You're good at it! Can I get a rematch?", - "Congrats! Should we go for a rematch?" + "confirm_rematch": [ + "Be ready!", + "I'm not gonna let you win." + ], + "deny_rematch": [ + "As you wish.", + "Let me know anytime you want to play." ] } } diff --git a/skills/games/rochambeau/src/actions/play.py b/skills/games/rochambeau/src/actions/play.py index f4e95e45..4f8cad46 100644 --- a/skills/games/rochambeau/src/actions/play.py +++ b/skills/games/rochambeau/src/actions/play.py @@ -5,27 +5,26 @@ import random import utils def play(params): - """This is a test""" + """Define the winner""" handsigns = { 'ROCK': { 'superior_to': 'SCISSORS', - 'inferior_to': 'PAPER' + 'inferior_to': 'PAPER', + 'emoji': '✊' }, 'PAPER': { 'superior_to': 'ROCK', - 'inferior_to': 'SCISSORS' + 'inferior_to': 'SCISSORS', + 'emoji': '✋' }, 'SCISSORS': { 'superior_to': 'PAPER', - 'inferior_to': 'ROCK' + 'inferior_to': 'ROCK', + 'emoji': '✌' } } - entities, slots = params['entities'], params['slots'] - # TODO: make resolution more simple. E.g. slots['rounds_nb']['strValue']. Same for entities - rounds_nb = str(slots['rounds_nb']['resolution']['value']) - testo_email = str(slots['testo_email']['resolution']['value']) - testo_nb = str(slots['testo_nb']['resolution']['value']) + entities = params['entities'] player = { 'handsign': None, 'points': 0 @@ -40,29 +39,33 @@ def play(params): if entity['entity'] == 'handsign': player['handsign'] = entity['option'] - utils.output('inter', 'Just a test: ' + rounds_nb + ' + ' + testo_email + ' + ' + testo_nb) - # Exit the loop if no handsign has been found if player['handsign'] == None: - return utils.output('end', None, None, { 'isInActionLoop': False }) + utils.output('inter', None, None, { 'isInActionLoop': False }) + + leon_emoji = handsigns[leon['handsign']]['emoji'] + player_emoji = handsigns[player['handsign']]['emoji'] + + utils.output('inter', { 'key': 'leon_emoji', 'data': { 'leon_emoji': leon_emoji } }) if leon['handsign'] == player['handsign']: - return utils.output('end', 'equal') + utils.output('inter', 'equal') # Point for Leon - if handsigns[leon['handsign']]['superior_to'] == player['handsign']: - # TODO: increment +1 for Leon - return utils.output('end', { 'key': 'point_for_leon', + elif handsigns[leon['handsign']]['superior_to'] == player['handsign']: + utils.output('inter', { 'key': 'point_for_leon', 'data': { 'handsign_1': leon['handsign'].lower(), 'handsign_2': player['handsign'].lower() } }) - # TODO: increment +1 for player - return utils.output('end', { 'key': 'point_for_player', - 'data': { - 'handsign_1': player['handsign'].lower(), - 'handsign_2': leon['handsign'].lower() - } - }) + else: + utils.output('inter', { 'key': 'point_for_player', + 'data': { + 'handsign_1': player['handsign'].lower(), + 'handsign_2': leon['handsign'].lower() + } + }) + + return utils.output('end', 'ask_for_rematch', { 'isInActionLoop': False }) diff --git a/skills/games/rochambeau/src/actions/rematch.py b/skills/games/rochambeau/src/actions/rematch.py index dfbded5b..b544cce0 100644 --- a/skills/games/rochambeau/src/actions/rematch.py +++ b/skills/games/rochambeau/src/actions/rematch.py @@ -4,21 +4,19 @@ import utils def rematch(params): - """This is a test""" + """Take decision whether to do a rematch""" - entities, slots = params['entities'], params['slots'] - decision = 0 + resolvers = params['resolvers'] + decision = False - # Find entities - # TODO: replace with confirmation resolver - for item in params['entities']: - if item['entity'] == 'number': - decision = item['resolution']['value'] + for resolver in resolvers: + if resolver['name'] == 'affirmation_denial': + decision = resolver['value'] - if decision == 1: - return utils.output('end', 'Let\'s goooo', { + if decision == True: + return utils.output('end', 'confirm_rematch', { 'isInActionLoop': False, 'restart': True }) - return utils.output('end', 'As you wish', { 'isInActionLoop': False }) + return utils.output('end', 'deny_rematch', { 'isInActionLoop': False }) diff --git a/skills/games/rochambeau/src/actions/setup.py b/skills/games/rochambeau/src/actions/setup.py deleted file mode 100644 index 92d41c83..00000000 --- a/skills/games/rochambeau/src/actions/setup.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf-8 -*- - -import utils - -def setup(params): - """This is a test""" - - entities, slots = params['entities'], params['slots'] - - # TODO: use rounds_nb slot and save it in DB - - return utils.output('end', 'ready')