Add weather command

This commit is contained in:
SileNce5k 2023-12-03 21:12:21 +01:00
parent 0853f97e99
commit b0188483ac
No known key found for this signature in database
GPG key ID: C507260E7F2583AD
2 changed files with 57 additions and 0 deletions

27
commands/misc/weather.js Normal file
View file

@ -0,0 +1,27 @@
const getWeather = require('../../util/getWeather')
module.exports = {
name: "weather",
description: "Returns what the weather is for the specified location",
async execute({message, args}) {
if(args.length < 1){
message.channel.send(`You have to provide a location`)
return;
}
let location = args.join()
let weather = await getWeather(location).catch((err) => {
console.log(err);
});
// convert °C to °F and add it after C temperature in parentheses
let tempRegex = /(-?\d+)(?=°C)/g;
if(weather.success){
let tempInCelsius = weather.weather.match(tempRegex)[0];
let tempInFahrenheit = `(${Math.round(tempInCelsius * 1.8 + 32)}°F)`;
let splitWeather = weather.weather.split("°C");
weather.weather = `${splitWeather[0]}°C ${tempInFahrenheit} ${splitWeather[1]}`
}
message.channel.send(weather.weather);
}
}