40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
const command = {
|
|
name: "weather",
|
|
desc: "get the weather from wttr.in",
|
|
run: async (client, msg, splitted) => {
|
|
if (splitted[2] === undefined) {
|
|
client
|
|
.say(msg.channelName, `${msg.displayName}, supply a location PoroSad`)
|
|
.catch((err) => console.log(err));
|
|
|
|
return;
|
|
}
|
|
|
|
const data = await fetch(
|
|
`https://wttr.in/${splitted[2].replaceAll(/\W/g, "")}?format=j1`
|
|
)
|
|
.then((res) => res.json())
|
|
.then((data) => {
|
|
return data.current_condition[0];
|
|
})
|
|
.catch((err) => console.log(err));
|
|
|
|
if (data === undefined) {
|
|
client
|
|
.say(msg.channelName, `${msg.displayName}, Invalid location PoroSad`)
|
|
.catch((err) => console.log(err));
|
|
|
|
return;
|
|
}
|
|
|
|
await client
|
|
.say(
|
|
msg.channelName,
|
|
`${msg.displayName} Weather for ${splitted[2]} Status: ${data.weatherDesc[0]?.value} Temp: ${data.temp_C}°C Feels like: ${data.FeelsLikeC}°C`
|
|
)
|
|
.catch((err) => console.log(err));
|
|
},
|
|
};
|
|
|
|
module.exports = { command };
|