remove unnecessary promise

This commit is contained in:
Sebastian Korotkiewicz 2022-03-26 16:53:24 +01:00
parent 53c0532e15
commit bb0b9c93df
Signed by: grizzly
GPG Key ID: 5BDC557B496BDB0D
2 changed files with 20 additions and 24 deletions

View File

@ -5,32 +5,29 @@ const Weather = (event) => {
let reqCity = event.message.match(/,w ([A-Za-z0-9 ]+)/);
// let city = event.message.split(" ");
let city = encodeURIComponent(reqCity[1].trim());
// check if user posted a city TODO
return new Promise((resolve, reject) => {
axios({
method: "get",
url: `https://wttr.in/${city}?format=j1`,
}).then((r) => {
let weatherDesc = r.data.current_condition[0].weatherDesc[0].value;
let humidity = r.data.current_condition[0].humidity;
let tempC = r.data.current_condition[0].temp_C;
let tempF = r.data.current_condition[0].temp_F;
let windspeedKmph = r.data.current_condition[0].windspeedKmph;
let windspeedMiles = r.data.current_condition[0].windspeedMiles;
let areaName = r.data.nearest_area[0].areaName[0].value;
let country = r.data.nearest_area[0].country[0].value;
let region = r.data.nearest_area[0].region[0].value;
axios({
method: "get",
url: `https://wttr.in/${city}?format=j1`,
}).then((r) => {
let weatherDesc = r.data.current_condition[0].weatherDesc[0].value;
let humidity = r.data.current_condition[0].humidity;
let tempC = r.data.current_condition[0].temp_C;
let tempF = r.data.current_condition[0].temp_F;
let windspeedKmph = r.data.current_condition[0].windspeedKmph;
let windspeedMiles = r.data.current_condition[0].windspeedMiles;
let areaName = r.data.nearest_area[0].areaName[0].value;
let country = r.data.nearest_area[0].country[0].value;
let region = r.data.nearest_area[0].region[0].value;
let output = `${Color("Weather")} (${
event.nick
}) ${areaName}, ${region}, ${country} | ${tempC}C/${tempF}F/${
Number(tempC) + 273.15
}K | ${weatherDesc} | Humidity: ${humidity}% | Wind: ${windspeedKmph}km/h/${windspeedMiles}mi/h`;
let output = `${Color("Weather")} (${
event.nick
}) ${areaName}, ${region}, ${country} | ${tempC}C/${tempF}F/${
Number(tempC) + 273.15
}K | ${weatherDesc} | Humidity: ${humidity}% | Wind: ${windspeedKmph}km/h/${windspeedMiles}mi/h`;
resolve(output);
});
event.reply(output);
});
};

View File

@ -36,8 +36,7 @@ bot.on("close", () => {
});
bot.matchMessage(/^,w /, async (event) => {
const data = await Weather(event);
event.reply(data);
return Weather(event);
});
bot.matchMessage(/^,help/, (event) => {