Add and tweak D-ATIS

This commit is contained in:
Skylar Grant 2024-06-22 09:42:02 -04:00
parent 444bad7935
commit b11d14b72d
5 changed files with 14 additions and 9 deletions

View File

@ -7,14 +7,18 @@ module.exports = {
alias: [ 'atis' ], alias: [ 'atis' ],
async execute(message, commandData) { async execute(message, commandData) {
try { try {
const icaoId = commandData.args; const icaoId = commandData.args.toUpperCase();
if (icaoId.length !== 4) throw new Error('Not enough or too many ICAO IDs!') 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 datisData = await fn.avWx.datis.getData(icaoId);
const messagePayload = fn.avWx.datis.parseData(datisData[0]); const messagePayload = fn.avWx.datis.parseData(datisData[0]);
message.reply(messagePayload); message.reply(messagePayload);
} else {
message.reply("No D-ATIS available for the specified ICAO ID.");
}
} catch (e) { } catch (e) {
try { try {
message.reply(`Something went wrong while retrieving the METAR: ${e.name}\n\n${e.message}`); message.reply(`D-ATIS Error: ${e.message}`);
console.error(e); console.error(e);
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -16,7 +16,7 @@ module.exports = {
}); });
} catch (e) { } catch (e) {
try { try {
message.reply(`Something went wrong while retrieving the METAR: ${e.name}\n\n${e.message}`); message.reply(`METAR Error: ${e.message}`);
console.error(e); console.error(e);
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@ -831,7 +831,7 @@ const functions = {
async getAllICAOs() { async getAllICAOs() {
const reqUrl = 'https://datis.clowd.io/api/stations'; const reqUrl = 'https://datis.clowd.io/api/stations';
const response = await axios.get(reqUrl); const response = await axios.get(reqUrl);
response.forEach(icaoId => { response.data.forEach(icaoId => {
config.datisICAOs.push(icaoId); config.datisICAOs.push(icaoId);
}); });
}, },

View File

@ -43,6 +43,7 @@ client.once('ready', async () => {
await fn.download.medicalAdvice(client); await fn.download.medicalAdvice(client);
console.log('Ready!'); console.log('Ready!');
await fn.avWx.metar.getAllICAOs(); await fn.avWx.metar.getAllICAOs();
await fn.avWx.datis.getAllICAOs();
// console.log(JSON.stringify(icaoArray)); // console.log(JSON.stringify(icaoArray));
client.channels.fetch(statusChannelId).then(channel => { client.channels.fetch(statusChannelId).then(channel => {
channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`); channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`);

View File

@ -1,6 +1,6 @@
{ {
"name": "nodbot", "name": "nodbot",
"version": "3.3.0", "version": "3.3.1",
"description": "Nods and Nod Accessories, now with ChatGPT!", "description": "Nods and Nod Accessories, now with ChatGPT!",
"main": "main.js", "main": "main.js",
"dependencies": { "dependencies": {