Add cron parser for start time of a reminder
This commit is contained in:
@@ -3,6 +3,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use chrono_tz::TZ_VARIANTS;
|
||||
use poise::serenity_prelude::AutocompleteChoice;
|
||||
|
||||
use crate::time_parser::cron_next_timestamp;
|
||||
use crate::{models::CtxData, time_parser::natural_parser, Context};
|
||||
|
||||
pub async fn timezone_autocomplete(ctx: Context<'_>, partial: &str) -> Vec<String> {
|
||||
@@ -42,7 +43,13 @@ pub async fn time_hint_autocomplete(ctx: Context<'_>, partial: &str) -> Vec<Auto
|
||||
if partial.is_empty() {
|
||||
vec![AutocompleteChoice::new("Start typing a time...".to_string(), "now".to_string())]
|
||||
} else {
|
||||
match natural_parser(partial, &ctx.timezone().await.to_string()).await {
|
||||
let timezone = ctx.timezone().await;
|
||||
let timestamp = match cron_next_timestamp(partial, timezone) {
|
||||
Some(ts) => Some(ts),
|
||||
None => natural_parser(partial, &timezone.to_string()).await,
|
||||
};
|
||||
|
||||
match timestamp {
|
||||
Some(timestamp) => match SystemTime::now().duration_since(UNIX_EPOCH) {
|
||||
Ok(now) => {
|
||||
let diff = timestamp - now.as_secs() as i64;
|
||||
|
Reference in New Issue
Block a user