nodbot/dot-commands/datis.js

28 lines
800 B
JavaScript
Raw Normal View History

2024-06-22 13:17:24 +00:00
const fn = require('../functions');
module.exports = {
name: 'datis',
description: 'Lookup dATIS for an airport',
usage: 'ICAO.datis',
alias: [ 'atis' ],
async execute(message, commandData) {
try {
2024-06-22 13:42:02 +00:00
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);
2024-06-22 14:08:28 +00:00
const messagePayload = fn.avWx.datis.parseData(datisData);
2024-06-22 13:42:02 +00:00
message.reply(messagePayload);
} else {
message.reply("No D-ATIS available for the specified ICAO ID.");
}
2024-06-22 13:17:24 +00:00
} catch (e) {
try {
2024-06-22 13:42:02 +00:00
message.reply(`D-ATIS Error: ${e.message}`);
2024-06-22 13:17:24 +00:00
console.error(e);
} catch (e) {
console.error(e);
}
}
}
}