From f40e778993079fe0e5bac43c356d6a0dd0365b8c Mon Sep 17 00:00:00 2001 From: David Houweling Date: Tue, 22 Oct 2024 22:36:52 +1100 Subject: [PATCH] thread match stats into series message --- src/commands/stats/stats.mts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/commands/stats/stats.mts b/src/commands/stats/stats.mts index 68211ec..e1eae6c 100644 --- a/src/commands/stats/stats.mts +++ b/src/commands/stats/stats.mts @@ -119,24 +119,22 @@ export class StatsCommand extends BaseCommand { const series = await this.services.haloService.getSeriesFromDiscordQueue(queueData); const seriesEmbed = await this.createSeriesEmbed(queueData, queueValue, series); - await interaction.editReply({ + const message = await interaction.editReply({ embeds: [seriesEmbed], }); - /* Based on https://discordjs.guide/popular-topics/threads.html#thread-related-gateway-events - * But threads is not available for channel here. Needs further investigation - await Promise.all(series.map(async (match, index) => { - const thread = await channel.threads.create({ - name: `Match ${index + 1} - Queue ${queueValue}`, - autoArchiveDuration: 60, - startMessage: mainMessage.id, - }); + const thread = await message.startThread({ + name: `In depth match stats for queue #${queueValue.toString()}`, + autoArchiveDuration: 60, + }); - const matchEmbed = await this.createMatchEmbed(match); + for (const match of series) { + const players = await this.services.haloService.getPlayerXuidsToGametags(match); + const matchEmbed = this.getMatchEmbed(match); + const embed = await matchEmbed.getEmbed(match, players); - await thread.send({ embeds: [matchEmbed] }); - })); - */ + await thread.send({ embeds: [embed] }); + } } catch (error) { const reply = { content: `Failed to fetch (Channel: <#${channel.channel?.id ?? "unknown"}>, queue: ${queue.value?.toString() ?? "unknown"}): ${error instanceof Error ? error.message : "unknown"}`,