const recorder = require('../../cores/logs.local'); const { closeButton } = require('../utility/close'); module.exports = { command: 'logs', handler: async (bot, msg) => { const chatId = msg.chat.id; const logs = await recorder.listLogs(); if (!logs || logs.length === 0) { await bot.sendMessage(chatId, 'Nessun file di log disponibile.', { reply_to_message_id: msg.message_id, reply_markup: closeButton(msg.message_id) }); return; } const session = recorder.getSession(); let text = '*Registrazioni dei Log*\n\n'; if (session) { text += `in corso: *${session.name}*\n`; text += `${session.elements} dati raccolti ogni ${session.delay}s\n\n`; } text += `${logs.length} file disponibili:\n`; text += '_Selezionane uno per scaricarlo_'; // Bottoni per ogni file const keyboard = logs.map(log => { const date = new Date(log.created).toLocaleDateString('it-IT', { day: '2-digit', month: '2-digit', year: '2-digit', hour: '2-digit', minute: '2-digit' }); const isActive = session && session.name === log.name; const label = isActive ? `🔴 ${log.name} *[IN CORSO, NON DISPONIBILE]*` : `${date})`; const callback = isActive ? `logbusy:${log.name}` : `logfile:${log.name}:${msg.message_id}`; return [{ text: label, callback_data: callback }]; }); // Aggiungi il bottone chiudi keyboard.push([{ text: '<- Chiudi', callback_data: `close:${msg.message_id}` }]); await bot.sendMessage(chatId, text, { parse_mode: 'Markdown', reply_to_message_id: msg.message_id, reply_markup: { inline_keyboard: keyboard } }); } };