From f291a0e198252717c58a54afdaeaa81ad110b9e9 Mon Sep 17 00:00:00 2001 From: marsalva Date: Tue, 17 Mar 2026 21:55:19 +0000 Subject: [PATCH] Actualizar robot.js --- robot.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/robot.js b/robot.js index 559347f..7576f6a 100644 --- a/robot.js +++ b/robot.js @@ -334,6 +334,9 @@ async function runHomeserve(ownerId, user, pass, gremiosDB) { }); if (scrapData && scrapData['Nombre Cliente']) { + // 🪄 Arreglamos el nombre ANTES de guardarlo (Solo en HomeServe) + scrapData['Nombre Cliente'] = arreglarNombre(scrapData['Nombre Cliente']); + const idGremioDetectado = clasificarGremio(scrapData['Descripción'], gremiosDB); if (idGremioDetectado) { scrapData['guild_id'] = idGremioDetectado; @@ -376,6 +379,26 @@ async function syncAndArchive(ownerId, provider, currentWebRefs) { } } +function normalizarTexto(texto) { + if (!texto) return ""; + return texto.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, ""); +} + +// 🛠️ NUEVO: El "Gira-Nombres" EXCLUSIVO para HomeServe +function arreglarNombre(nombreRaw) { + if (!nombreRaw) return ""; + let nombreLimpio = nombreRaw.trim(); + // Si detectamos que tiene una coma... + if (nombreLimpio.includes(',')) { + let partes = nombreLimpio.split(','); + let apellidos = partes[0].trim(); + let nombre = partes[1].trim(); + // Le damos la vuelta y quitamos espacios sobrantes + nombreLimpio = `${nombre} ${apellidos}`.replace(/\s+/g, ' '); + } + return nombreLimpio; +} + async function saveServiceToDB(ownerId, provider, ref, data) { console.log(`💾 Guardando/Actualizando ${provider.toUpperCase()} ${ref}...`);