Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed blackjack errors deducting coins #537

Merged
merged 2 commits into from
Oct 5, 2024
Merged
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
25 changes: 17 additions & 8 deletions src/commandDetails/games/blackjack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,26 @@ const blackjackExecuteCommand: SapphireMessageExecuteType = async (
// Return next game state
await msg.edit({ embeds: [getEmbedFromGame(game!)] });
await reactCollector.update({ components: [optionRow] });
} catch {
// If player has not acted within time limit, consider it as quitting the game
game = performGameAction(author, BlackjackAction.QUIT);
msg.edit(
"You didn't act within the time limit. Unfortunately, this counts as a quit. Please start another game!",
);
if (game) {
game.stage = BlackjackStage.DONE;
} catch (error) {
if (error instanceof Error && error.message.includes('time')) {
// If player has not acted within time limit, consider it as quitting the game
game = performGameAction(author, BlackjackAction.QUIT);
await msg.edit(
"You didn't act within the time limit. Unfortunately, this counts as a quit. Please start another game!",
);
if (game) {
game.stage = BlackjackStage.DONE;
}
} else {
// Handling Unexpected Errors
await msg.edit('An unexpected error occured. The game has been aborted.');

closeGame(author, 0); // No change to balance
return 'An unexpected error occured. The game has been aborted.';
}
}
}

if (game) {
// Update game embed
await msg.edit({ embeds: [getEmbedFromGame(game)], components: [] });
Expand Down
Loading