Skip to content

Commit ca5bf69

Browse files
committed
shiritori: Exception -> Enum
- return structured enum instead of exception - refresh tests dependencies and lint rules
1 parent 601eaf7 commit ca5bf69

File tree

8 files changed

+800
-1007
lines changed

8 files changed

+800
-1007
lines changed

functions/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"parserOptions": {
3-
"ecmaVersion": 7,
3+
"ecmaVersion": 8,
44
"sourceType": "module"
55
},
66
"extends": ["semistandard"],

functions/index.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ admin.initializeApp();
2828
const corpus = 'noun';
2929

3030
const dict = k => admin.database()
31-
.ref(corpus).child(k)
32-
.once('value')
33-
.then(snap => snap.val());
31+
.ref(corpus).child(k)
32+
.once('value')
33+
.then(snap => snap.val());
3434

3535
const app = actionssdk({
3636
// リクエストとレスポンスをロギングする。
@@ -47,28 +47,27 @@ app.intent('actions.intent.MAIN', conv => {
4747
conv.ask('どうぞ、始めて下さい');
4848
});
4949

50-
app.intent('actions.intent.TEXT', (conv, input) => {
51-
return shiritori.interact(dict, input, conv.data.used)
52-
.then(result => {
53-
conv.data.used.unshift(input);
54-
conv.data.used.unshift(result.word);
55-
conv.ask(new SimpleResponse({
56-
speech: result.word,
57-
text: `${result.word} [${result.kana}]`
58-
}));
59-
})
60-
.catch(reason => {
61-
switch (reason.constructor) {
62-
case shiritori.Win:
63-
conv.close('すごい!あなたの勝ちです。');
64-
break;
65-
case shiritori.Bad:
66-
conv.close('ざんねん。あなたの負けです。');
67-
break;
68-
default:
69-
throw reason;
70-
}
71-
});
50+
app.intent('actions.intent.TEXT', async (conv, input) => {
51+
const result = await shiritori.interact(dict, input, conv.data.used);
52+
switch (result.state) {
53+
case shiritori.state.CONTINUE:
54+
conv.data.used.unshift(input);
55+
conv.data.used.unshift(result.word);
56+
conv.ask(new SimpleResponse({
57+
speech: result.word,
58+
text: `${result.word} [${result.kana}]`
59+
}));
60+
break;
61+
case shiritori.state.LOOSE_N:
62+
case shiritori.state.LOOSE_USED:
63+
case shiritori.state.LOOSE_CHAIN:
64+
conv.close('ざんねん。あなたの負けです。');
65+
break;
66+
case shiritori.state.WIN_N:
67+
case shiritori.state.WIN_USED:
68+
conv.close('すごい!あなたの勝ちです。');
69+
break;
70+
}
7271
});
7372

7473
exports.shiritoriV3 = functions.https.onRequest(app);

0 commit comments

Comments
 (0)