Files
signalk-plugin/plugin/telegram/commands/structure.js
2026-03-11 15:25:03 +01:00

48 lines
1.8 KiB
JavaScript

const realtime = require('../../realtime/core.js');
module.exports = {
command: 'structure',
description: 'Mostra la struttura dati del plugin',
pattern: /\/structure/,
execute: async (bot, msg) => {
const chatId = msg.chat.id;
const rules = realtime.getSensorRules();
if (!rules) {
return bot.sendMessage(chatId, 'Nessuna configurazione sensori caricata.');
}
let text = `*Struttura Dati Plugin*\n`;
text += `Versione: \`${rules.version}\`\n`;
text += `Attivo: ${rules.isActive ? 'Si' : 'No'}\n`;
text += `Collezioni: ${rules.items?.length || 0}\n\n`;
if (rules.items) {
for (const item of rules.items) {
text += `*${item.collection}*\n`;
text += ` Path: \`${item.main_path}\`\n`;
if (item.elements && Array.isArray(item.elements)) {
for (const element of item.elements) {
const { subelements, ...fields } = element;
const [name, subPath] = Object.entries(fields)[0];
text += ` - ${name} -> \`${item.main_path}.${subPath}\`\n`;
if (subelements && Array.isArray(subelements)) {
for (const sub of subelements) {
const [sName, sPath] = Object.entries(sub)[0];
text += ` - ${sName} -> \`${item.main_path}.${subPath}.${sPath}\`\n`;
}
}
}
} else {
text += ` (valore singolo)\n`;
}
text += `\n`;
}
}
await bot.sendMessage(chatId, text, { parse_mode: 'Markdown' });
}
};