Skip to content

Commit 2a93f10

Browse files
authored
Merge pull request #53 from Balatro-Multiplayer/mmr-fix
Potential fix for LOSS 0.0 MMR
2 parents 12d2ff0 + 61f4639 commit 2a93f10

File tree

2 files changed

+64
-32
lines changed

2 files changed

+64
-32
lines changed

src/events/interactionCreate.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,16 @@ export default {
221221
await handleTwoPlayerMatchVoting(interaction, {
222222
participants: matchUsersArray,
223223
onComplete: async (interaction, winner) => {
224+
console.log(
225+
`Starting finish vote from vote from ${interaction.user.id} with winner ${winner}`,
226+
)
224227
try {
225228
const customSelId = interaction.values[0]
226229
const matchDataParts: string[] = customSelId.split('_')
227230
const matchId = parseInt(matchDataParts[1])
231+
console.log(
232+
`Finishing vote for match ${matchId}, winner ${winner}`,
233+
)
228234

229235
// Check if this match is Best of 3 or 5
230236
const matchDataObj = await getMatchData(matchId)
@@ -279,6 +285,10 @@ export default {
279285
winningTeam = 2
280286
}
281287

288+
console.log(
289+
`Winning team variable for match ${matchId}: ${winningTeam}`,
290+
)
291+
282292
if (winningTeam) {
283293
await setWinningTeam(matchId, winningTeam)
284294
await endMatch(matchId)

src/utils/matchHelpers.ts

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -566,43 +566,15 @@ export async function endMatch(
566566
matchId: number,
567567
cancelled = false,
568568
): Promise<boolean> {
569-
try {
570-
// close match in DB
571-
await closeMatch(matchId)
572-
573-
// get log file using glob library
574-
// const pattern = path
575-
// .join(__dirname, '..', 'logs', `match-${matchId}_*.log`)
576-
// .replace(/\\/g, '/')
577-
// const files = await glob(pattern)
578-
// const file: string | null = files[0] ?? null
569+
console.log(`Ending match ${matchId}, cancelled: ${cancelled}`)
579570

580-
// TODO: Re-add this and send it to the website
581-
// if (file) {
582-
// // format and send transcript
583-
// const logContent = fs.readFileSync(file, 'utf8')
584-
// const logLines = logContent
585-
// .split('\n')
586-
// .filter((line) => line.trim() !== '')
587-
// const parsedLogLines = await parseLogLines(logLines)
588-
// console.log(parsedLogLines) // json body
589-
//
590-
// // delete the log file after transcript is sent
591-
// fs.unlinkSync(file)
592-
// }
593-
594-
// delete match channel
571+
if (cancelled) {
572+
console.log(`Match ${matchId} cancelled.`)
595573
const wasSuccessfullyDeleted = await deleteMatchChannel(matchId)
596574
if (!wasSuccessfullyDeleted) {
597575
console.log(`Channel id not found / failed to delete match ${matchId}`)
598576
}
599-
600-
if (cancelled) return true
601-
} catch (err) {
602-
console.error(
603-
`Error in file formatting or channel deletion for match ${matchId}:`,
604-
err,
605-
)
577+
return true
606578
}
607579

608580
// build results button row
@@ -628,8 +600,11 @@ export async function endMatch(
628600
}
629601

630602
const queueId = await getQueueIdFromMatch(matchId)
603+
console.log(`Queue ID for match ${matchId}: ${queueId}`)
631604
const queueSettings = await getQueueSettings(queueId, ['queue_name', 'color'])
605+
console.log(`Queue settings for match ${matchId}:`, queueSettings)
632606
const matchData = await getMatchData(matchId)
607+
console.log(`Match data for match ${matchId}:`, matchData)
633608

634609
let teamResults: teamResults | null
635610
// create our teamResults object here
@@ -643,9 +618,12 @@ export async function endMatch(
643618

644619
teamResults = await calculateNewMMR(queueId, matchId, teamResultsData)
645620

621+
console.log(`match ${matchId} results: ${teamResults.teams}`)
622+
646623
// Save elo_change and winstreak to database
647624
const updatePromises = teamResults.teams.flatMap((team) =>
648625
team.players.map(async (player) => {
626+
console.log(`Team ${team} player ${player} in match ${matchId}`)
649627
// Update win streak
650628
await updatePlayerWinStreak(player.user_id, queueId, team.score == 1)
651629

@@ -661,6 +639,48 @@ export async function endMatch(
661639

662640
await Promise.all(updatePromises)
663641

642+
console.log(`Updated elo_change and win_streak for match ${matchId}`)
643+
644+
try {
645+
// close match in DB
646+
console.log(`Ending match ${matchId}, cancelled: ${cancelled}`)
647+
await closeMatch(matchId)
648+
649+
// get log file using glob library
650+
// const pattern = path
651+
// .join(__dirname, '..', 'logs', `match-${matchId}_*.log`)
652+
// .replace(/\\/g, '/')
653+
// const files = await glob(pattern)
654+
// const file: string | null = files[0] ?? null
655+
656+
// TODO: Re-add this and send it to the website
657+
// if (file) {
658+
// // format and send transcript
659+
// const logContent = fs.readFileSync(file, 'utf8')
660+
// const logLines = logContent
661+
// .split('\n')
662+
// .filter((line) => line.trim() !== '')
663+
// const parsedLogLines = await parseLogLines(logLines)
664+
// console.log(parsedLogLines) // json body
665+
//
666+
// // delete the log file after transcript is sent
667+
// fs.unlinkSync(file)
668+
// }
669+
670+
// delete match channel
671+
const wasSuccessfullyDeleted = await deleteMatchChannel(matchId)
672+
if (!wasSuccessfullyDeleted) {
673+
console.log(`Channel id not found / failed to delete match ${matchId}`)
674+
}
675+
676+
if (cancelled) return true
677+
} catch (err) {
678+
console.error(
679+
`Error in file formatting or channel deletion for match ${matchId}:`,
680+
err,
681+
)
682+
}
683+
664684
// build results embed
665685
const resultsEmbed = new EmbedBuilder()
666686
.setTitle(`🏆 ${queueSettings.queue_name} Match #${matchId} 🏆`)
@@ -771,6 +791,8 @@ export async function endMatch(
771791
return false
772792
}
773793

794+
console.log(`Sending results to ${resultsChannel.id} on match ${matchId}`)
795+
774796
await resultsChannel.send({
775797
embeds: [resultsEmbed],
776798
components: [resultsButtonRow],

0 commit comments

Comments
 (0)