152 lines
3.7 KiB
JavaScript
152 lines
3.7 KiB
JavaScript
const {
|
|
cardToString
|
|
} = require("../../utils/pokerEngine");
|
|
|
|
const {
|
|
getPokerService
|
|
} = require("../../utils/crumbPoker");
|
|
|
|
const {
|
|
POKER_CARD_RESPONSE_LIFETIME,
|
|
deferPokerReply,
|
|
editPokerError,
|
|
getPokerGameIdFromInteraction
|
|
} = require("../../utils/pokerDiscord");
|
|
|
|
|
|
module.exports = {
|
|
name:
|
|
"pokerCards",
|
|
|
|
async execute(
|
|
interaction
|
|
) {
|
|
await deferPokerReply(
|
|
interaction
|
|
);
|
|
|
|
const gameId =
|
|
getPokerGameIdFromInteraction(
|
|
interaction
|
|
);
|
|
|
|
if (!gameId) {
|
|
return interaction.editReply({
|
|
content:
|
|
"❌ This Poker table is no longer active.",
|
|
embeds: [],
|
|
components: []
|
|
});
|
|
}
|
|
|
|
try {
|
|
const service =
|
|
getPokerService();
|
|
|
|
const [
|
|
cards,
|
|
game
|
|
] =
|
|
await Promise.all([
|
|
service.viewCards({
|
|
gameId,
|
|
userId:
|
|
interaction.user.id
|
|
}),
|
|
service.getTable({
|
|
gameId
|
|
})
|
|
]);
|
|
|
|
const hand =
|
|
game.data.hand;
|
|
|
|
const player =
|
|
game.data.players.find(
|
|
candidate =>
|
|
String(candidate.userId) ===
|
|
String(interaction.user.id)
|
|
);
|
|
|
|
const currentPlayer =
|
|
hand?.players?.find(
|
|
candidate =>
|
|
candidate.seat ===
|
|
hand.currentSeat
|
|
);
|
|
|
|
const isYourTurn =
|
|
Boolean(
|
|
player
|
|
&&
|
|
hand
|
|
&&
|
|
hand.currentSeat ===
|
|
player.seat
|
|
);
|
|
|
|
const communityCards =
|
|
hand?.communityCards ?? [];
|
|
|
|
const lines = [
|
|
"### 🃏 Your Cards",
|
|
`**${cards.map(cardToString).join(" ")}**`,
|
|
"",
|
|
"**Community:** " +
|
|
(communityCards.length
|
|
? communityCards
|
|
.map(cardToString)
|
|
.join(" ")
|
|
: "No community cards yet."),
|
|
""
|
|
];
|
|
|
|
if (isYourTurn) {
|
|
lines.push(
|
|
"👉 **It's YOUR TURN.**",
|
|
game.data.turnExpiresAt
|
|
? `⏱️ Auto-folds <t:${game.data.turnExpiresAt}:R>.`
|
|
: "⏱️ Your turn timer is active."
|
|
);
|
|
}
|
|
|
|
else if (currentPlayer) {
|
|
lines.push(
|
|
`Waiting for <@${currentPlayer.userId}> to act.`
|
|
);
|
|
}
|
|
|
|
else {
|
|
lines.push(
|
|
"The hand is not currently waiting on a player action."
|
|
);
|
|
}
|
|
|
|
await interaction.editReply({
|
|
content:
|
|
lines.join("\n"),
|
|
embeds: [],
|
|
components: []
|
|
});
|
|
|
|
setTimeout(
|
|
() => {
|
|
interaction
|
|
.deleteReply()
|
|
.catch(() => {});
|
|
},
|
|
POKER_CARD_RESPONSE_LIFETIME
|
|
);
|
|
|
|
return;
|
|
}
|
|
|
|
catch (error) {
|
|
return editPokerError(
|
|
interaction,
|
|
error
|
|
);
|
|
}
|
|
}
|
|
};
|