// ======================================== // FICHIER: HumanSimulationTracker.js // RESPONSABILITÉ: Système anti-répétition centralisé // Empêche spam de mots/phrases identiques // ======================================== const { logSh } = require('../ErrorReporting'); /** * CLASSE TRACKER CENTRALISÉ * Partage entre tous les modules Human Simulation */ class HumanSimulationTracker { constructor() { // Mots injectés (répétitions personnalité, fatigue) this.injectedWords = new Set(); // Développements de phrases utilisés (soir) this.usedDevelopments = new Set(); // Hésitations utilisées (fatigue élevée) this.usedHesitations = new Set(); // Compteur fautes orthographe/grammaire this.spellingErrorsApplied = 0; // Stats globales this.stats = { wordsInjected: 0, developmentsAdded: 0, hesitationsAdded: 0, spellingErrorsAdded: 0, blockedRepetitions: 0 }; logSh('🧠 HumanSimulationTracker initialisé', 'DEBUG'); } /** * VÉRIFIER SI UN MOT PEUT ÊTRE INJECTÉ * @param {string} word - Mot à injecter * @param {string} content - Contenu actuel * @param {number} maxOccurrences - Maximum occurrences autorisées (défaut: 2) * @returns {boolean} - true si injection autorisée */ canInjectWord(word, content, maxOccurrences = 2) { // Compter occurrences actuelles dans le contenu const regex = new RegExp(`\\b${word}\\b`, 'gi'); const currentCount = (content.match(regex) || []).length; // Vérifier si déjà injecté précédemment const alreadyInjected = this.injectedWords.has(word.toLowerCase()); // Autoriser si < maxOccurrences ET pas déjà injecté const canInject = currentCount < maxOccurrences && !alreadyInjected; if (!canInject) { logSh(` 🚫 Injection bloquée: "${word}" (déjà ${currentCount}× présent ou déjà injecté)`, 'DEBUG'); this.stats.blockedRepetitions++; } return canInject; } /** * ENREGISTRER MOT INJECTÉ * @param {string} word - Mot qui a été injecté */ trackInjectedWord(word) { this.injectedWords.add(word.toLowerCase()); this.stats.wordsInjected++; logSh(` ✅ Mot tracké: "${word}" (total: ${this.stats.wordsInjected})`, 'DEBUG'); } /** * VÉRIFIER SI UN DÉVELOPPEMENT PEUT ÊTRE UTILISÉ * @param {string} development - Développement à ajouter * @returns {boolean} - true si autorisation */ canUseDevelopment(development) { const canUse = !this.usedDevelopments.has(development); if (!canUse) { logSh(` 🚫 Développement bloqué: déjà utilisé dans ce texte`, 'DEBUG'); this.stats.blockedRepetitions++; } return canUse; } /** * ENREGISTRER DÉVELOPPEMENT UTILISÉ * @param {string} development - Développement ajouté */ trackDevelopment(development) { this.usedDevelopments.add(development); this.stats.developmentsAdded++; logSh(` ✅ Développement tracké (total: ${this.stats.developmentsAdded})`, 'DEBUG'); } /** * VÉRIFIER SI HÉSITATION PEUT ÊTRE AJOUTÉE * @param {string} hesitation - Hésitation à ajouter * @returns {boolean} - true si autorisation */ canUseHesitation(hesitation) { const canUse = !this.usedHesitations.has(hesitation); if (!canUse) { logSh(` 🚫 Hésitation bloquée: déjà utilisée`, 'DEBUG'); this.stats.blockedRepetitions++; } return canUse; } /** * ENREGISTRER HÉSITATION UTILISÉE * @param {string} hesitation - Hésitation ajoutée */ trackHesitation(hesitation) { this.usedHesitations.add(hesitation); this.stats.hesitationsAdded++; logSh(` ✅ Hésitation trackée: "${hesitation}" (total: ${this.stats.hesitationsAdded})`, 'DEBUG'); } /** * VÉRIFIER SI FAUTE ORTHOGRAPHE PEUT ÊTRE APPLIQUÉE * Maximum 1 faute par texte complet * @returns {boolean} - true si autorisation */ canApplySpellingError() { const canApply = this.spellingErrorsApplied === 0; if (!canApply) { logSh(` 🚫 Faute spelling bloquée: déjà ${this.spellingErrorsApplied} faute(s) dans ce texte`, 'DEBUG'); } return canApply; } /** * ENREGISTRER FAUTE ORTHOGRAPHE APPLIQUÉE */ trackSpellingError() { this.spellingErrorsApplied++; this.stats.spellingErrorsAdded++; logSh(` ✅ Faute spelling trackée (total: ${this.stats.spellingErrorsAdded})`, 'DEBUG'); } /** * OBTENIR STATISTIQUES * @returns {object} - Stats complètes */ getStats() { return { ...this.stats, injectedWords: Array.from(this.injectedWords), usedDevelopments: this.usedDevelopments.size, usedHesitations: this.usedHesitations.size, spellingErrorsApplied: this.spellingErrorsApplied }; } /** * RÉINITIALISER TRACKER (pour nouveau texte) */ reset() { this.injectedWords.clear(); this.usedDevelopments.clear(); this.usedHesitations.clear(); this.spellingErrorsApplied = 0; logSh('🔄 HumanSimulationTracker réinitialisé', 'DEBUG'); } } // ============= EXPORTS ============= module.exports = { HumanSimulationTracker };