@@ -37,7 +37,7 @@ import {
3737 getQueueSettings ,
3838 getStake ,
3939 getStakeByName ,
40- getUserPriorityQueueId ,
40+ // getUserPriorityQueueId,
4141 getUserQueues ,
4242 setMatchStakeVoteTeam ,
4343 setPickedMatchStake ,
@@ -194,73 +194,80 @@ export default {
194194 }
195195 }
196196
197- await handleTwoPlayerMatchVoting ( interaction , {
198- participants : matchUsersArray ,
199- onComplete : async ( interaction , winner ) => {
200- const customSelId = interaction . values [ 0 ]
201- const matchDataParts : string [ ] = customSelId . split ( '_' )
202- const matchId = parseInt ( matchDataParts [ 1 ] )
203-
204- // Check if this match is Best of 3 or 5
205- const matchDataObj = await getMatchData ( matchId )
206- const isBo3 = matchDataObj . best_of_3
207- const isBo5 = matchDataObj . best_of_5
208-
209- if ( ! isBo3 && ! isBo5 ) {
210- await setWinningTeam ( matchId , winner )
211- await endMatch ( matchId )
212- return
213- }
214-
215- const embed = interaction . message . embeds [ 0 ]
216- const fields = embed . data . fields || [ ]
197+ try {
198+ await handleTwoPlayerMatchVoting ( interaction , {
199+ participants : matchUsersArray ,
200+ onComplete : async ( interaction , winner ) => {
201+ const customSelId = interaction . values [ 0 ]
202+ const matchDataParts : string [ ] = customSelId . split ( '_' )
203+ const matchId = parseInt ( matchDataParts [ 1 ] )
204+
205+ // Check if this match is Best of 3 or 5
206+ const matchDataObj = await getMatchData ( matchId )
207+ const isBo3 = matchDataObj . best_of_3
208+ const isBo5 = matchDataObj . best_of_5
209+
210+ if ( ! isBo3 && ! isBo5 ) {
211+ await setWinningTeam ( matchId , winner )
212+ await endMatch ( matchId )
213+ return
214+ } else {
215+ const embed = interaction . message . embeds [ 0 ]
216+ const fields = embed . data . fields || [ ]
217217
218- // Update Best of scores and check for match winner
219- const winnerIndex = winner === 1 ? 0 : 1
220- for ( let i = 0 ; i < Math . min ( 2 , fields . length ) ; i ++ ) {
221- const val = fields [ i ] . value || ''
222- const lines = val . split ( '\n' )
218+ // Update Best of scores in the embed ( for display only)
219+ const winnerIndex = winner === 1 ? 0 : 1
220+ for ( let i = 0 ; i < Math . min ( 2 , fields . length ) ; i ++ ) {
221+ const val = fields [ i ] . value || ''
222+ const lines = val . split ( '\n' )
223223
224- const cleaned = lines . filter (
225- ( l ) => ! l . includes ( 'Win Votes' ) && ! l . includes ( '<@' ) ,
226- )
224+ const cleaned = lines . filter (
225+ ( l ) => ! l . includes ( 'Win Votes' ) && ! l . includes ( '<@' ) ,
226+ )
227227
228- const mmrIdx = cleaned . findIndex ( ( l ) => l . includes ( 'MMR' ) )
229- if ( mmrIdx !== - 1 ) {
230- const mmrLine = cleaned [ mmrIdx ]
231- const m = mmrLine . match ( / S c o r e : \s * ( \d + ) / i)
232- let score = m ? parseInt ( m [ 1 ] , 10 ) || 0 : 0
228+ const mmrIdx = cleaned . findIndex ( ( l ) => l . includes ( 'MMR' ) )
229+ if ( mmrIdx !== - 1 ) {
230+ const mmrLine = cleaned [ mmrIdx ]
231+ const m = mmrLine . match ( / S c o r e : \s * ( \d + ) / i)
232+ let score = m ? parseInt ( m [ 1 ] , 10 ) || 0 : 0
233233
234- if ( i === winnerIndex ) score += 1
234+ if ( i === winnerIndex ) score += 1
235235
236- cleaned [ mmrIdx ] =
237- mmrLine . replace ( / \s * - ? \s * S c o r e : \s * \d + / i, '' ) . trimEnd ( ) +
238- ` - Score: ${ score } `
239- }
236+ cleaned [ mmrIdx ] =
237+ mmrLine . replace ( / \s * - ? \s * S c o r e : \s * \d + / i, '' ) . trimEnd ( ) +
238+ ` - Score: ${ score } `
239+ }
240240
241- fields [ i ] . value = cleaned . join ( '\n' )
242- }
243-
244- const scores = getBestOfMatchScores ( fields )
245- const requiredWins = isBo5 ? 3 : isBo3 ? 2 : 1
246- const [ team1Wins , team2Wins ] = scores
241+ fields [ i ] . value = cleaned . join ( '\n' )
242+ }
247243
248- let winningTeam = 0
249- if ( team1Wins >= requiredWins ) {
250- winningTeam = 1
251- } else if ( team2Wins >= requiredWins ) {
252- winningTeam = 2
253- }
244+ // Get updated scores from the embed (after incrementing)
245+ let scores = getBestOfMatchScores ( fields )
246+ let requiredWins = isBo5 ? 3 : isBo3 ? 2 : 1
247+ const [ team1Wins , team2Wins ] = scores
248+
249+ // Check if a team has won the Best of series
250+ let winningTeam = 0
251+ if ( team1Wins >= requiredWins ) {
252+ winningTeam = 1
253+ } else if ( team2Wins >= requiredWins ) {
254+ winningTeam = 2
255+ }
254256
255- if ( winningTeam ) {
256- await endMatch ( matchId )
257- return
258- }
257+ if ( winningTeam ) {
258+ await setWinningTeam ( matchId , winningTeam )
259+ await endMatch ( matchId )
260+ return
261+ }
259262
260- interaction . message . embeds [ 0 ] = embed
261- await interaction . update ( { embeds : interaction . message . embeds } )
262- } ,
263- } )
263+ interaction . message . embeds [ 0 ] = embed
264+ await interaction . update ( { embeds : interaction . message . embeds } )
265+ }
266+ } ,
267+ } )
268+ } catch ( err ) {
269+ console . error ( err )
270+ }
264271 }
265272
266273 if ( interaction . customId . startsWith ( 'deck-bans-' ) ) {
@@ -434,9 +441,9 @@ export default {
434441
435442 if ( interaction . customId === 'check-queued' ) {
436443 const userQueueList = await getUserQueues ( interaction . user . id )
437- const priorityQueueId = await getUserPriorityQueueId (
438- interaction . user . id ,
439- )
444+ // const priorityQueueId = await getUserPriorityQueueId(
445+ // interaction.user.id,
446+ // )
440447
441448 if ( userQueueList . length > 0 ) {
442449 const timeSpent = await timeSpentInQueue (
@@ -447,7 +454,7 @@ export default {
447454 content :
448455 `
449456 You are in queue for **${ userQueueList . map ( ( queue ) => `${ queue . queue_name } ` ) . join ( ', ' ) } **!` +
450- `${ priorityQueueId ? `\nYour priority queue is **${ ( await getQueueSettings ( priorityQueueId , [ 'queue_name' ] ) ) . queue_name } **!` : `` } ` +
457+ // `${priorityQueueId ? `\nYour priority queue is **${(await getQueueSettings(priorityQueueId, ['queue_name'])).queue_name}**!` : `` }` +
451458 `\nJoined queue ${ timeSpent } .` ,
452459 flags : MessageFlags . Ephemeral ,
453460 } )
@@ -542,6 +549,7 @@ export default {
542549 voteType : 'Cancel Match Votes' ,
543550 embedFieldIndex : 2 ,
544551 participants : matchUsersArray ,
552+ matchId : matchId ,
545553 onComplete : async ( interaction ) => {
546554 await cancel ( interaction , matchId )
547555 } ,
@@ -724,6 +732,8 @@ export default {
724732 voteType : 'Rematch Votes' ,
725733 embedFieldIndex : 2 ,
726734 participants : matchUsersArray ,
735+ matchId : matchId ,
736+ resendMessage : false ,
727737 onComplete : async ( interaction , { embed } ) => {
728738 await interaction . update ( {
729739 content : 'A Rematch for this matchup has begun!' ,
@@ -796,6 +806,7 @@ export default {
796806 voteType : voteFieldName ,
797807 embedFieldIndex : 3 ,
798808 participants : matchUsersArray ,
809+ matchId : matchId ,
799810 onComplete : async ( interaction , { embed } ) => {
800811 const rows = interaction . message . components . map ( ( row ) =>
801812 ActionRowBuilder . from ( row as any ) ,
0 commit comments