Skip to content

shiritori: update dependencies #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion functions/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parserOptions": {
"ecmaVersion": 7,
"ecmaVersion": 8,
"sourceType": "module"
},
"extends": ["semistandard"],
Expand Down
60 changes: 27 additions & 33 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ const { actionssdk, SimpleResponse } = require('actions-on-google');
const functions = require('firebase-functions');
const shiritori = require('./shiritori');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
admin.initializeApp();

const corpus = 'noun';

const dict = k => {
return admin.database()
.ref(corpus).child(k)
.once('value')
.then(snap => snap.val());
};
const dict = k => admin.database()
.ref(corpus).child(k)
.once('value')
.then(snap => snap.val());

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

app.intent('actions.intent.MAIN', (conv) => {
app.intent('actions.intent.MAIN', conv => {
conv.ask('どうぞ、始めて下さい');
});

app.intent('actions.intent.TEXT', (conv, input) => {
return shiritori.loaded.then(() => {
return shiritori.interact(dict, input, conv.data.used)
.then(result => {
conv.data.used.unshift(input);
conv.data.used.unshift(result.word);
conv.ask(new SimpleResponse({
speech: result.word,
text: `${result.word} [${result.kana}]`
}));
})
.catch(result => {
if (result.win) {
if (result.word) {
conv.close(`${result.word} [${result.kana}]`);
} else {
conv.close('すごい!あなたの勝ちです。');
}
} else if (result.loose) {
conv.close('ざんねん。あなたの負けです。');
} else {
throw result;
}
});
});
app.intent('actions.intent.TEXT', async (conv, input) => {
const result = await shiritori.interact(dict, input, conv.data.used);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't seem to catch the Error anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the previous code was doing nothing but re-throwing it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you at least catch the error here and state an error message? Otherwise the function will crash and so will your action.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, actually removed the error handling, since it wasn't valid, see ce5269c commit message for more details.

switch (result.state) {
case shiritori.state.CONTINUE:
conv.data.used.unshift(input);
conv.data.used.unshift(result.word);
conv.ask(new SimpleResponse({
speech: result.word,
text: `${result.word} [${result.kana}]`
}));
break;
case shiritori.state.LOSE_N:
case shiritori.state.LOSE_USED:
case shiritori.state.LOSE_CHAIN:
conv.close('ざんねん。あなたの負けです。');
break;
case shiritori.state.WIN_N:
case shiritori.state.WIN_USED:
conv.close('すごい!あなたの勝ちです。');
break;
}
});

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