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:
2026-02-19 16:05:59 -06:00
parent 0c053ab036
commit aa98d9185f
3 changed files with 103 additions and 20 deletions

View File

@@ -2,6 +2,7 @@
require_once __DIR__ . '/../../includes/db.php';
require_once __DIR__ . '/../../includes/env_loader.php';
require_once __DIR__ . '/../../includes/emoji_helper.php';
require_once __DIR__ . '/../TelegramSender.php';
require_once __DIR__ . '/../actions/TelegramActions.php';
require_once __DIR__ . '/../converters/HtmlToTelegramHtmlConverter.php';
@@ -49,8 +50,18 @@ try {
sendWelcomeMessage($pdo, $sender, $chatId, $username);
}
// Procesar texto de mensajes regulares
if (!empty($text)) {
// Ignorar stickers puros (sin caption)
if (isset($message['sticker']) && empty($caption)) {
exit('Sticker ignorado');
}
// Ignorar GIFs/animaciones puras (sin caption)
if (isset($message['animation']) && empty($caption)) {
exit('GIF ignorado');
}
// Procesar texto de mensajes regulares (solo si tiene contenido real)
if (!empty($text) && hasRealContent($text)) {
if (str_starts_with($text, '/')) {
handleTelegramCommand($sender, $pdo, $chatId, $userId, $text, $username);
} elseif (str_starts_with($text, '#')) {
@@ -60,12 +71,11 @@ try {
handleTelegramMessage($pdo, $sender, $chatId, $userId, $text);
}
}
// Procesar caption de fotos o videos
elseif (!empty($caption)) {
// Solo traducir si hay caption
// Procesar caption de fotos o videos (solo si tiene contenido real)
elseif (!empty($caption) && hasRealContent($caption)) {
handleTelegramMessage($pdo, $sender, $chatId, $userId, $caption);
}
// Si no hay texto ni caption, ignorar (foto/video sin texto)
// Si no hay contenido real (solo emojis, stickers, GIFs), ignorar
} elseif (isset($update['callback_query'])) {
$callbackQuery = $update['callback_query'];
@@ -99,7 +109,9 @@ function registerTelegramUser(PDO $pdo, array $user): void
function handleAutoTranslation(PDO $pdo, Telegram\TelegramSender $sender, src\Translate $translator, int $chatId, string $text): void
{
$keyboard = getTelegramTranslationButtons($pdo, $text);
// Usar texto sin emojis para detección de idioma, pero guardar el original para mostrar
$textForDetection = stripEmojisForDetection($text);
$keyboard = getTelegramTranslationButtons($pdo, $textForDetection ?: $text);
if (!empty($keyboard)) {
$message = "🌐 <b>Traducciones disponibles:</b>\nHaz clic en una bandera para ver la traducción";
@@ -256,8 +268,8 @@ function handleTelegramCommand(Telegram\TelegramSender $sender, PDO $pdo, int $c
function handleTelegramMessage(PDO $pdo, Telegram\TelegramSender $sender, int $chatId, int $userId, string $text): void
{
// 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;
}
@@ -380,12 +392,13 @@ function handleTelegramCallback(PDO $pdo, Telegram\TelegramSender $sender, src\T
}
try {
// Obtener el idioma original
$sourceLang = $translator->detectLanguage($originalText) ?? 'es';
// Obtener el idioma original (usar texto sin emojis para mayor precisión)
$textForDetection = stripEmojisForDetection($originalText);
$sourceLang = $translator->detectLanguage($textForDetection) ?? 'es';
file_put_contents('/var/www/html/lastwar/logs/telegram_debug.log', date('Y-m-d H:i:s') . " - sourceLang: $sourceLang, targetLang: $targetLang, originalText: " . substr($originalText, 0, 50) . "\n", FILE_APPEND);
// Traducir
$translated = $translator->translate($originalText, $sourceLang, $targetLang);
// Traducir (usar texto sin emojis para evitar interferencias)
$translated = $translator->translate($textForDetection ?: $originalText, $sourceLang, $targetLang);
file_put_contents('/var/www/html/lastwar/logs/telegram_debug.log', date('Y-m-d H:i:s') . " - translated: $translated\n", FILE_APPEND);
if ($translated) {