Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,15 @@ export default {
matchId: number,
log: boolean = false,
) {
// Prevent concurrent cancellation (same guard used by win path)
if (processingMatchEnds.has(matchId)) {
console.log(
`Match ${matchId} cancel already being processed, skipping`,
)
return
}
processingMatchEnds.add(matchId)

let usedDeferredReply = false
let usedMessageUpdate = false

Expand Down Expand Up @@ -1188,6 +1197,8 @@ export default {
}
} catch (err) {
console.error('Error in finishing match:', err)
} finally {
processingMatchEnds.delete(matchId)
}
}

Expand All @@ -1197,13 +1208,16 @@ export default {
(member.roles.cache.has(botSettings.helper_role_id) ||
member.roles.cache.has(botSettings.queue_helper_role_id)) &&
!matchUsersArray.includes(interaction.user.id)
)
) {
await cancel(interaction, matchId)
return
}
}

// Check if log channel is the channel
if (interaction.channel!.id == botSettings.queue_logs_channel_id) {
await cancel(interaction, matchId, true)
return
}

// Otherwise do normal vote
Expand Down
10 changes: 10 additions & 0 deletions src/utils/matchHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,16 @@ export async function endMatch(
cancelled = false,
): Promise<EndMatchResult> {
const matchCheck = await getMatchStatus(matchId)
if (!matchCheck && cancelled) {
console.log(
`Match ${matchId} already closed, skipping cancellation to prevent double MMR revert`,
)
return {
success: true,
cancelled: true,
revertedMmrChanges: [],
}
}
if (!matchCheck) {
console.log(`match ${matchId} already closed, running change winner logic`)
}
Expand Down