54 lines
2.0 KiB
JavaScript
54 lines
2.0 KiB
JavaScript
const realtime = require('../../realtime/core.js');
|
|
const { config } = require('../../config.js');
|
|
|
|
module.exports = {
|
|
command: 'logs',
|
|
description: 'Mostra lo stato della registrazione dati in tempo reale',
|
|
pattern: /\/logs/,
|
|
execute: async (bot, msg, { app }) => {
|
|
const chatId = msg.chat.id;
|
|
try {
|
|
const stats = realtime.getStats();
|
|
const consoleUrl = config.cloudUrl || 'https://console.mebboat.it';
|
|
|
|
let statusIcon = '🔴';
|
|
if (stats.status === 'connected') statusIcon = '🟢';
|
|
else if (stats.status === 'error') statusIcon = '🟡';
|
|
|
|
let text = `📊 *Registrazione Dati Realtime*\n\n`;
|
|
text += `Stato: ${statusIcon} *${stats.status}*\n`;
|
|
text += `Sensore: \`${stats.sensorID}\`\n`;
|
|
text += `Messaggi inviati: *${stats.sent}*\n`;
|
|
text += `Frequenza: ogni *${stats.sentEveryMLS / 1000}s*\n`;
|
|
|
|
if (stats.buffered > 0) {
|
|
text += `⚠️ Messaggi in buffer: *${stats.buffered}*\n`;
|
|
}
|
|
|
|
if (stats.reconnections > 0) {
|
|
text += `Riconnessioni: ${stats.reconnections}\n`;
|
|
}
|
|
|
|
if (stats.firstSent) {
|
|
text += `\nPrimo invio: ${stats.firstSent}\n`;
|
|
}
|
|
|
|
text += `\n_I dati vengono inviati automaticamente al server ogni secondo._`;
|
|
text += `\n_Consulta i log storici sulla console:_`;
|
|
|
|
await bot.sendMessage(chatId, text, {
|
|
parse_mode: 'Markdown',
|
|
reply_markup: {
|
|
inline_keyboard: [
|
|
[{ text: '📈 Apri Console Log', url: `${consoleUrl}/logs` }],
|
|
[{ text: '🔄 Aggiorna Stato', callback_data: 'logs-refresh' }]
|
|
]
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.error("[Telegram] Errore comando /logs:", error);
|
|
bot.sendMessage(chatId, `❌ Errore: ${error.message}`);
|
|
}
|
|
}
|
|
};
|