diff --git a/commands/airport.js b/commands/airport.js new file mode 100644 index 0000000..54e57be --- /dev/null +++ b/commands/airport.js @@ -0,0 +1,26 @@ +const axios = require("axios").default; +const functions = require('../functions.js'); + +let options = { + method: 'GET', + url: 'https://forteweb-airportguide-airport-basic-info-v1.p.rapidapi.com/get_airport_by_iata', + params: {auth: 'authairport567', airport_id: 'LAX'}, + headers: { + 'x-rapidapi-key': '0b3f85bcb7msh1e6e80e963c9914p1d1934jsnc3542fc83520', + 'x-rapidapi-host': 'forteweb-airportguide-airport-basic-info-v1.p.rapidapi.com' + } +}; + +module.exports = { + name: 'airport', + description: 'Get airport information by IATA code.', + execute(message, file) { + options.params.airport_id = file.name; + axios.request(options).then(function (response) { + const embed = functions.createAirportEmbed(response.data, message.author); + message.channel.send(embed).then().catch(err => console.error(err)); + }).catch(function (error) { + console.error(error); + }); + } +} \ No newline at end of file diff --git a/commands/template b/commands/template index ed1de33..225e811 100644 --- a/commands/template +++ b/commands/template @@ -1,8 +1,6 @@ -const axios = require('axios').default; - module.exports = { - name: 'strain', - description: 'Search for information about a cannabis strain. Powered by Otreeba', + name: '', + description: '', execute(message, file) { } diff --git a/config.json b/config.json index 17ad28d..94dbd1e 100644 --- a/config.json +++ b/config.json @@ -15,7 +15,8 @@ "truth", "joint", "ping", - "strain" + "strain", + "airport" ], "emoji": { "joint": "<:joint:862082955902976000>", diff --git a/functions.js b/functions.js index d3ef14f..aa4f8c1 100644 --- a/functions.js +++ b/functions.js @@ -60,5 +60,19 @@ module.exports = { const gif = require(`./gifs/${name}.js`); message.client.gifs.set(gif.name, gif); }); + }, + createAirportEmbed(data, author) { + const airport = data.airport[0]; + return new Discord.MessageEmbed() + .setAuthor('Airport Information') + .setTitle(airport.airport_name) + .addFields( + { name: 'Location', value: `${airport.city}, ${airport.state_abbrev}`, inline: true }, + { name: 'Coordinates', value: `${airport.latitude}, ${airport.longitude}`, inline: true }, + { name: 'Elevation', value: `${airport.elevation}ft`, inline: true }, + { name: 'More Information', value: airport.link_path } + ) + .setTimestamp() + .setFooter(`@${author.username}#${author.discriminator}`); } } \ No newline at end of file