affluence/src/commands/affluence.rs

67 lines
1.8 KiB
Rust
Raw Normal View History

2023-05-12 13:38:55 +02:00
use crate::{Context, Error};
2023-05-15 11:19:07 +02:00
use chrono::NaiveDate;
2023-05-12 15:51:46 +02:00
use uuid::{uuid, Uuid};
const STERRE_BIB_ID: Uuid = uuid!("4737e57a-ee05-4f7b-901a-7bb541eeb297");
2023-05-14 23:38:30 +02:00
const TIME_FORMAT: &str = "%H:%M";
2023-05-12 13:38:55 +02:00
2023-05-12 15:51:46 +02:00
/// List available timeslots for day
#[poise::command(prefix_command, slash_command)]
2023-05-13 10:04:36 +02:00
pub async fn available(ctx: Context<'_>, date: NaiveDate) -> Result<(), Error> {
2023-05-12 15:51:46 +02:00
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 {
2023-05-15 11:19:07 +02:00
let available_hours = resource.condensed_available_hours();
if available_hours.is_empty() {
2023-05-13 10:04:36 +02:00
fields.push((
resource.resource_name.clone(),
"Nothing available.".to_string(),
false,
));
2023-05-12 15:51:46 +02:00
2023-05-13 10:04:36 +02:00
continue;
2023-05-12 15:51:46 +02:00
}
2023-05-15 11:19:07 +02:00
fields.push((
resource.resource_name.clone(),
available_hours
.into_iter()
.map(|(start_block, duration)| {
format!(
2023-05-13 10:04:36 +02:00
"{} - {} ({:02}:{:02})",
2023-05-15 11:19:07 +02:00
start_block.hour.format(TIME_FORMAT),
(start_block.hour + duration).format(TIME_FORMAT),
2023-05-13 10:04:36 +02:00
duration.num_hours(),
duration.num_minutes() % 60
2023-05-15 11:19:07 +02:00
)
})
.collect::<Vec<String>>()
.join("\n"),
false,
));
2023-05-12 15:51:46 +02:00
}
2023-05-13 10:04:36 +02:00
ctx.send(|f| {
f.embed(|e| {
e.description(format!("Available booking dates for {}.", date))
.fields(fields)
})
})
.await?;
2023-05-12 15:51:46 +02:00
Ok(())
}
2023-05-13 10:04:36 +02:00
// Create a reservation
// #[poise::command(prefix_command, slash_command)]
// pub async fn reserve(
// ctx: Context<'_>,
// date: NaiveDate,
// ) -> Result<(), Error> {
2023-05-14 23:38:30 +02:00
2023-05-13 13:08:03 +02:00
// }