ユーザーが藍が対局情報を投稿するのを許可するか否か設定できるように

This commit is contained in:
syuilo 2018-08-04 20:37:26 +09:00
parent 1e30e89375
commit 7f21f1055b
2 changed files with 43 additions and 33 deletions

View file

@ -37,20 +37,22 @@ process.on('message', async msg => {
onGameStarted(msg.body); onGameStarted(msg.body);
//#region TLに投稿する //#region TLに投稿する
const game = msg.body; if (form.find(i => i.id == 'publish').value) {
const url = `${config.host}/reversi/${game.id}`; const game = msg.body;
const user = game.user1Id == config.id ? game.user2 : game.user1; const url = `${config.host}/reversi/${game.id}`;
const isSettai = form[0].value === 0; const user = game.user1Id == config.id ? game.user2 : game.user1;
const text = isSettai const isSettai = form[0].value === 0;
? `?[${getUserName(user)}](${config.host}/@${user.username})さんの接待を始めました!` const text = isSettai
: `対局を?[${getUserName(user)}](${config.host}/@${user.username})さんと始めました! (強さ${form[0].value})`; ? `?[${getUserName(user)}](${config.host}/@${user.username})さんの接待を始めました!`
: `対局を?[${getUserName(user)}](${config.host}/@${user.username})さんと始めました! (強さ${form[0].value})`;
const res = await request.post(`${config.host}/api/notes/create`, { const res = await request.post(`${config.host}/api/notes/create`, {
json: { json: {
i: config.i, i: config.i,
text: `${text}\n→[観戦する](${url})` text: `${text}\n→[観戦する](${url})`
} }
}); });
}
note = res.createdNote; note = res.createdNote;
//#endregion //#endregion
@ -64,28 +66,31 @@ process.on('message', async msg => {
}); });
//#region TLに投稿する //#region TLに投稿する
const user = game.user1Id == config.id ? game.user2 : game.user1; if (form.find(i => i.id == 'publish').value) {
const isSettai = form[0].value === 0; const user = game.user1Id == config.id ? game.user2 : game.user1;
const text = isSettai const isSettai = form[0].value === 0;
? msg.body.winnerId === null const text = isSettai
? `?[${getUserName(user)}](${config.host}/@${user.username})さんに接待で引き分けました...` ? msg.body.winnerId === null
: msg.body.winnerId == config.id ? `?[${getUserName(user)}](${config.host}/@${user.username})さんに接待で引き分けました...`
? `?[${getUserName(user)}](${config.host}/@${user.username})さんに接待で勝ってしまいました...` : msg.body.winnerId == config.id
: `?[${getUserName(user)}](${config.host}/@${user.username})さんに接待で負けてあげました♪` ? `?[${getUserName(user)}](${config.host}/@${user.username})さんに接待で勝ってしまいました...`
: msg.body.winnerId === null : `?[${getUserName(user)}](${config.host}/@${user.username})さんに接待で負けてあげました♪`
? `?[${getUserName(user)}](${config.host}/@${user.username})さんと引き分けました~` : msg.body.winnerId === null
: msg.body.winnerId == config.id ? `?[${getUserName(user)}](${config.host}/@${user.username})さんと引き分けました~`
? `?[${getUserName(user)}](${config.host}/@${user.username})さんに勝ちました♪` : msg.body.winnerId == config.id
: `?[${getUserName(user)}](${config.host}/@${user.username})さんに負けました...`; ? `?[${getUserName(user)}](${config.host}/@${user.username})さんに勝ちました♪`
: `?[${getUserName(user)}](${config.host}/@${user.username})さんに負けました...`;
await request.post(`${config.host}/api/notes/create`, { await request.post(`${config.host}/api/notes/create`, {
json: { json: {
i: config.i, i: config.i,
renoteId: note ? note.id : null, renoteId: note ? note.id : null,
text: text text: text
} }
}); });
}
//#endregion //#endregion
process.exit(); process.exit();
} }

View file

@ -132,6 +132,11 @@ function gameStart(game) {
// フォーム // フォーム
const form = [{ const form = [{
id: 'publish',
type: 'switch',
label: '藍が対局情報を投稿するのを許可',
value: true
}, {
id: 'strength', id: 'strength',
type: 'radio', type: 'radio',
label: '強さ', label: '強さ',