Mejoras en el envío de plantillas con imágenes
- Agregar detección de URLs de Discord gifts para evitar botones de traducción - Enviar imágenes en orden correcto (texto-imagen-texto-imagen) en Discord y Telegram - Usar APP_URL del .env para las URLs de imágenes - Agregar funciones sendContentWithOrderedImagesAndButtons en ambos bots
This commit is contained in:
@@ -113,40 +113,31 @@ function handleTemplateCommand(PDO $pdo, Message $message, string $command): voi
|
||||
$template = $stmt->fetch();
|
||||
|
||||
if ($template) {
|
||||
require_once __DIR__ . '/discord/converters/HtmlToDiscordMarkdownConverter.php';
|
||||
require_once __DIR__ . '/discord/DiscordSender.php';
|
||||
require_once __DIR__ . '/src/Translate.php';
|
||||
|
||||
$converter = new \Discord\Converters\HtmlToDiscordMarkdownConverter();
|
||||
|
||||
$images = $converter->extractImages($template['message_content']);
|
||||
$contentWithoutImages = $converter->removeImages($template['message_content']);
|
||||
$content = $converter->convert($contentWithoutImages);
|
||||
|
||||
require_once __DIR__ . '/discord/DiscordSender.php';
|
||||
require_once __DIR__ . '/src/Translate.php';
|
||||
|
||||
$sender = new \Discord\DiscordSender();
|
||||
|
||||
$plainText = $template['message_content'];
|
||||
$plainText = preg_replace('/<br\s*\/?>/i', "\n", $plainText);
|
||||
$plainText = preg_replace('/<\/p>/i', "\n", $plainText);
|
||||
$plainText = preg_replace('/<p[^>]*>/i', '', $plainText);
|
||||
$plainText = strip_tags($plainText);
|
||||
$plainText = html_entity_decode($plainText, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
$plainText = trim($plainText);
|
||||
|
||||
$translationButtons = getDiscordTranslationButtons($pdo, $plainText);
|
||||
|
||||
if (!empty($images)) {
|
||||
$sender->sendMessageWithImages((string)$message->channel_id, $content, $images, $translationButtons);
|
||||
$sender = new \Discord\DiscordSender();
|
||||
|
||||
// Parsear el contenido manteniendo el orden texto-imagen
|
||||
$segments = $sender->parseContent($template['message_content']);
|
||||
|
||||
if (!empty($segments)) {
|
||||
// Obtener texto completo para botones de traducción
|
||||
$plainText = $template['message_content'];
|
||||
$plainText = preg_replace('/<br\s*\/?>/i', "\n", $plainText);
|
||||
$plainText = preg_replace('/<\/p>/i', "\n", $plainText);
|
||||
$plainText = preg_replace('/<p[^>]*>/i', '', $plainText);
|
||||
$plainText = strip_tags($plainText);
|
||||
$plainText = html_entity_decode($plainText, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
$plainText = trim($plainText);
|
||||
|
||||
$translationButtons = getDiscordTranslationButtons($pdo, $plainText);
|
||||
|
||||
// Enviar contenido ordenado con botones
|
||||
$sender->sendContentWithOrderedImagesAndButtons((string)$message->channel_id, $segments, $translationButtons);
|
||||
}
|
||||
} else {
|
||||
$sender->sendMessage((string)$message->channel_id, $content, null, $translationButtons);
|
||||
$message->channel->sendMessage("❌ Plantilla no encontrada: #{$command}");
|
||||
}
|
||||
|
||||
} else {
|
||||
$message->channel->sendMessage("❌ Plantilla no encontrada: #{$command}");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$message->channel->sendMessage("❌ Error: " . $e->getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user