Add weather lookup and reflect command in embed

This commit is contained in:
= 2021-07-13 20:52:54 -04:00
parent be7d3a1687
commit 47725a7624
5 changed files with 53 additions and 9 deletions

View File

@ -17,7 +17,7 @@ module.exports = {
execute(message, file) { execute(message, file) {
options.params.airport_id = file.name; options.params.airport_id = file.name;
axios.request(options).then(function (response) { 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)); message.channel.send(embed).then().catch(err => console.error(err));
}).catch(function (error) { }).catch(function (error) {
console.error(error); console.error(error);

View File

@ -28,7 +28,7 @@ module.exports = {
'embed_url': client.gifs.get(file.name).embed_url, 'embed_url': client.gifs.get(file.name).embed_url,
'author': message.author, '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
View 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);
});
}
}

View File

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

View File

@ -45,13 +45,13 @@ module.exports = {
cleanInput(input) { cleanInput(input) {
return input.replace(/'/g, '\\\'').replace(/\n/g, '\\n'); return input.replace(/'/g, '\\\'').replace(/\n/g, '\\n');
}, },
createGifEmbed(data) { createGifEmbed(data, author, command) {
return new Discord.MessageEmbed() return new Discord.MessageEmbed()
.setAuthor('NodBot v2 - GIF') .setAuthor('NodBot v2 - GIF')
.setTitle(data.name) .setTitle(command)
.setImage(data.embed_url) .setImage(data.embed_url)
.setTimestamp() .setTimestamp()
.setFooter('@' + data.author.username + '#' + data.author.discriminator); .setFooter(`@${author.username}#${author.discriminator}`);
}, },
saveGif(message, name, embed_url) { saveGif(message, name, embed_url) {
fs.writeFile(`./gifs/${name}.js`, `module.exports = {\n\tname: '${name}',\n\tembed_url: '${embed_url}'\n}`, function(err) { 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); message.client.gifs.set(gif.name, gif);
}); });
}, },
createAirportEmbed(data, author) { createAirportEmbed(data, author, command) {
const airport = data.airport[0]; const airport = data.airport[0];
return new Discord.MessageEmbed() return new Discord.MessageEmbed()
.setAuthor('Airport Information') .setAuthor(command)
.setTitle(airport.airport_name) .setTitle(airport.airport_name)
.addFields( .addFields(
{ name: 'Location', value: `${airport.city}, ${airport.state_abbrev}`, inline: true }, { name: 'Location', value: `${airport.city}, ${airport.state_abbrev}`, inline: true },
@ -74,5 +74,22 @@ module.exports = {
) )
.setTimestamp() .setTimestamp()
.setFooter(`@${author.username}#${author.discriminator}`); .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}`);
}
} }