wip bump versions

This commit is contained in:
jude
2023-12-22 19:11:39 +00:00
parent e7803b98e8
commit cce0de7c75
9 changed files with 850 additions and 535 deletions

View File

@ -1,7 +1,7 @@
use std::time::{SystemTime, UNIX_EPOCH};
use chrono_tz::TZ_VARIANTS;
use poise::AutocompleteChoice;
use poise::serenity_prelude::AutocompleteChoice;
use crate::{models::CtxData, time_parser::natural_parser, Context};
@ -37,15 +37,9 @@ WHERE
.collect()
}
pub async fn time_hint_autocomplete(
ctx: Context<'_>,
partial: &str,
) -> Vec<AutocompleteChoice<String>> {
pub async fn time_hint_autocomplete(ctx: Context<'_>, partial: &str) -> Vec<AutocompleteChoice> {
if partial.is_empty() {
vec![AutocompleteChoice {
name: "Start typing a time...".to_string(),
value: "now".to_string(),
}]
vec![AutocompleteChoice::new("Start typing a time...".to_string(), "now".to_string())]
} else {
match natural_parser(partial, &ctx.timezone().await.to_string()).await {
Some(timestamp) => match SystemTime::now().duration_since(UNIX_EPOCH) {
@ -53,64 +47,49 @@ pub async fn time_hint_autocomplete(
let diff = timestamp - now.as_secs() as i64;
if diff < 0 {
vec![AutocompleteChoice {
name: "Time is in the past".to_string(),
value: "1 year ago".to_string(),
}]
vec![AutocompleteChoice::new(
"Time is in the past".to_string(),
"1 year ago".to_string(),
)]
} else {
if diff > 86400 {
vec![
AutocompleteChoice {
name: partial.to_string(),
value: partial.to_string(),
},
AutocompleteChoice {
name: format!(
AutocompleteChoice::new(partial.to_string(), partial.to_string()),
AutocompleteChoice::new(
format!(
"In approximately {} days, {} hours",
diff / 86400,
(diff % 86400) / 3600
),
value: partial.to_string(),
},
partial.to_string(),
),
]
} else if diff > 3600 {
vec![
AutocompleteChoice {
name: partial.to_string(),
value: partial.to_string(),
},
AutocompleteChoice {
name: format!("In approximately {} hours", diff / 3600),
value: partial.to_string(),
},
AutocompleteChoice::new(partial.to_string(), partial.to_string()),
AutocompleteChoice::new(
format!("In approximately {} hours", diff / 3600),
partial.to_string(),
),
]
} else {
vec![
AutocompleteChoice {
name: partial.to_string(),
value: partial.to_string(),
},
AutocompleteChoice {
name: format!("In approximately {} minutes", diff / 60),
value: partial.to_string(),
},
AutocompleteChoice::new(partial.to_string(), partial.to_string()),
AutocompleteChoice::new(
format!("In approximately {} minutes", diff / 60),
partial.to_string(),
),
]
}
}
}
Err(_) => {
vec![AutocompleteChoice {
name: partial.to_string(),
value: partial.to_string(),
}]
vec![AutocompleteChoice::new(partial.to_string(), partial.to_string())]
}
},
None => {
vec![AutocompleteChoice {
name: "Time not recognised".to_string(),
value: "now".to_string(),
}]
vec![AutocompleteChoice::new("Time not recognised".to_string(), "now".to_string())]
}
}
}