85 lines
2.9 KiB
JavaScript
85 lines
2.9 KiB
JavaScript
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
|
|
};
|