diff --git a/src/commands/autocomplete.rs b/src/commands/autocomplete.rs new file mode 100644 index 0000000..75be35f --- /dev/null +++ b/src/commands/autocomplete.rs @@ -0,0 +1,35 @@ +use chrono_tz::TZ_VARIANTS; + +use crate::Context; + +pub async fn timezone_autocomplete(ctx: Context<'_>, partial: &str) -> Vec { + if partial.is_empty() { + ctx.data().popular_timezones.iter().map(|t| t.to_string()).collect::>() + } else { + TZ_VARIANTS + .iter() + .filter(|tz| tz.to_string().contains(&partial)) + .take(25) + .map(|t| t.to_string()) + .collect::>() + } +} + +pub async fn macro_name_autocomplete(ctx: Context<'_>, partial: &str) -> Vec { + sqlx::query!( + " +SELECT name +FROM macro +WHERE + guild_id = (SELECT id FROM guilds WHERE guild = ?) + AND name LIKE CONCAT(?, '%')", + ctx.guild_id().unwrap().0, + partial, + ) + .fetch_all(&ctx.data().database) + .await + .unwrap_or_default() + .iter() + .map(|s| s.name.clone()) + .collect() +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index e53c6f3..f66c86f 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,3 +1,4 @@ +mod autocomplete; pub mod info_cmds; pub mod moderation_cmds; pub mod reminder_cmds; diff --git a/src/commands/moderation_cmds.rs b/src/commands/moderation_cmds.rs index e65ee9a..4c902b9 100644 --- a/src/commands/moderation_cmds.rs +++ b/src/commands/moderation_cmds.rs @@ -8,6 +8,7 @@ use poise::{serenity_prelude::command::CommandOptionType, CreateReply}; use regex::Captures; use serde_json::{json, Value}; +use super::autocomplete::{macro_name_autocomplete, timezone_autocomplete}; use crate::{ component_models::pager::{MacroPager, Pager}, consts::{EMBED_DESCRIPTION_MAX_LENGTH, THEME_COLOR}, @@ -18,19 +19,6 @@ use crate::{ Context, Data, Error, GuildId, }; -async fn timezone_autocomplete(ctx: Context<'_>, partial: &str) -> Vec { - if partial.is_empty() { - ctx.data().popular_timezones.iter().map(|t| t.to_string()).collect::>() - } else { - TZ_VARIANTS - .iter() - .filter(|tz| tz.to_string().contains(&partial)) - .take(25) - .map(|t| t.to_string()) - .collect::>() - } -} - /// Select your timezone #[poise::command(slash_command, identifying_name = "timezone")] pub async fn timezone( @@ -206,25 +194,6 @@ Do not share it! Ok(()) } -async fn macro_name_autocomplete(ctx: Context<'_>, partial: &str) -> Vec { - sqlx::query!( - " -SELECT name -FROM macro -WHERE - guild_id = (SELECT id FROM guilds WHERE guild = ?) - AND name LIKE CONCAT(?, '%')", - ctx.guild_id().unwrap().0, - partial, - ) - .fetch_all(&ctx.data().database) - .await - .unwrap_or_default() - .iter() - .map(|s| s.name.clone()) - .collect() -} - /// Record and replay command sequences #[poise::command( slash_command, diff --git a/src/commands/reminder_cmds.rs b/src/commands/reminder_cmds.rs index a626e91..bc83fb7 100644 --- a/src/commands/reminder_cmds.rs +++ b/src/commands/reminder_cmds.rs @@ -14,6 +14,7 @@ use poise::{ AutocompleteChoice, CreateReply, Modal, }; +use super::autocomplete::timezone_autocomplete; use crate::{ component_models::{ pager::{DelPager, LookPager, Pager}, @@ -592,7 +593,12 @@ pub async fn remind( expires: Option, #[description = "Set the TTS flag on the reminder message, similar to the /tts command"] tts: Option, + #[description = "Set a timezone override for this reminder only"] + #[autocomplete = "timezone_autocomplete"] + timezone: Option, ) -> Result<(), Error> { + let tz = timezone.map(|t| t.parse::().ok()).flatten(); + if content.is_empty() { let data = ContentModal::execute(ctx).await?; @@ -604,11 +610,21 @@ pub async fn remind( interval, expires, tts, + tz, ) .await } else { - create_reminder(Context::Application(ctx), time, content, channels, interval, expires, tts) - .await + create_reminder( + Context::Application(ctx), + time, + content, + channels, + interval, + expires, + tts, + tz, + ) + .await } } @@ -620,6 +636,7 @@ async fn create_reminder( interval: Option, expires: Option, tts: Option, + timezone: Option, ) -> Result<(), Error> { if interval.is_none() && expires.is_some() { ctx.say("`expires` can only be used with `interval`").await?; @@ -630,7 +647,7 @@ async fn create_reminder( ctx.defer().await?; let user_data = ctx.author_data().await.unwrap(); - let timezone = ctx.timezone().await; + let timezone = timezone.unwrap_or(ctx.timezone().await); let time = natural_parser(&time, &timezone.to_string()).await;