snapshot_poker_phase5

This commit is contained in:
DeSqBlocki
2026-09-08 21:49:43 +02:00
parent 6342c4569b
commit 1ef2295c07
9 changed files with 1462 additions and 18 deletions
+61
View File
@@ -6,6 +6,12 @@ const {
refreshPokerTableMessage refreshPokerTableMessage
} = require("../utils/pokerDiscord"); } = require("../utils/pokerDiscord");
const {
announcePokerHandProgress,
createPokerProfileContext,
recordPokerHandProfiles
} = require("../utils/pokerProfile");
const TURN_CHECK_INTERVAL = const TURN_CHECK_INTERVAL =
5 * 1000; 5 * 1000;
@@ -91,6 +97,39 @@ async function processPokerTurns(
client, client,
result result
); );
if (
result.game
?.data
?.hand
?.state ===
"PAYOUT"
) {
try {
await recordPokerHandProfiles(
result.game
);
const context =
await createPokerProfileContext(
client,
result.game
);
if (context) {
await announcePokerHandProgress(
context,
result.game
);
}
}
catch (error) {
console.error(
`[PokerProfile] Timeout profile processing failed for ${result.game.gameId}:`,
error
);
}
}
} }
} }
} }
@@ -169,6 +208,28 @@ async function recoverPoker(
client, client,
game game
); );
if (
game.data?.hand?.state ===
"PAYOUT"
) {
await recordPokerHandProfiles(
game
);
const context =
await createPokerProfileContext(
client,
game
);
if (context) {
await announcePokerHandProgress(
context,
game
);
}
}
} }
catch (error) { catch (error) {
console.error( console.error(
-4
View File
@@ -3,10 +3,6 @@
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": {
"test": "node --test",
"test:poker": "node --test tests/pokerEngine.test.js tests/crumbPoker.test.js"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://git.desq-gaming.de/admin_rb/ShaiBot.git" "url": "https://git.desq-gaming.de/admin_rb/ShaiBot.git"
+36 -12
View File
@@ -474,20 +474,41 @@ async function clearCookieOperation(
userId, userId,
operationId operationId
) { ) {
const cookies = if (
getCookieCollection(); typeof operationId !==
"string"
||
!/^[A-Za-z0-9:_-]{1,160}$/.test(
operationId
)
) {
throw new Error(
"INVALID_COOKIE_OPERATION_ID"
);
}
await cookies.updateOne( const {
{ cookies
userId } =
}, getCollections();
{
$pull: { const result =
appliedCookieOperations: await cookies.updateOne(
operationId {
userId
},
{
$pull: {
appliedCookieOperations:
operationId
}
} }
} );
);
/*
* Keep the Cookie document tidy once the final temporary
* idempotency marker has been cleared.
*/
await cookies.updateOne( await cookies.updateOne(
{ {
@@ -503,6 +524,9 @@ async function clearCookieOperation(
} }
} }
); );
return result.modifiedCount ===
1;
} }
+36
View File
@@ -8,6 +8,11 @@ const {
PokerEngineError PokerEngineError
} = require("./pokerEngine"); } = require("./pokerEngine");
const {
recordPokerActionProfile,
recordPokerHandProfiles
} = require("./pokerProfile");
/* /*
* ============================================================ * ============================================================
* CONFIG * CONFIG
@@ -1965,6 +1970,37 @@ function createPokerService({
); );
} }
/*
* Profile/stat history is secondary to the authoritative
* Poker state. A profile failure must never invalidate a
* successfully committed table action or payout.
*/
try {
await recordPokerActionProfile(
nextGame,
userId,
action
);
if (
nextGame.data.hand
?.state ===
"PAYOUT"
) {
await recordPokerHandProfiles(
nextGame
);
}
}
catch (error) {
console.error(
`[PokerProfile] Failed to persist profile history for ${nextGame.gameId}:`,
error
);
}
return clone(nextGame); return clone(nextGame);
} }
+2
View File
@@ -127,6 +127,8 @@ function formatPokerError(
return ( return (
known[error?.code] known[error?.code]
?? ??
known[error?.message]
??
error?.message error?.message
?? ??
"The Poker action could not be completed." "The Poker action could not be completed."
+30
View File
@@ -9,6 +9,10 @@ const {
refreshPokerTableMessage refreshPokerTableMessage
} = require("./pokerDiscord"); } = require("./pokerDiscord");
const {
announcePokerHandProgress
} = require("./pokerProfile");
async function executePokerAction( async function executePokerAction(
interaction, interaction,
@@ -50,6 +54,19 @@ async function executePokerAction(
game game
); );
try {
await announcePokerHandProgress(
interaction,
game
);
}
catch (error) {
console.error(
`[PokerProfile] Failed to announce completed hand ${game.gameId}:`,
error
);
}
return interaction.editReply({ return interaction.editReply({
content: content:
typeof successText === typeof successText ===
@@ -145,6 +162,19 @@ async function executeMinimumRaise(
game game
); );
try {
await announcePokerHandProgress(
interaction,
game
);
}
catch (error) {
console.error(
`[PokerProfile] Failed to announce completed hand ${game.gameId}:`,
error
);
}
return interaction.editReply({ return interaction.editReply({
content: content:
`✅ ${type === "bet" ? "Bet" : "Raised to"} ${legal.minRaiseTo.toLocaleString()} 🍪`, `✅ ${type === "bet" ? "Bet" : "Raised to"} ${legal.minRaiseTo.toLocaleString()} 🍪`,
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -754,7 +754,8 @@ async function auditProfileData(
"slots", "slots",
"blackjack", "blackjack",
"roulette", "roulette",
"heist" "heist",
"poker"
] ]
) { ) {
const value = const value =
+7 -1
View File
@@ -935,6 +935,9 @@ async function trackProfileEvent(
); );
break; break;
case "profile_refresh":
break;
default: default:
return; return;
} }
@@ -2041,7 +2044,8 @@ async function buildStatsEmbed(
["🎰 Slots", stats.games?.slots], ["🎰 Slots", stats.games?.slots],
["🃏 Blackjack", stats.games?.blackjack], ["🃏 Blackjack", stats.games?.blackjack],
["🎡 Roulette", stats.games?.roulette], ["🎡 Roulette", stats.games?.roulette],
["🏦 Heist", stats.games?.heist] ["🏦 Heist", stats.games?.heist],
["♠️ Poker", stats.games?.poker]
].map(([name, game = {}]) => { ].map(([name, game = {}]) => {
const played = const played =
Number(game.played ?? 0); Number(game.played ?? 0);
@@ -2923,6 +2927,8 @@ function formatCategoryName(
"🎡 Roulette", "🎡 Roulette",
heist: heist:
"🏦 Heist", "🏦 Heist",
poker:
"♠️ Poker",
collector: collector:
"🏆 Collector", "🏆 Collector",
other: other: