nodbot/dot-commands/datis.js

24 lines
675 B
JavaScript

const fn = require('../functions');
module.exports = {
name: 'datis',
description: 'Lookup dATIS for an airport',
usage: 'ICAO.datis',
alias: [ 'atis' ],
async execute(message, commandData) {
try {
const icaoId = commandData.args;
if (icaoId.length !== 4) throw new Error('Not enough or too many ICAO IDs!')
const datisData = await fn.avWx.datis.getData(icaoId);
const messagePayload = fn.avWx.datis.parseData(datisData[0]);
message.reply(messagePayload);
} catch (e) {
try {
message.reply(`Something went wrong while retrieving the METAR: ${e.name}\n\n${e.message}`);
console.error(e);
} catch (e) {
console.error(e);
}
}
}
}