28 lines
803 B
JavaScript
28 lines
803 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.toUpperCase();
|
|
if (icaoId.length !== 4) throw new Error('Invalid ICAO ID. Provide only one ICAO code at a time like KBOS');
|
|
if (fn.avWx.datis.validate(icaoId)) {
|
|
const datisData = await fn.avWx.datis.getData(icaoId);
|
|
const messagePayload = fn.avWx.datis.parseData(datisData[0]);
|
|
message.reply(messagePayload);
|
|
} else {
|
|
message.reply("No D-ATIS available for the specified ICAO ID.");
|
|
}
|
|
} catch (e) {
|
|
try {
|
|
message.reply(`D-ATIS Error: ${e.message}`);
|
|
console.error(e);
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
}
|
|
} |