Add weather lookup and reflect command in embed
This commit is contained in:
parent
be7d3a1687
commit
47725a7624
@ -17,7 +17,7 @@ module.exports = {
|
||||
execute(message, file) {
|
||||
options.params.airport_id = file.name;
|
||||
axios.request(options).then(function (response) {
|
||||
const embed = functions.createAirportEmbed(response.data, message.author);
|
||||
const embed = functions.createAirportEmbed(response.data, message.author, `${file.name}.${file.extension}`);
|
||||
message.channel.send(embed).then().catch(err => console.error(err));
|
||||
}).catch(function (error) {
|
||||
console.error(error);
|
||||
|
@ -28,7 +28,7 @@ module.exports = {
|
||||
'embed_url': client.gifs.get(file.name).embed_url,
|
||||
'author': message.author,
|
||||
};
|
||||
message.channel.send(functions.createGifEmbed(gifInfo));
|
||||
message.channel.send(functions.createGifEmbed(gifInfo, message.author, `${file.name}.${file.extension}`));
|
||||
}
|
||||
}
|
||||
}
|
26
commands/weather.js
Normal file
26
commands/weather.js
Normal file
@ -0,0 +1,26 @@
|
||||
const functions = require('../functions.js');
|
||||
const axios = require("axios").default;
|
||||
|
||||
var options = {
|
||||
method: 'GET',
|
||||
url: 'https://weatherapi-com.p.rapidapi.com/current.json',
|
||||
params: {q: ''},
|
||||
headers: {
|
||||
'x-rapidapi-key': '0b3f85bcb7msh1e6e80e963c9914p1d1934jsnc3542fc83520',
|
||||
'x-rapidapi-host': 'weatherapi-com.p.rapidapi.com'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
name: 'weather',
|
||||
description: 'Get the current weather by ZIP code or city name.',
|
||||
execute(message, file) {
|
||||
options.params.q = file.name;
|
||||
axios.request(options).then(function (response) {
|
||||
const embed = functions.createWeatherEmbed(response.data, message.author, `${file.name}.${file.extension}`);
|
||||
message.channel.send(embed).then().catch(err => console.error(err));
|
||||
}).catch(function (error) {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
}
|
@ -16,7 +16,8 @@
|
||||
"joint",
|
||||
"ping",
|
||||
"strain",
|
||||
"airport"
|
||||
"airport",
|
||||
"weather"
|
||||
],
|
||||
"emoji": {
|
||||
"joint": "<:joint:862082955902976000>",
|
||||
|
29
functions.js
29
functions.js
@ -45,13 +45,13 @@ module.exports = {
|
||||
cleanInput(input) {
|
||||
return input.replace(/'/g, '\\\'').replace(/\n/g, '\\n');
|
||||
},
|
||||
createGifEmbed(data) {
|
||||
createGifEmbed(data, author, command) {
|
||||
return new Discord.MessageEmbed()
|
||||
.setAuthor('NodBot v2 - GIF')
|
||||
.setTitle(data.name)
|
||||
.setTitle(command)
|
||||
.setImage(data.embed_url)
|
||||
.setTimestamp()
|
||||
.setFooter('@' + data.author.username + '#' + data.author.discriminator);
|
||||
.setFooter(`@${author.username}#${author.discriminator}`);
|
||||
},
|
||||
saveGif(message, name, embed_url) {
|
||||
fs.writeFile(`./gifs/${name}.js`, `module.exports = {\n\tname: '${name}',\n\tembed_url: '${embed_url}'\n}`, function(err) {
|
||||
@ -61,10 +61,10 @@ module.exports = {
|
||||
message.client.gifs.set(gif.name, gif);
|
||||
});
|
||||
},
|
||||
createAirportEmbed(data, author) {
|
||||
createAirportEmbed(data, author, command) {
|
||||
const airport = data.airport[0];
|
||||
return new Discord.MessageEmbed()
|
||||
.setAuthor('Airport Information')
|
||||
.setAuthor(command)
|
||||
.setTitle(airport.airport_name)
|
||||
.addFields(
|
||||
{ name: 'Location', value: `${airport.city}, ${airport.state_abbrev}`, inline: true },
|
||||
@ -74,5 +74,22 @@ module.exports = {
|
||||
)
|
||||
.setTimestamp()
|
||||
.setFooter(`@${author.username}#${author.discriminator}`);
|
||||
}
|
||||
},
|
||||
createWeatherEmbed(data, author, command) {
|
||||
const loc = data.location;
|
||||
const weather = data.current;
|
||||
return new Discord.MessageEmbed()
|
||||
.setAuthor(command)
|
||||
.setTitle(`${loc.name}, ${loc.region}, ${loc.country} Weather`)
|
||||
.setDescription(`The weather is currently ${weather.condition.text}`)
|
||||
.addFields(
|
||||
{ name: 'Temperature', value: `${weather.temp_f}°F (Feels like: ${weather.feelslike_f}°F)`, inline: true },
|
||||
{ name: 'Winds', value: `${weather.wind_mph} ${weather.wind_dir}`, inline: true },
|
||||
{ name: 'Pressure', value: `${weather.pressure_in}inHg`, inline: true },
|
||||
{ name: 'Relative Humidity', value: `${weather.humidity}%`, inline: true }
|
||||
)
|
||||
.setImage(`https:${weather.condition.icon}`)
|
||||
.setTimestamp()
|
||||
.setFooter(`@${author.username}#${author.discriminator}`);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user