From 0c7d0efa3030e5b930a6d506c8bf77831cbfe2f2 Mon Sep 17 00:00:00 2001 From: Cma Date: Fri, 20 Dec 2024 21:09:54 +0900 Subject: [PATCH] fix: template --- app/routes/_index/templates.tsx | 48 ++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/app/routes/_index/templates.tsx b/app/routes/_index/templates.tsx index e8f602a..a641c46 100644 --- a/app/routes/_index/templates.tsx +++ b/app/routes/_index/templates.tsx @@ -11,13 +11,27 @@ interface Template { apply: (run: Run) => string; } -const presentRunners = (runners: Run["runner"]) => { +const twitter = (twitterId: string | undefined) => + twitterId ? `(@${twitterId})` : ""; + +const presentParticipants = ( + participants: Run["runner"] | Run["commentary"] +) => { + return participants + .map((p) => { + const name = p.username.replaceAll("@", "@ "); + return `${name}さん${twitter(p.twitterid)}`; + }) + .join("、"); +}; + +const presentRunnerTimes = (runners: Run["runner"]) => { return runners .map((runner) => { const name = runner.username.replaceAll("@", "@ "); - return `${name}さん(@${runner.twitterid})`; + return `${name}${twitter(runner.twitterid)} xx:xx:xx`; }) - .join("、"); + .join("\n"); }; export const templates: Template[] = [ @@ -26,32 +40,40 @@ export const templates: Template[] = [ apply: (run) => `次のタイムアタックは『${run.gamename}』\nカテゴリーは「${ run.category - }」\n走者は${presentRunners( - run.runner - )}です。\n\n配信はこちらから⇒https://www.twitch.tv/rtainjapan\n#RTAinJapan`, + }」\n走者は${presentParticipants(run.runner)}です。\n${ + run.commentary.length > 0 + ? `解説は${presentParticipants(run.commentary)}です。` + : "" + }\n\n配信はこちらから⇒https://www.twitch.tv/rtainjapan\n#RTAinJapan`, }, { label: "finishWithTime", apply: (run) => `『${run.gamename}』のカテゴリー「${ run.category - }」RTA\n走者の${presentRunners( - run.runner - )}お疲れさまでした。\nクリアタイムはxx:xx:xxでした。\n\n配信はこちらから⇒https://www.twitch.tv/rtainjapan\n#RTAinJapan`, + }」RTA\n走者の${presentParticipants(run.runner)}${ + run.commentary.length > 0 + ? `、解説の${presentParticipants(run.commentary)}` + : "" + }お疲れさまでした。\nクリアタイムはxx:xx:xxでした。\n\n配信はこちらから⇒https://www.twitch.tv/rtainjapan\n#RTAinJapan`, }, { label: "finishWithoutTime", apply: (run) => `『${run.gamename}』のカテゴリー「${ run.category - }」RTA\n走者の${presentRunners( - run.runner - )}お疲れさまでした。\n\n配信はこちらから⇒https://www.twitch.tv/rtainjapan\n#RTAinJapan`, + }」RTA\n走者の${presentParticipants(run.runner)}${ + run.commentary.length > 0 + ? `、解説の${presentParticipants(run.commentary)}` + : "" + }お疲れさまでした。\n\n配信はこちらから⇒https://www.twitch.tv/rtainjapan\n#RTAinJapan`, }, { label: "finishOnlyTime", apply: (run) => - `『${run.gamename}』\nクリアタイムは次の通りです\n\n\n配信はこちらから⇒https://www.twitch.tv/rtainjapan\n#RTAinJapan`, + `『${run.gamename}』\nクリアタイムは次の通りです\n\n${presentRunnerTimes( + run.runner + )}\n\n配信はこちらから⇒https://www.twitch.tv/rtainjapan\n#RTAinJapan`, }, { label: "running",