Aggiunto collegamento al server

This commit is contained in:
Giuseppe Raffa
2026-03-11 15:25:03 +01:00
parent c37f30e4ea
commit 41f33ce181
51 changed files with 3088 additions and 4414 deletions

View File

@@ -0,0 +1,84 @@
const dataHub = require('../../tools/dataHub');
/**
* Formatta i dati meteo in un messaggio Telegram leggibile.
* @returns {string} Testo formattato Markdown
*/
function formatWeatherData() {
const { forecast, sea } = dataHub.getWeatherData();
if (!forecast && !sea) {
return 'Nessun dato meteo disponibile.\nIl polling potrebbe non essere ancora partito.';
}
let text = '*Meteo Attuale*\n';
text += `_${new Date().toLocaleTimeString('it-IT')}_\n\n`;
if (forecast) {
if (forecast.temperature !== null && forecast.temperature !== undefined) {
text += `Temperatura: *${forecast.temperature}*C\n`;
}
if (forecast.humidity !== null && forecast.humidity !== undefined) {
text += `Umidita: *${forecast.humidity}*%\n`;
}
if (forecast.pressure !== null && forecast.pressure !== undefined) {
text += `Pressione: *${forecast.pressure}* hPa\n`;
}
if (forecast.rain !== null && forecast.rain !== undefined) {
text += `Pioggia: *${forecast.rain}* mm\n`;
}
if (forecast.wind) {
text += `\nVento:\n`;
if (forecast.wind.speed !== null && forecast.wind.speed !== undefined) {
text += ` Velocita: *${forecast.wind.speed}* km/h\n`;
}
if (forecast.wind.direction !== null && forecast.wind.direction !== undefined) {
text += ` Direzione: *${forecast.wind.direction}*\n`;
}
if (forecast.wind.gusts !== null && forecast.wind.gusts !== undefined) {
text += ` Raffiche: *${forecast.wind.gusts}* km/h\n`;
}
}
}
if (sea) {
text += `\nMare:\n`;
if (sea.waves) {
if (sea.waves.height !== null && sea.waves.height !== undefined) {
text += ` Altezza onde: *${sea.waves.height}* m\n`;
}
if (sea.waves.period !== null && sea.waves.period !== undefined) {
text += ` Periodo: *${sea.waves.period}* s\n`;
}
if (sea.waves.direction !== null && sea.waves.direction !== undefined) {
text += ` Direzione: *${sea.waves.direction}*\n`;
}
}
if (sea.temperature !== null && sea.temperature !== undefined) {
text += ` Temp. acqua: *${sea.temperature}*C\n`;
}
}
return text;
}
module.exports = {
command: 'weather',
description: 'Mostra i dati meteo attuali',
pattern: /\/weather/,
execute: async (bot, msg) => {
const chatId = msg.chat.id;
const text = formatWeatherData();
await bot.sendMessage(chatId, text, {
parse_mode: 'Markdown',
reply_markup: {
inline_keyboard: [
[{ text: 'Aggiorna', callback_data: 'weather-refresh' }]
]
}
});
},
formatWeatherData
};