82 lines
2.0 KiB
JavaScript
82 lines
2.0 KiB
JavaScript
const {
|
|
getPokerService
|
|
} = require("../../utils/crumbPoker");
|
|
|
|
const {
|
|
deferPokerReply,
|
|
editPokerError,
|
|
publishPokerTable,
|
|
buildOpenTableLink
|
|
} = require("../../utils/pokerDiscord");
|
|
|
|
|
|
module.exports = {
|
|
name:
|
|
"pokerCreate",
|
|
|
|
async execute(
|
|
interaction
|
|
) {
|
|
await deferPokerReply(
|
|
interaction
|
|
);
|
|
|
|
const service =
|
|
getPokerService();
|
|
|
|
let game = null;
|
|
|
|
try {
|
|
game =
|
|
await service.createTable({
|
|
guildId:
|
|
interaction.guildId,
|
|
channelId:
|
|
interaction.channelId,
|
|
ownerId:
|
|
interaction.user.id
|
|
});
|
|
|
|
const published =
|
|
await publishPokerTable(
|
|
interaction,
|
|
game
|
|
);
|
|
|
|
return interaction.editReply({
|
|
content:
|
|
`✅ Poker table created. **${published.game.data.buyIn.toLocaleString()} Cookies** were moved into your Poker stack.`,
|
|
embeds: [],
|
|
components:
|
|
buildOpenTableLink(
|
|
published.game
|
|
)
|
|
});
|
|
}
|
|
|
|
catch (error) {
|
|
if (game) {
|
|
try {
|
|
await service.cashOut({
|
|
gameId:
|
|
game.gameId,
|
|
userId:
|
|
interaction.user.id
|
|
});
|
|
}
|
|
catch (refundError) {
|
|
console.error(
|
|
`[Poker] Failed to refund unpublished table ${game.gameId}:`,
|
|
refundError
|
|
);
|
|
}
|
|
}
|
|
|
|
return editPokerError(
|
|
interaction,
|
|
error
|
|
);
|
|
}
|
|
}
|
|
};
|