use crate::{Context, Error}; use chrono::NaiveDate; use uuid::{uuid, Uuid}; const STERRE_BIB_ID: Uuid = uuid!("4737e57a-ee05-4f7b-901a-7bb541eeb297"); const TIME_FORMAT: &str = "%H:%M"; /// List available timeslots for day #[poise::command(prefix_command, slash_command)] pub async fn available(ctx: Context<'_>, date: NaiveDate) -> Result<(), Error> { let client = &ctx.data().client; let resources = client.available(STERRE_BIB_ID, date, 1).await?; let mut fields: Vec<(String, String, bool)> = Default::default(); for resource in &resources { let available_hours = resource.condensed_available_hours(); if available_hours.is_empty() { fields.push(( resource.resource_name.clone(), "Nothing available.".to_string(), false, )); continue; } fields.push(( resource.resource_name.clone(), available_hours .into_iter() .map(|(start_block, duration)| { format!( "{} - {} ({:02}:{:02})", start_block.hour.format(TIME_FORMAT), (start_block.hour + duration).format(TIME_FORMAT), duration.num_hours(), duration.num_minutes() % 60 ) }) .collect::>() .join("\n"), false, )); } ctx.send(|f| { f.embed(|e| { e.description(format!("Available booking dates for {}.", date)) .fields(fields) }) }) .await?; Ok(()) } // Create a reservation // #[poise::command(prefix_command, slash_command)] // pub async fn reserve( // ctx: Context<'_>, // date: NaiveDate, // ) -> Result<(), Error> { // }