Provide non-obvious business rules and constraints for economy, inventory, quest, moderation, trade, and trivia modules to reduce context-gathering overhead for AI tools. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1.5 KiB
1.5 KiB
Trivia Module
- Trivia is an economic sink: the entry fee is deducted immediately when starting, before the question is fetched. If the API call fails after payment, the user loses the fee. This is by design (prevents free retries).
- Questions come from the OpenTDB API with base64 encoding to avoid HTML entity issues. The service decodes all fields from base64 before returning.
- Sessions are in-memory (
Mapkeyed byuserId_timestamp). Lost on restart. Expired sessions are cleaned up every 30 seconds. - The cooldown is set at session start, not on answer submission. This means a user is on cooldown even if they never answer.
- Answer correctness (
isCorrect) is determined by the caller (interaction handler), not the service. ThesubmitAnswermethod trusts theisCorrectboolean. The session storescorrectIndexfor the UI layer to compare. - Reward calculation:
potentialReward = entryFee * rewardMultiplier. The multiplier comes from config. Wrong answers get 0 (the entry fee is already gone). - Unlike most services,
TriviaServiceis a class instance (not a plain object). This is because it needs constructor logic for the cleanup interval. The singleton is exported astriviaService. - The reward payment in
submitAnswerreads the current balance and sets it directly (not usingsqladdition). This is a potential race condition under extreme concurrency but acceptable given the per-user cooldown. - Session is deleted before processing the reward to prevent double-submit, even if the reward transaction fails.