diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 549c115..e658fea 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -221,10 +221,16 @@ export default { await handleTwoPlayerMatchVoting(interaction, { participants: matchUsersArray, onComplete: async (interaction, winner) => { + console.log( + `Starting finish vote from vote from ${interaction.user.id} with winner ${winner}`, + ) try { const customSelId = interaction.values[0] const matchDataParts: string[] = customSelId.split('_') const matchId = parseInt(matchDataParts[1]) + console.log( + `Finishing vote for match ${matchId}, winner ${winner}`, + ) // Check if this match is Best of 3 or 5 const matchDataObj = await getMatchData(matchId) @@ -279,6 +285,10 @@ export default { winningTeam = 2 } + console.log( + `Winning team variable for match ${matchId}: ${winningTeam}`, + ) + if (winningTeam) { await setWinningTeam(matchId, winningTeam) await endMatch(matchId) diff --git a/src/utils/matchHelpers.ts b/src/utils/matchHelpers.ts index f05c541..5b61b88 100644 --- a/src/utils/matchHelpers.ts +++ b/src/utils/matchHelpers.ts @@ -566,43 +566,15 @@ export async function endMatch( matchId: number, cancelled = false, ): Promise { - try { - // close match in DB - await closeMatch(matchId) - - // get log file using glob library - // const pattern = path - // .join(__dirname, '..', 'logs', `match-${matchId}_*.log`) - // .replace(/\\/g, '/') - // const files = await glob(pattern) - // const file: string | null = files[0] ?? null + console.log(`Ending match ${matchId}, cancelled: ${cancelled}`) - // TODO: Re-add this and send it to the website - // if (file) { - // // format and send transcript - // const logContent = fs.readFileSync(file, 'utf8') - // const logLines = logContent - // .split('\n') - // .filter((line) => line.trim() !== '') - // const parsedLogLines = await parseLogLines(logLines) - // console.log(parsedLogLines) // json body - // - // // delete the log file after transcript is sent - // fs.unlinkSync(file) - // } - - // delete match channel + if (cancelled) { + console.log(`Match ${matchId} cancelled.`) const wasSuccessfullyDeleted = await deleteMatchChannel(matchId) if (!wasSuccessfullyDeleted) { console.log(`Channel id not found / failed to delete match ${matchId}`) } - - if (cancelled) return true - } catch (err) { - console.error( - `Error in file formatting or channel deletion for match ${matchId}:`, - err, - ) + return true } // build results button row @@ -628,8 +600,11 @@ export async function endMatch( } const queueId = await getQueueIdFromMatch(matchId) + console.log(`Queue ID for match ${matchId}: ${queueId}`) const queueSettings = await getQueueSettings(queueId, ['queue_name', 'color']) + console.log(`Queue settings for match ${matchId}:`, queueSettings) const matchData = await getMatchData(matchId) + console.log(`Match data for match ${matchId}:`, matchData) let teamResults: teamResults | null // create our teamResults object here @@ -643,9 +618,12 @@ export async function endMatch( teamResults = await calculateNewMMR(queueId, matchId, teamResultsData) + console.log(`match ${matchId} results: ${teamResults.teams}`) + // Save elo_change and winstreak to database const updatePromises = teamResults.teams.flatMap((team) => team.players.map(async (player) => { + console.log(`Team ${team} player ${player} in match ${matchId}`) // Update win streak await updatePlayerWinStreak(player.user_id, queueId, team.score == 1) @@ -661,6 +639,48 @@ export async function endMatch( await Promise.all(updatePromises) + console.log(`Updated elo_change and win_streak for match ${matchId}`) + + try { + // close match in DB + console.log(`Ending match ${matchId}, cancelled: ${cancelled}`) + await closeMatch(matchId) + + // get log file using glob library + // const pattern = path + // .join(__dirname, '..', 'logs', `match-${matchId}_*.log`) + // .replace(/\\/g, '/') + // const files = await glob(pattern) + // const file: string | null = files[0] ?? null + + // TODO: Re-add this and send it to the website + // if (file) { + // // format and send transcript + // const logContent = fs.readFileSync(file, 'utf8') + // const logLines = logContent + // .split('\n') + // .filter((line) => line.trim() !== '') + // const parsedLogLines = await parseLogLines(logLines) + // console.log(parsedLogLines) // json body + // + // // delete the log file after transcript is sent + // fs.unlinkSync(file) + // } + + // delete match channel + const wasSuccessfullyDeleted = await deleteMatchChannel(matchId) + if (!wasSuccessfullyDeleted) { + console.log(`Channel id not found / failed to delete match ${matchId}`) + } + + if (cancelled) return true + } catch (err) { + console.error( + `Error in file formatting or channel deletion for match ${matchId}:`, + err, + ) + } + // build results embed const resultsEmbed = new EmbedBuilder() .setTitle(`🏆 ${queueSettings.queue_name} Match #${matchId} 🏆`) @@ -771,6 +791,8 @@ export async function endMatch( return false } + console.log(`Sending results to ${resultsChannel.id} on match ${matchId}`) + await resultsChannel.send({ embeds: [resultsEmbed], components: [resultsButtonRow],