From 62abf32195dd1d354e2b546b14fddac5bd2cd778 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 16 Mar 2018 22:38:28 +0900 Subject: [PATCH] :v: --- src/common/othello/ai/back.ts | 25 ++++++++++++++----------- src/common/othello/ai/front.ts | 16 ++++++++-------- src/config.ts | 4 ++++ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/common/othello/ai/back.ts b/src/common/othello/ai/back.ts index c3a74a8348..047ecaf4e9 100644 --- a/src/common/othello/ai/back.ts +++ b/src/common/othello/ai/back.ts @@ -45,17 +45,19 @@ process.on('message', async msg => { //#region TLに投稿する const game = msg.body; - const url = `https://${conf.host}/othello/${game.id}`; + const url = `${conf.url}/othello/${game.id}`; const user = game.user1_id == id ? game.user2 : game.user1; const isSettai = form[0].value === 0; const text = isSettai - ? `?[${user.name}](https://${conf.host}/${user.username})さんの接待を始めました!` - : `対局を?[${user.name}](https://${conf.host}/${user.username})さんと始めました! (強さ${form[0].value})`; - const res = await request.post(`https://api.${conf.host}/posts/create`, { + ? `?[${user.name}](${conf.url}/${user.username})さんの接待を始めました!` + : `対局を?[${user.name}](${conf.url}/${user.username})さんと始めました! (強さ${form[0].value})`; + + const res = await request.post(`${conf.api_url}/posts/create`, { json: { i, text: `${text}\n→[観戦する](${url})` } }); + post = res.created_post; //#endregion } @@ -72,16 +74,17 @@ process.on('message', async msg => { const isSettai = form[0].value === 0; const text = isSettai ? msg.body.winner_id === null - ? `?[${user.name}](https://${conf.host}/${user.username})さんに接待で引き分けました...` + ? `?[${user.name}](${conf.url}/${user.username})さんに接待で引き分けました...` : msg.body.winner_id == id - ? `?[${user.name}](https://${conf.host}/${user.username})さんに接待で勝ってしまいました...` - : `?[${user.name}](https://${conf.host}/${user.username})さんに接待で負けてあげました♪` + ? `?[${user.name}](${conf.url}/${user.username})さんに接待で勝ってしまいました...` + : `?[${user.name}](${conf.url}/${user.username})さんに接待で負けてあげました♪` : msg.body.winner_id === null - ? `?[${user.name}](https://${conf.host}/${user.username})さんと引き分けました~ (強さ${form[0].value})` + ? `?[${user.name}](${conf.url}/${user.username})さんと引き分けました~ (強さ${form[0].value})` : msg.body.winner_id == id - ? `?[${user.name}](https://${conf.host}/${user.username})さんに勝ちました♪ (強さ${form[0].value})` - : `?[${user.name}](https://${conf.host}/${user.username})さんに負けました... (強さ${form[0].value})`; - request.post(`https://api.${conf.host}/posts/create`, { + ? `?[${user.name}](${conf.url}/${user.username})さんに勝ちました♪ (強さ${form[0].value})` + : `?[${user.name}](${conf.url}/${user.username})さんに負けました... (強さ${form[0].value})`; + + request.post(`${conf.api_url}/posts/create`, { json: { i, reply_id: post.id, text: text diff --git a/src/common/othello/ai/front.ts b/src/common/othello/ai/front.ts index 4d5f6e53eb..d892afbeda 100644 --- a/src/common/othello/ai/front.ts +++ b/src/common/othello/ai/front.ts @@ -29,7 +29,7 @@ const id = conf.othello_ai.id; /** * ホームストリーム */ -const homeStream = new ReconnectingWebSocket(`wss://api.${conf.host}/?i=${i}`, undefined, { +const homeStream = new ReconnectingWebSocket(`${conf.ws_url}/?i=${i}`, undefined, { constructor: WebSocket }); @@ -51,7 +51,7 @@ homeStream.on('message', message => { if (post.user_id == id) return; // リアクションする - request.post('https://api.misskey.xyz/posts/reactions/create', { + request.post(`${conf.api_url}/posts/reactions/create`, { json: { i, post_id: post.id, reaction: 'love' @@ -60,7 +60,7 @@ homeStream.on('message', message => { if (post.text) { if (post.text.indexOf('オセロ') > -1) { - request.post('https://api.misskey.xyz/posts/create', { + request.post(`${conf.api_url}/posts/create`, { json: { i, reply_id: post.id, text: '良いですよ~' @@ -77,7 +77,7 @@ homeStream.on('message', message => { const message = msg.body; if (message.text) { if (message.text.indexOf('オセロ') > -1) { - request.post(`https://api.${conf.host}/messaging/messages/create`, { + request.post(`${conf.api_url}/messaging/messages/create`, { json: { i, user_id: message.user_id, text: '良いですよ~' @@ -92,7 +92,7 @@ homeStream.on('message', message => { // ユーザーを対局に誘う function invite(userId) { - request.post(`https://api.${conf.host}/othello/match`, { + request.post(`${conf.api_url}/othello/match`, { json: { i, user_id: userId } @@ -102,7 +102,7 @@ function invite(userId) { /** * オセロストリーム */ -const othelloStream = new ReconnectingWebSocket(`wss://api.${conf.host}/othello?i=${i}`, undefined, { +const othelloStream = new ReconnectingWebSocket(`${conf.ws_url}/othello?i=${i}`, undefined, { constructor: WebSocket }); @@ -134,7 +134,7 @@ othelloStream.on('message', message => { */ function gameStart(game) { // ゲームストリームに接続 - const gw = new ReconnectingWebSocket(`wss://api.${conf.host}/othello-game?i=${i}&game=${game.id}`, undefined, { + const gw = new ReconnectingWebSocket(`${conf.ws_url}/othello-game?i=${i}&game=${game.id}`, undefined, { constructor: WebSocket }); @@ -222,7 +222,7 @@ async function onInviteMe(inviter) { console.log(`Someone invited me: @${inviter.username}`); // 承認 - const game = await request.post(`https://api.${conf.host}/othello/match`, { + const game = await request.post(`${conf.api_url}/othello/match`, { json: { i, user_id: inviter.id diff --git a/src/config.ts b/src/config.ts index 82488cef8e..09e06f3311 100644 --- a/src/config.ts +++ b/src/config.ts @@ -103,9 +103,11 @@ type Source = { type Mixin = { host: string; scheme: string; + ws_scheme: string; secondary_host: string; secondary_scheme: string; api_url: string; + ws_url: string; auth_url: string; docs_url: string; ch_url: string; @@ -131,6 +133,8 @@ export default function load() { mixin.host = config.url.substr(config.url.indexOf('://') + 3); mixin.scheme = config.url.substr(0, config.url.indexOf('://')); + mixin.ws_scheme = mixin.scheme.replace('http', 'ws'); + mixin.ws_url = `${mixin.ws_scheme}://api.${mixin.host}`; mixin.secondary_host = config.secondary_url.substr(config.secondary_url.indexOf('://') + 3); mixin.secondary_scheme = config.secondary_url.substr(0, config.secondary_url.indexOf('://')); mixin.api_url = `${mixin.scheme}://api.${mixin.host}`;