feat: add support for image attachments in AI requests and enhance metadata handling

This commit is contained in:
2025-10-04 02:30:28 -05:00
parent 2194273b09
commit d1264d6824
3 changed files with 342 additions and 24 deletions

View File

@@ -225,8 +225,46 @@ export const command: CommandMessage = {
try {
let aiResponse: string;
// Usar el nuevo método con memoria persistente
if (isReplyToAI || true) { // Siempre usar memoria por ahora
// Verificar si hay imágenes adjuntas
const attachments = Array.from(message.attachments.values());
const hasImages = attachments.length > 0 && aiService.hasImageAttachments?.(attachments);
// Usar el nuevo método con memoria persistente y soporte para imágenes
if (hasImages) {
// Agregar información sobre las imágenes a los metadatos
const imageInfo = attachments
.filter(att => att.contentType?.startsWith('image/') ||
['.jpg', '.jpeg', '.png', '.gif', '.webp', '.bmp'].some(ext =>
att.name?.toLowerCase().endsWith(ext)))
.map(att => `${att.name} (${att.contentType || 'imagen'})`)
.join(', ');
const enhancedMeta = messageMeta + (imageInfo ? ` | Imágenes adjuntas: ${imageInfo}` : '');
// Usar método específico para imágenes
const request = {
userId,
guildId,
channelId: message.channel.id,
prompt: prompt.trim(),
priority: 'normal' as const,
timestamp: Date.now(),
aiRolePrompt: undefined,
meta: enhancedMeta,
messageId: message.id,
referencedMessageId,
attachments: attachments,
client: message.client
};
// Procesar con imágenes
aiResponse = await new Promise((resolve, reject) => {
request.resolve = resolve;
request.reject = reject;
aiService.requestQueue.push(request as any);
});
} else {
// Método normal sin imágenes
aiResponse = await aiService.processAIRequestWithMemory(
userId,
prompt,
@@ -238,15 +276,6 @@ export const command: CommandMessage = {
'normal',
{ meta: messageMeta }
);
} else {
// Método legacy para compatibilidad
aiResponse = await aiService.processAIRequest(
userId,
prompt,
guildId,
'normal',
{ meta: messageMeta }
);
}
// Reemplazar :nombre: por el tag real del emoji, evitando bloques de código