Paginated weather forecasting

This commit is contained in:
Xyon 2023-08-29 17:05:57 +01:00
parent f58193ddf7
commit 61bd91560a
Signed by: xyon
GPG Key ID: DD18155D6B18078D
2 changed files with 5 additions and 3 deletions

View File

@ -1,4 +1,4 @@
use chrono::{Timelike, Utc};
use chrono::{NaiveDateTime, Timelike};
use poise::serenity_prelude::utils::Colour;
use d20::roll_range;
use poise::ReplyHandle;
@ -47,7 +47,9 @@ async fn weather(ctx: ManifoldContext<'_>, #[rest] #[description="Location to lo
});
}
paginate(ctx, my_message, pages, (Utc::now().hour() + 1) as usize).await?;
let now = NaiveDateTime::parse_from_str(weather_forecast.current.last_updated.as_str(), "%Y-%m-%d %H:%M").unwrap_or(NaiveDateTime::default());
paginate(ctx, my_message, pages, (now.hour() + 1) as usize).await?;
Ok(())
}

View File

@ -26,7 +26,7 @@ pub async fn paginate(ctx: ManifoldContext<'_>, message: ReplyHandle<'_>, pages:
// button was pressed
.filter(move |press| press.data.custom_id.starts_with(&ctx_id.to_string()))
// Timeout when no navigation button has been pressed for 24 hours
.timeout(std::time::Duration::from_secs(3600 * 24))
.timeout(std::time::Duration::from_secs(300))
.await
{
// Depending on which button was pressed, go to next or previous page