/** * responsesRandomizer module * Listens to all guild messages and randomly sends a generated narrative. * Uses sendNarrative from responses.js. */ import { sendNarrative } from './responses.js'; /** * Initialize the responsesRandomizer module. * @param {import('discord.js').Client} client - Discord client instance. * @param {object} clientConfig - Full client configuration object. */ export async function init(client, clientConfig) { const cfg = clientConfig.responsesRandomizer; const chance = Number(cfg.chance); if (isNaN(chance) || chance <= 0) { client.logger.warn(`[module:responsesRandomizer] Invalid chance value: ${cfg.chance}. Module disabled.`); return; } client.logger.info(`[module:responsesRandomizer] Enabled with chance=${chance}`); client.on('messageCreate', async (message) => { try { // Skip bot messages or non-guild messages if (message.author.bot || !message.guild) return; const content = message.content?.trim(); if (!content) return; // Roll the dice if (Math.random() > chance) return; // Generate and send narrative await sendNarrative(client, clientConfig.responses, message.channel.id, content); } catch (err) { client.logger.error(`[module:responsesRandomizer] Error processing message: ${err.message}`); } }); }