52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
const realtime = require('../../realtime/core.js');
|
|
const { config } = require('../../config.js');
|
|
|
|
module.exports = [
|
|
{
|
|
id: 'logs-refresh',
|
|
execute: async ({ bot, chatId, msg }) => {
|
|
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 = '🟡';
|
|
|
|
const now = new Date().toLocaleTimeString('it-IT');
|
|
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`;
|
|
}
|
|
|
|
text += `\n_(Aggiornato: ${now})_`;
|
|
|
|
try {
|
|
await bot.editMessageText(text, {
|
|
chat_id: chatId,
|
|
message_id: msg.message_id,
|
|
parse_mode: 'Markdown',
|
|
reply_markup: {
|
|
inline_keyboard: [
|
|
[{ text: '📈 Apri Console Log', url: `${consoleUrl}/logs` }],
|
|
[{ text: '🔄 Aggiorna Stato', callback_data: 'logs-refresh' }]
|
|
]
|
|
}
|
|
});
|
|
} catch (e) {
|
|
if (!e.message.includes('message is not modified')) {
|
|
console.error("[Telegram] Errore refresh logs:", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
];
|