Skip to content

Commit

Permalink
fix(guess): stop updating a guess game's progress after that game has…
Browse files Browse the repository at this point in the history
… ended
  • Loading branch information
tuanddd committed Sep 8, 2023
1 parent 0301d34 commit de40608
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/commands/guess/new/slash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import {
getEmojiToken,
TokenEmojiKey,
} from "utils/common"
import { announceResult } from "../end/slash"
import { announceResult, cleanupAfterEndGame } from "../end/slash"
import { composeEmbedMessage } from "../../../ui/discord/embed"
import { truncate } from "lodash"
import moment, { now } from "moment-timezone"

function collectPlayerChoice(data: any, referee: User) {
return async function (i: ButtonInteraction) {
Expand Down Expand Up @@ -198,6 +199,12 @@ const slashCmd: SlashCommand = {
),
})
.catch(() => null)

// buffer 30s more to ensure all transactions are committed
if (now() >= moment(game.end_at).unix() * 1000 + 30 * 1000) {
clearInterval(timers.get(game.code))
return
}
}

const yesCode = data.options.find((opt: any) =>
Expand Down Expand Up @@ -289,7 +296,7 @@ const slashCmd: SlashCommand = {
)
}

// await cleanupAfterEndGame(thread, data.code)
await cleanupAfterEndGame(thread, data.code)
})
}, durationMs + 30 * 1000) // + more 30s to make sure all transactions are committed
)
Expand Down

0 comments on commit de40608

Please sign in to comment.