Adding airport info search

This commit is contained in:
= 2021-07-13 20:15:57 -04:00
parent 8fc6505f1d
commit be7d3a1687
4 changed files with 44 additions and 5 deletions

26
commands/airport.js Normal file
View File

@ -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);
});
}
}

View File

@ -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) {
}

View File

@ -15,7 +15,8 @@
"truth",
"joint",
"ping",
"strain"
"strain",
"airport"
],
"emoji": {
"joint": "<:joint:862082955902976000>",

View File

@ -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}`);
}
}