Always fetch tomorrow's weather, today, to avoid having no forecast close to midnight

This commit is contained in:
Xyon 2023-08-29 17:10:48 +01:00
parent 61bd91560a
commit 4f9171d96a
Signed by: xyon
GPG Key ID: DD18155D6B18078D
1 changed files with 5 additions and 5 deletions

View File

@ -14,7 +14,7 @@ use crate::helpers::paginate;
async fn weather(ctx: ManifoldContext<'_>, #[rest] #[description="Location to look up weather for"] location: Option<String>) -> ManifoldResult<()> { async fn weather(ctx: ManifoldContext<'_>, #[rest] #[description="Location to look up weather for"] location: Option<String>) -> ManifoldResult<()> {
let my_message = ctx.say("Retrieving weather, be patient").await?; let my_message = ctx.say("Retrieving weather, be patient").await?;
let weather_forecast = _get_weather(ctx, &my_message, location, Some(1)).await?; let weather_forecast = _get_weather(ctx, &my_message, location, Some(2)).await?;
let responses = &ctx.data().responses; let responses = &ctx.data().responses;
@ -22,8 +22,8 @@ async fn weather(ctx: ManifoldContext<'_>, #[rest] #[description="Location to lo
let card_colour = Colour::from_rgb(roll_range(0, 255).unwrap_or(0) as u8, roll_range(0, 255).unwrap_or(0) as u8, roll_range(0, 255).unwrap_or(0) as u8); let card_colour = Colour::from_rgb(roll_range(0, 255).unwrap_or(0) as u8, roll_range(0, 255).unwrap_or(0) as u8, roll_range(0, 255).unwrap_or(0) as u8);
if let Some(f) = weather_forecast.forecast.forecastday.first() { weather_forecast.forecast.forecastday.iter().for_each(|d| {
f.hour.iter().for_each(|f| { d.hour.iter().for_each(|f| {
pages.push(CreateEmbed::default() pages.push(CreateEmbed::default()
.colour(card_colour) .colour(card_colour)
.title(format!("Current weather at {}, {}, {}", weather_forecast.location.name, weather_forecast.location.region, weather_forecast.location.country)) .title(format!("Current weather at {}, {}, {}", weather_forecast.location.name, weather_forecast.location.region, weather_forecast.location.country))
@ -44,8 +44,8 @@ async fn weather(ctx: ManifoldContext<'_>, #[rest] #[description="Location to lo
f.text(format!("{}", responses.get_response(&"weather card footer".to_string()).unwrap_or(&"Weather Powered By Deez Nutz".to_string()))); f.text(format!("{}", responses.get_response(&"weather card footer".to_string()).unwrap_or(&"Weather Powered By Deez Nutz".to_string())));
f f
}).to_owned()); }).to_owned());
})
}); });
}
let now = NaiveDateTime::parse_from_str(weather_forecast.current.last_updated.as_str(), "%Y-%m-%d %H:%M").unwrap_or(NaiveDateTime::default()); let now = NaiveDateTime::parse_from_str(weather_forecast.current.last_updated.as_str(), "%Y-%m-%d %H:%M").unwrap_or(NaiveDateTime::default());