diff --git a/dot-commands/datis.js b/dot-commands/datis.js index c494761..478f44c 100644 --- a/dot-commands/datis.js +++ b/dot-commands/datis.js @@ -7,14 +7,18 @@ module.exports = { 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); + 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(`Something went wrong while retrieving the METAR: ${e.name}\n\n${e.message}`); + message.reply(`D-ATIS Error: ${e.message}`); console.error(e); } catch (e) { console.error(e); diff --git a/dot-commands/metar.js b/dot-commands/metar.js index 2da15b5..33207e9 100644 --- a/dot-commands/metar.js +++ b/dot-commands/metar.js @@ -16,7 +16,7 @@ module.exports = { }); } catch (e) { 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); } catch (e) { console.error(e); diff --git a/functions.js b/functions.js index 8e2666a..47f69dc 100644 --- a/functions.js +++ b/functions.js @@ -831,7 +831,7 @@ const functions = { async getAllICAOs() { const reqUrl = 'https://datis.clowd.io/api/stations'; const response = await axios.get(reqUrl); - response.forEach(icaoId => { + response.data.forEach(icaoId => { config.datisICAOs.push(icaoId); }); }, diff --git a/main.js b/main.js index 7902b9e..55a347c 100644 --- a/main.js +++ b/main.js @@ -43,6 +43,7 @@ client.once('ready', async () => { await fn.download.medicalAdvice(client); console.log('Ready!'); await fn.avWx.metar.getAllICAOs(); + await fn.avWx.datis.getAllICAOs(); // console.log(JSON.stringify(icaoArray)); client.channels.fetch(statusChannelId).then(channel => { channel.send(`${new Date().toISOString()} -- <@${process.env.ownerId}>\nStartup Sequence Complete`); diff --git a/package.json b/package.json index 92c9503..566a3e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodbot", - "version": "3.3.0", + "version": "3.3.1", "description": "Nods and Nod Accessories, now with ChatGPT!", "main": "main.js", "dependencies": {