Feature: Manejo inteligente de emojis, stickers y GIFs
Cambios principales: - Nuevo archivo: includes/emoji_helper.php * hasRealContent(): Detecta si hay contenido real (no solo emojis) * stripEmojisForDetection(): Preserva emojis visuales pero mejora detección de idioma Telegram (telegram_bot_webhook.php): - Ignorar stickers puros sin caption - Ignorar GIFs/animaciones puras sin caption - Procesar caption si tiene contenido real - Usar stripEmojisForDetection() para mejor precisión en idioma Discord (discord_bot.php): - Ignorar mensajes con solo emojis/espacios - Usar stripEmojisForDetection() para detección más precisa - Intentar preservar emojis en la traducción Comportamiento: - Solo 👍 = Ignorado - Hola 👍 = Traducido como 'Hola' (emoji se preserva) - {sticker_sin_caption} = Ignorado - {gif_sin_caption} = Ignorado - {foto_con_caption} = Caption traducido
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
require_once __DIR__ . '/includes/db.php';
|
||||
require_once __DIR__ . '/includes/env_loader.php';
|
||||
require_once __DIR__ . '/includes/emoji_helper.php';
|
||||
|
||||
use Discord\Discord;
|
||||
use Discord\Parts\Channel\Message;
|
||||
@@ -331,16 +332,17 @@ function sendToN8NIA(Message $message, string $userMessage): void
|
||||
function handleAutoTranslationWithButtons(PDO $pdo, Message $message, string $text): void
|
||||
{
|
||||
try {
|
||||
// Si no hay texto, ignorar (ej: solo imagen/video sin caption)
|
||||
if (empty(trim($text))) {
|
||||
// Si no hay contenido real (solo emojis, espacios), ignorar
|
||||
if (!hasRealContent($text)) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/src/Translate.php';
|
||||
$translator = new src\Translate();
|
||||
|
||||
// Detectar idioma del mensaje
|
||||
$detectedLang = $translator->detectLanguage($text) ?? 'es';
|
||||
// Detectar idioma del mensaje (sin emojis para mejor precisión)
|
||||
$textForDetection = stripEmojisForDetection($text);
|
||||
$detectedLang = $translator->detectLanguage($textForDetection) ?? 'es';
|
||||
|
||||
// Obtener idiomas activos de la base de datos
|
||||
$stmt = $pdo->query("SELECT language_code, flag_emoji FROM supported_languages WHERE is_active = 1");
|
||||
@@ -531,8 +533,10 @@ function handleTranslateInteraction($interaction, string $customId): void
|
||||
$interaction->respondWithMessage($loadingBuilder, true);
|
||||
|
||||
// Ahora traducir (esto puede tardar)
|
||||
$sourceLang = $translator->detectLanguage($originalText) ?? 'es';
|
||||
$translated = $translator->translate($originalText, $sourceLang, $targetLang);
|
||||
// Usar texto sin emojis para detectar idioma y traducir con mayor precisión
|
||||
$textForDetection = stripEmojisForDetection($originalText);
|
||||
$sourceLang = $translator->detectLanguage($textForDetection) ?? 'es';
|
||||
$translated = $translator->translate($textForDetection, $sourceLang, $targetLang);
|
||||
|
||||
if ($translated) {
|
||||
// Limpiar todo el HTML
|
||||
@@ -546,8 +550,24 @@ function handleTranslateInteraction($interaction, string $customId): void
|
||||
$translated = preg_replace('/\n\s*\n/', "\n", $translated);
|
||||
|
||||
// Actualizar la respuesta con la traducción real
|
||||
// Preservar emojis del original si los hay
|
||||
$displayText = trim($translated);
|
||||
if (strpos($originalText, '👍') !== false || preg_match('/[\x{1F300}-\x{1F9FF}]/u', $originalText)) {
|
||||
// Si el original tenía emojis, intentar identificarlos
|
||||
// Para mensajes simples, los emojis generalmente están al inicio o final
|
||||
$emojiPrefix = '';
|
||||
$emojiSuffix = '';
|
||||
if (preg_match('/^([\x{1F300}-\x{1F9FF}]+)\s*/u', $originalText, $match)) {
|
||||
$emojiPrefix = $match[1] . ' ';
|
||||
}
|
||||
if (preg_match('/\s*([\x{1F300}-\x{1F9FF}]+)$/u', $originalText, $match)) {
|
||||
$emojiSuffix = ' ' . $match[1];
|
||||
}
|
||||
$displayText = $emojiPrefix . $displayText . $emojiSuffix;
|
||||
}
|
||||
|
||||
$finalBuilder = \Discord\Builders\MessageBuilder::new()
|
||||
->setContent("🌐 **Traducción (" . strtoupper($targetLang) . "):**\n\n" . trim($translated));
|
||||
->setContent("🌐 **Traducción (" . strtoupper($targetLang) . "):**\n\n" . $displayText);
|
||||
$interaction->updateOriginalResponse($finalBuilder);
|
||||
} else {
|
||||
// Actualizar con error
|
||||
|
||||
Reference in New Issue
Block a user