Compare commits
No commits in common. "7467b1f588643962ee45dc91b8ebcf4df9c309af" and "1eef50c9991055612637064c16766584058aed53" have entirely different histories.
7467b1f588
...
1eef50c999
|
|
@ -26,10 +26,3 @@ diesel = { version = "2.0.4", features = ["sqlite", "returning_clauses_for_sqlit
|
||||||
diesel_migrations = { version = "2.0.0", features = [ "sqlite" ] }
|
diesel_migrations = { version = "2.0.0", features = [ "sqlite" ] }
|
||||||
# Force sqlite3 to be bundled, allowing for a fully static binary
|
# Force sqlite3 to be bundled, allowing for a fully static binary
|
||||||
libsqlite3-sys = { version = "*", features = ["bundled"] }
|
libsqlite3-sys = { version = "*", features = ["bundled"] }
|
||||||
|
|
||||||
# https://stackoverflow.com/a/54842093
|
|
||||||
[profile.release]
|
|
||||||
lto = true # Enable link-time optimization
|
|
||||||
codegen-units = 1 # Reduce number of codegen units to increase optimizations
|
|
||||||
panic = 'abort' # Abort on panic
|
|
||||||
strip = true # Strip symbols from binary*
|
|
||||||
|
|
|
||||||
|
|
@ -48,22 +48,25 @@ fn resource_to_embed_field(resource: Resource) -> EmbedField {
|
||||||
#[poise::command(prefix_command, slash_command)]
|
#[poise::command(prefix_command, slash_command)]
|
||||||
pub async fn available(ctx: Context<'_>, date: HumanNaiveDate) -> Result<(), Error> {
|
pub async fn available(ctx: Context<'_>, date: HumanNaiveDate) -> Result<(), Error> {
|
||||||
let client = &ctx.data().client;
|
let client = &ctx.data().client;
|
||||||
let date: NaiveDate = date.into();
|
let mut resources = client
|
||||||
|
.available(STERRE_BIB_ID, date.clone().into(), 1)
|
||||||
let mut resources = client.available(STERRE_BIB_ID, date, 1).await?;
|
.await?;
|
||||||
// Cloning here isn't super efficient, but this list only consists of a handful of elements so
|
// Cloning here isn't super efficient, but this list only consists of a handful of elements so
|
||||||
// it's fine
|
// it's fine
|
||||||
resources.sort_by_key(|k| k.resource_name.clone());
|
resources.sort_by_key(|k| k.resource_name.clone());
|
||||||
|
|
||||||
ctx.send(|f| {
|
ctx.send(|f| {
|
||||||
f.embed(|e| {
|
f.embed(|e| {
|
||||||
e.description(format!("Available booking dates for {}.", date))
|
e.description(format!(
|
||||||
.fields(
|
"Available booking dates for {}.",
|
||||||
resources
|
Into::<NaiveDate>::into(date)
|
||||||
.into_iter()
|
))
|
||||||
.map(resource_to_embed_field)
|
.fields(
|
||||||
.collect::<Vec<EmbedField>>(),
|
resources
|
||||||
)
|
.into_iter()
|
||||||
|
.map(resource_to_embed_field)
|
||||||
|
.collect::<Vec<EmbedField>>(),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
@ -88,7 +91,6 @@ pub async fn book(
|
||||||
|
|
||||||
let guild_id = ctx.guild_id().unwrap();
|
let guild_id = ctx.guild_id().unwrap();
|
||||||
let discord_id = ctx.author().id.0 as i64;
|
let discord_id = ctx.author().id.0 as i64;
|
||||||
let date: NaiveDate = date.into();
|
|
||||||
|
|
||||||
let user = {
|
let user = {
|
||||||
let mut conn = ctx.data().pool.get()?;
|
let mut conn = ctx.data().pool.get()?;
|
||||||
|
|
@ -105,7 +107,9 @@ pub async fn book(
|
||||||
let user = user.unwrap();
|
let user = user.unwrap();
|
||||||
|
|
||||||
let client = &ctx.data().client;
|
let client = &ctx.data().client;
|
||||||
let resources = client.available(STERRE_BIB_ID, date, 1).await?;
|
let resources = client
|
||||||
|
.available(STERRE_BIB_ID, date.clone().into(), 1)
|
||||||
|
.await?;
|
||||||
let chosen_resource = resources
|
let chosen_resource = resources
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|r| capacity.is_none() || capacity.unwrap() <= r.capacity)
|
.filter(|r| capacity.is_none() || capacity.unwrap() <= r.capacity)
|
||||||
|
|
@ -115,7 +119,7 @@ pub async fn book(
|
||||||
let reservation = Reservation {
|
let reservation = Reservation {
|
||||||
auth_type: None,
|
auth_type: None,
|
||||||
email: user.email.clone(),
|
email: user.email.clone(),
|
||||||
date,
|
date: date.clone().into(),
|
||||||
start_time,
|
start_time,
|
||||||
end_time,
|
end_time,
|
||||||
note: "coworking space".to_string(),
|
note: "coworking space".to_string(),
|
||||||
|
|
@ -132,7 +136,7 @@ pub async fn book(
|
||||||
ctx.send(|f| {
|
ctx.send(|f| {
|
||||||
f.embed(|e| {
|
f.embed(|e| {
|
||||||
e.description("A new reservation has been made.")
|
e.description("A new reservation has been made.")
|
||||||
.field("when", format!("{} {} - {}", date, start_time.format(TIME_FORMAT), end_time.format(TIME_FORMAT)), false)
|
.field("when", format!("{} {} - {}", Into::<NaiveDate>::into(date), start_time.format(TIME_FORMAT), end_time.format(TIME_FORMAT)), false)
|
||||||
.field("where", &chosen_resource.resource_name, false)
|
.field("where", &chosen_resource.resource_name, false)
|
||||||
.footer(|ft| ft.text(
|
.footer(|ft| ft.text(
|
||||||
format!("A confirmation mail has been sent to {}. Please check your email and confirm your reservation within two hours.", user.email)))
|
format!("A confirmation mail has been sent to {}. Please check your email and confirm your reservation within two hours.", user.email)))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue