Paginated weather forecasting
This commit is contained in:
parent
f58193ddf7
commit
61bd91560a
|
|
@ -1,4 +1,4 @@
|
||||||
use chrono::{Timelike, Utc};
|
use chrono::{NaiveDateTime, Timelike};
|
||||||
use poise::serenity_prelude::utils::Colour;
|
use poise::serenity_prelude::utils::Colour;
|
||||||
use d20::roll_range;
|
use d20::roll_range;
|
||||||
use poise::ReplyHandle;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ pub async fn paginate(ctx: ManifoldContext<'_>, message: ReplyHandle<'_>, pages:
|
||||||
// button was pressed
|
// button was pressed
|
||||||
.filter(move |press| press.data.custom_id.starts_with(&ctx_id.to_string()))
|
.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 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
|
.await
|
||||||
{
|
{
|
||||||
// Depending on which button was pressed, go to next or previous page
|
// Depending on which button was pressed, go to next or previous page
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue