TravBot-v3/src/commands/fun/weather.ts

39 lines
1.7 KiB
TypeScript
Raw Normal View History

import {Command, NamedCommand} from "../../core";
import {MessageEmbed} from "discord.js";
2021-04-08 11:37:49 +00:00
import {find} from "weather-js";
export default new NamedCommand({
description: "Shows weather info of specified location.",
2021-04-08 11:37:49 +00:00
run: "You need to provide a city.",
any: new Command({
async run({message, channel, guild, author, member, client, args}) {
find(
{
search: args.join(" "),
degreeType: "C"
},
function (error, result) {
if (error) return channel.send(error.toString());
if (result.length === 0) return channel.send("No city found by that name.");
var current = result[0].current;
var location = result[0].location;
const embed = new MessageEmbed()
.setDescription(`**${current.skytext}**`)
.setAuthor(`Weather for ${current.observationpoint}`)
.setThumbnail(current.imageUrl)
.setColor(0x00ae86)
.addField("Timezone", `UTC${location.timezone}`, true)
.addField("Degree Type", "C", true)
.addField("Temperature", `${current.temperature} Degrees`, true)
.addField("Feels like", `${current.feelslike} Degrees`, true)
.addField("Winds", current.winddisplay, true)
.addField("Humidity", `${current.humidity}%`, true);
return channel.send({
embed
});
}
);
}
})
});