Skip to content

Commit 30b1a43

Browse files
authored
Merge pull request #17 from proppy/bump
shiritori: update dependencies
2 parents df40267 + 4a0233f commit 30b1a43

12 files changed

+8967
-6747
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: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ const { actionssdk, SimpleResponse } = require('actions-on-google');
2323
const functions = require('firebase-functions');
2424
const shiritori = require('./shiritori');
2525
const admin = require('firebase-admin');
26-
admin.initializeApp(functions.config().firebase);
26+
admin.initializeApp();
2727

2828
const corpus = 'noun';
2929

30-
const dict = k => {
31-
return admin.database()
32-
.ref(corpus).child(k)
33-
.once('value')
34-
.then(snap => snap.val());
35-
};
30+
const dict = k => admin.database()
31+
.ref(corpus).child(k)
32+
.once('value')
33+
.then(snap => snap.val());
3634

3735
const app = actionssdk({
3836
// リクエストとレスポンスをロギングする。
@@ -45,35 +43,31 @@ const app = actionssdk({
4543
})
4644
});
4745

48-
app.intent('actions.intent.MAIN', (conv) => {
46+
app.intent('actions.intent.MAIN', conv => {
4947
conv.ask('どうぞ、始めて下さい');
5048
});
5149

52-
app.intent('actions.intent.TEXT', (conv, input) => {
53-
return shiritori.loaded.then(() => {
54-
return shiritori.interact(dict, input, conv.data.used)
55-
.then(result => {
56-
conv.data.used.unshift(input);
57-
conv.data.used.unshift(result.word);
58-
conv.ask(new SimpleResponse({
59-
speech: result.word,
60-
text: `${result.word} [${result.kana}]`
61-
}));
62-
})
63-
.catch(result => {
64-
if (result.win) {
65-
if (result.word) {
66-
conv.close(`${result.word} [${result.kana}]`);
67-
} else {
68-
conv.close('すごい!あなたの勝ちです。');
69-
}
70-
} else if (result.loose) {
71-
conv.close('ざんねん。あなたの負けです。');
72-
} else {
73-
throw result;
74-
}
75-
});
76-
});
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.LOSE_N:
62+
case shiritori.state.LOSE_USED:
63+
case shiritori.state.LOSE_CHAIN:
64+
conv.close('ざんねん。あなたの負けです。');
65+
break;
66+
case shiritori.state.WIN_N:
67+
case shiritori.state.WIN_USED:
68+
conv.close('すごい!あなたの勝ちです。');
69+
break;
70+
}
7771
});
7872

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

0 commit comments

Comments
 (0)