2024-06-21 22:35:12 +00:00
|
|
|
const fn = require('../functions');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: 'metar',
|
|
|
|
description: 'Lookup METAR for an airport',
|
|
|
|
usage: 'ICAO.metar',
|
|
|
|
async execute(message, commandData) {
|
|
|
|
try {
|
|
|
|
// Parse the ICAOs into a CSV list by trimming whitespace and converting delimiters
|
|
|
|
// Also checks for validity of ICAOs
|
|
|
|
const icaoList = fn.avWx.parseICAOs(commandData);
|
|
|
|
const metarData = await fn.avWx.metar.getData(icaoList);
|
2024-09-26 23:55:12 +00:00
|
|
|
if (metarData.length === 0) {
|
|
|
|
message.reply('No METAR data found for the provided ICAOs.');
|
|
|
|
return;
|
|
|
|
}
|
2024-06-21 22:35:12 +00:00
|
|
|
const messages = fn.avWx.metar.parseData(metarData);
|
|
|
|
messages.forEach(messagePayload => {
|
|
|
|
message.reply(messagePayload);
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
try {
|
2024-06-22 13:42:02 +00:00
|
|
|
message.reply(`METAR Error: ${e.message}`);
|
2024-06-21 22:35:12 +00:00
|
|
|
console.error(e);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|