woomy/src/commands/weather.js

64 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-01-25 10:02:43 +00:00
const weather = require("weather-js");
exports.run = async (client, message, args, error) => {
if(!args[0]) {
2020-03-09 01:11:33 +00:00
return message.channel.send(
2020-01-25 10:02:43 +00:00
`<:error:466995152976871434> You didn't give me a location. Usage: \`${client.commands.get(`weather`).help.usage}\``
);
};
2020-03-09 01:11:33 +00:00
message.channel.startTyping();
2020-03-26 04:31:32 +00:00
try {
weather.find({search: args.join(" "), degreeType: 'C'}, function(err, result) {
if(err) return message.channel.send(`<:error:466995152976871434> API error: \`${error}\``)
if(result.length < 2 || !result) {
message.channel.stopTyping();
return message.channel.send("<:error:466995152976871434> City not found!");
};
2020-01-25 10:02:43 +00:00
2020-03-26 04:31:32 +00:00
var location = result[0].location;
var current = result[0].current;
2020-01-25 10:02:43 +00:00
2020-03-26 04:31:32 +00:00
var warning = (`${location.alert}` || "No warnings");
2020-01-25 10:02:43 +00:00
2020-03-26 04:31:32 +00:00
var embedColour;
if (current.temperature < 0) {
embedColour = "#addeff";
}else if (current.temperature < 20) {
embedColour = "#4fb8ff";
}else if (current.temperature < 26) {
embedColour = "#ffea4f";
}else if (current.temperature < 31) {
embedColour = "#ffa14f"
} else {
embedColour = "#ff614f"
};
2020-01-25 10:02:43 +00:00
2020-03-26 04:31:32 +00:00
embed = new Discord.MessageEmbed();
embed.setAuthor(`Weather for ${location.name}:`)
embed.setDescription(`• **Condition:** ${current.skytext}\n• **Temperature:** ${current.temperature}°C\n• **Feels like:** ${current.feelslike}°C\n• **Humidity:** ${current.humidity}%\n• **Wind:** ${current.winddisplay}\n• **Warnings:** ${warning}`)
embed.setThumbnail(current.imageUrl)
embed.setFooter(`Last updated at ${current.observationtime} ${current.date}`)
embed.setColor(embedColour)
message.channel.stopTyping();
message.channel.send(embed)
});
} catch(err) {
return message.channel.send(`<:error:466995152976871434> API error: \`${err}\``)
};
2020-01-25 10:02:43 +00:00
};
exports.conf = {
enabled: true,
guildOnly: false,
aliases: [],
permLevel: "User",
requiredPerms: ["EMBED_LINKS"]
};
exports.help = {
name: "weather",
category: "Utility",
description: "Tells you the weather",
usage: "weather [location]"
};