import { determinePrivacyFromRollMode } from "../utils/privacy.mjs"; Hooks.on(`preCreateChatMessage`, (_message, context, options, author) => { const isNew = options.action === `create`; const hasRolls = context.rolls?.length > 0; if (!isNew || !hasRolls) { return }; /** An object of dice denomination to rows to add */ const rows = {}; const mode = determinePrivacyFromRollMode(options.rollMode); for (const roll of context.rolls) { for (const die of roll.dice) { const size = die.denomination; rows[size] ??= []; for (const result of die.results) { rows[size].push({ mode, value: result.result }); }; }; }; for (const denomination in rows) { CONFIG.stats.db.createRows( `Dice/${denomination}`, author, rows[denomination], ); }; });