const recorder = require('../../cores/logs.local'); module.exports = { prefix: 'logfile:', handler: async (bot, query) => { const chatId = query.message.chat.id; const listMessageId = query.message.message_id; // callback_data = logfile:: const parts = query.data.split(':'); const logName = parts[1]; const userMessageId = parts[2]; // Elimina il messaggio con la lista dei file try { await bot.deleteMessage(chatId, listMessageId); } catch (e) {} // Ottieni il file e le sue informazioni const filePath = recorder.getLogFile(logName); if (!filePath) { bot.answerCallbackQuery(query.id, { text: 'File non trovato' }); return; } // Controllo aggiuntivo: se il file è quello in registrazione attiva const session = recorder.getSession(); if (session && session.name === logName) { bot.answerCallbackQuery(query.id, { text: `Il file "${logName}" è attualmente in uso per la registrazione attiva. Fermala per scaricarlo.`, show_alert: true }); return; } // Ottieni info del file const fs = require('fs'); const stat = fs.statSync(filePath); const sizeMB = (stat.size / (1024 * 1024)).toFixed(2); const created = new Date(stat.birthtime).toLocaleDateString('it-IT', { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit' }); const caption = `*CSV\nCreato: ${created}\ ${sizeMB} MB`; // Invia il file const docMessage = await bot.sendDocument(chatId, filePath, { caption: caption, parse_mode: 'Markdown' }); // Elimina il messaggio dell'utente (il comando /logs) try { if (userMessageId) { await bot.deleteMessage(chatId, parseInt(userMessageId)); } } catch (e) {} // Dopo 5 secondi, elimina il messaggio con il documento setTimeout(async () => { try { await bot.deleteMessage(chatId, docMessage.message_id); } catch (e) {} }, 10000); //dopo 10 secondi bot.answerCallbackQuery(query.id); } };