refactor: this is so fun
This commit is contained in:
parent
c966529a2b
commit
f8ce315d8e
3 changed files with 41 additions and 38 deletions
|
|
@ -1,32 +1,24 @@
|
|||
use crate::commands::EmbedField;
|
||||
use crate::{Context, Error};
|
||||
|
||||
use affluences_api::Resource;
|
||||
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();
|
||||
fn resource_to_embed_field(resource: Resource) -> EmbedField {
|
||||
let available_hours = resource.condensed_available_hours();
|
||||
|
||||
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((
|
||||
if available_hours.is_empty() {
|
||||
(
|
||||
resource.resource_name.clone(),
|
||||
"Nothing available.".to_string(),
|
||||
false,
|
||||
)
|
||||
} else {
|
||||
(
|
||||
resource.resource_name.clone(),
|
||||
available_hours
|
||||
.into_iter()
|
||||
|
|
@ -42,13 +34,25 @@ pub async fn available(ctx: Context<'_>, date: NaiveDate) -> Result<(), Error> {
|
|||
.collect::<Vec<String>>()
|
||||
.join("\n"),
|
||||
false,
|
||||
));
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// 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?;
|
||||
|
||||
ctx.send(|f| {
|
||||
f.embed(|e| {
|
||||
e.description(format!("Available booking dates for {}.", date))
|
||||
.fields(fields)
|
||||
.fields(
|
||||
resources
|
||||
.into_iter()
|
||||
.map(resource_to_embed_field)
|
||||
.collect::<Vec<EmbedField>>(),
|
||||
)
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ mod minecraft;
|
|||
|
||||
use crate::{Context, Data, Error};
|
||||
|
||||
type EmbedField = (String, String, bool);
|
||||
|
||||
pub fn commands() -> Vec<poise::structs::Command<Data, Error>> {
|
||||
vec![help(), affluence::available(), minecraft::ping_mc()]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue