Skip to content

Commit

Permalink
Merge pull request #134 from moeyashi/feature/132
Browse files Browse the repository at this point in the history
feat: 見た目の改善 #132
  • Loading branch information
moeyashi authored May 25, 2024
2 parents 8e70401 + f39296a commit 3cb2f93
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/slash-command/rival.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { SlashCommandBuilder } from 'discord.js';
import { searchTrack } from '../const/track.js';
import { displayMilliseconds } from '../util/time.js';
import { BLUE, RED } from '../const/color.js';

/** @type { import('../types').SlashCommand } */
export default {
Expand Down Expand Up @@ -50,23 +51,29 @@ export default {
} else {
/** @type {import('discord.js').APIEmbed[]} */
const embeds = [];
res.embeds = tracks.reduce(
(pv, { trackCode, executorMilliseconds, rivalMilliseconds }, i) => {
const track = searchTrack(trackCode);
if (i % 25 === 0) {
pv.push({
fields: [],
});
}
const diffRival = executorMilliseconds - rivalMilliseconds;
pv[pv.length - 1].fields?.push({
name: track?.trackName || '',
value: `${displayMilliseconds(executorMilliseconds)} VS ${displayMilliseconds(rivalMilliseconds)} ${diffRival / 1000}秒`,
let createLose = false;
for (let i = 0; i < tracks.length; i++) {
const { trackCode, executorMilliseconds, rivalMilliseconds } = tracks[i];
const track = searchTrack(trackCode);
const win = executorMilliseconds < rivalMilliseconds;
// 25コースごと、または勝ちから負けに変わった場合に新しいembedを作成
if (i % 25 === 0 || (!win && !createLose)) {
embeds.push({
title: win ? '勝ち' : '負け',
fields: [],
color: win ? BLUE : RED,
});
return pv;
},
embeds,
);
if (!win) {
createLose = true;
}
}
const diffRival = executorMilliseconds - rivalMilliseconds;
embeds[embeds.length - 1].fields?.push({
name: track?.trackName || '',
value: `**${diffRival / 1000}秒** (${displayMilliseconds(executorMilliseconds)} VS ${displayMilliseconds(rivalMilliseconds)})`,
});
}
res.embeds = embeds;
}
await interaction.followUp(res);
},
Expand Down

0 comments on commit 3cb2f93

Please sign in to comment.