Discard _current_ and use forecast with current page set to now
This commit is contained in:
parent
90be789c6b
commit
f58193ddf7
|
|
@ -1,3 +1,4 @@
|
||||||
|
use chrono::{Timelike, Utc};
|
||||||
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;
|
||||||
|
|
@ -20,28 +21,6 @@ async fn weather(ctx: ManifoldContext<'_>, #[rest] #[description="Location to lo
|
||||||
let mut pages = Vec::<CreateEmbed>::new();
|
let mut pages = Vec::<CreateEmbed>::new();
|
||||||
|
|
||||||
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);
|
||||||
pages.push(CreateEmbed::default()
|
|
||||||
.colour(card_colour)
|
|
||||||
.title(format!("Current weather at {}, {}, {}", weather_forecast.location.name, weather_forecast.location.region, weather_forecast.location.country))
|
|
||||||
.description(format!("Observations recorded at {}.", weather_forecast.current.last_updated))
|
|
||||||
.image(format!("https:{}", weather_forecast.current.condition.icon))
|
|
||||||
.fields(vec![
|
|
||||||
("Temperature (Dewpoint)", format!("{}°C/{}°F ({:.1}°C/{:.1}°F)", weather_forecast.current.temp_c, weather_forecast.current.temp_f, weather_forecast.current.dewpoint_c.unwrap_or(0.0), weather_forecast.current.dewpoint_f.unwrap_or(0.0)), true),
|
|
||||||
("Feels like", format!("{}°C/{}°F", weather_forecast.current.feelslike_c, weather_forecast.current.feelslike_f), true),
|
|
||||||
("Condition", format!("{}", weather_forecast.current.condition.text), true),
|
|
||||||
("Pressure", format!("{}mb/{}in", weather_forecast.current.pressure_mb, weather_forecast.current.pressure_in), true),
|
|
||||||
("Precipitation", format!("{}mm/{}in", weather_forecast.current.precip_mm, weather_forecast.current.precip_in), true),
|
|
||||||
("Humidity", format!("{}%", weather_forecast.current.humidity), true),
|
|
||||||
("Cloud coverage", format!("{}%", weather_forecast.current.cloud), true),
|
|
||||||
("UV index", format!("{}", weather_forecast.current.uv), true),
|
|
||||||
("Coordinates", format!("Lat: {} Lon: {}", weather_forecast.location.lat, weather_forecast.location.lon), true),
|
|
||||||
])
|
|
||||||
.field("Wind", format!("{}mph/{}kph from the {} ({} degrees), gusting to {}mph/{}kph", weather_forecast.current.wind_mph, weather_forecast.current.wind_kph, weather_forecast.current.wind_dir, weather_forecast.current.wind_degree, weather_forecast.current.gust_mph, weather_forecast.current.gust_kph), false)
|
|
||||||
.footer(|f| {
|
|
||||||
f.text(format!("{}", responses.get_response(&"weather card footer".to_string()).unwrap_or(&"Weather Powered By Deez Nutz".to_string())));
|
|
||||||
f
|
|
||||||
}).to_owned()
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Some(f) = weather_forecast.forecast.forecastday.first() {
|
if let Some(f) = weather_forecast.forecast.forecastday.first() {
|
||||||
f.hour.iter().for_each(|f| {
|
f.hour.iter().for_each(|f| {
|
||||||
|
|
@ -68,7 +47,7 @@ async fn weather(ctx: ManifoldContext<'_>, #[rest] #[description="Location to lo
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
paginate(ctx, my_message, pages).await?;
|
paginate(ctx, my_message, pages, (Utc::now().hour() + 1) as usize).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,13 @@ use crate::ManifoldContext;
|
||||||
use poise::{ReplyHandle, serenity_prelude};
|
use poise::{ReplyHandle, serenity_prelude};
|
||||||
use poise::serenity_prelude::CreateEmbed;
|
use poise::serenity_prelude::CreateEmbed;
|
||||||
|
|
||||||
pub async fn paginate(ctx: ManifoldContext<'_>, message: ReplyHandle<'_>, pages: Vec<CreateEmbed>) -> ManifoldResult<()> {
|
pub async fn paginate(ctx: ManifoldContext<'_>, message: ReplyHandle<'_>, pages: Vec<CreateEmbed>, mut current_page: usize) -> ManifoldResult<()> {
|
||||||
// Define some unique identifiers for the navigation buttons
|
// Define some unique identifiers for the navigation buttons
|
||||||
let ctx_id = ctx.id();
|
let ctx_id = ctx.id();
|
||||||
let prev_button_id = format!("{}prev", ctx.id());
|
let prev_button_id = format!("{}prev", ctx.id());
|
||||||
let next_button_id = format!("{}next", ctx.id());
|
let next_button_id = format!("{}next", ctx.id());
|
||||||
|
|
||||||
// Send the embed with the first page as content
|
// Send the embed with the first page as content
|
||||||
let mut current_page = 0;
|
|
||||||
message.edit(ctx, |m| {
|
message.edit(ctx, |m| {
|
||||||
m.embeds = vec![pages[current_page].to_owned()];
|
m.embeds = vec![pages[current_page].to_owned()];
|
||||||
m.components(|b| {
|
m.components(|b| {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue