86 lines
2.4 KiB
Rust
86 lines
2.4 KiB
Rust
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";
|
|
|
|
/// Show this help menu
|
|
#[poise::command(prefix_command, track_edits, slash_command)]
|
|
pub async fn help(
|
|
ctx: Context<'_>,
|
|
#[description = "Specific command to show help about"]
|
|
#[autocomplete = "poise::builtins::autocomplete_command"]
|
|
command: Option<String>,
|
|
) -> Result<(), Error> {
|
|
poise::builtins::help(
|
|
ctx,
|
|
command.as_deref(),
|
|
poise::builtins::HelpConfiguration {
|
|
extra_text_at_bottom: "This is an example bot made to showcase features of my custom Discord bot framework",
|
|
..Default::default()
|
|
},
|
|
)
|
|
.await?;
|
|
Ok(())
|
|
}
|
|
|
|
/// 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::<Vec<String>>()
|
|
.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> {
|
|
|
|
// }
|