Use autocomplete to ensure content box is shown

This commit is contained in:
jude 2022-09-11 15:24:02 +01:00
parent f20b95a482
commit 8991198fd3

View File

@ -11,7 +11,7 @@ use poise::{
serenity_prelude::{ serenity_prelude::{
builder::CreateEmbed, component::ButtonStyle, model::channel::Channel, ReactionType, builder::CreateEmbed, component::ButtonStyle, model::channel::Channel, ReactionType,
}, },
CreateReply, Modal, AutocompleteChoice, CreateReply, Modal,
}; };
use crate::{ use crate::{
@ -549,6 +549,20 @@ pub async fn delete_timer(
Ok(()) Ok(())
} }
async fn multiline_autocomplete(
_ctx: Context<'_>,
partial: &str,
) -> Vec<AutocompleteChoice<String>> {
if partial.is_empty() {
vec![AutocompleteChoice { name: "Multiline content...".to_string(), value: "".to_string() }]
} else {
vec![
AutocompleteChoice { name: partial.to_string(), value: partial.to_string() },
AutocompleteChoice { name: "Multiline content...".to_string(), value: "".to_string() },
]
}
}
#[derive(poise::Modal)] #[derive(poise::Modal)]
#[name = "Reminder"] #[name = "Reminder"]
struct ContentModal { struct ContentModal {
@ -568,7 +582,9 @@ struct ContentModal {
pub async fn remind( pub async fn remind(
ctx: ApplicationContext<'_>, ctx: ApplicationContext<'_>,
#[description = "A description of the time to set the reminder for"] time: String, #[description = "A description of the time to set the reminder for"] time: String,
#[description = "The message content to send"] content: Option<String>, #[description = "The message content to send"]
#[autocomplete = "multiline_autocomplete"]
content: String,
#[description = "Channel or user mentions to set the reminder for"] channels: Option<String>, #[description = "Channel or user mentions to set the reminder for"] channels: Option<String>,
#[description = "(Patreon only) Time to wait before repeating the reminder. Leave blank for one-shot reminder"] #[description = "(Patreon only) Time to wait before repeating the reminder. Leave blank for one-shot reminder"]
interval: Option<String>, interval: Option<String>,
@ -577,21 +593,7 @@ pub async fn remind(
#[description = "Set the TTS flag on the reminder message, similar to the /tts command"] #[description = "Set the TTS flag on the reminder message, similar to the /tts command"]
tts: Option<bool>, tts: Option<bool>,
) -> Result<(), Error> { ) -> Result<(), Error> {
match content { if content.is_empty() {
Some(content) => {
create_reminder(
Context::Application(ctx),
time,
content,
channels,
interval,
expires,
tts,
)
.await
}
None => {
let data = ContentModal::execute(ctx).await?; let data = ContentModal::execute(ctx).await?;
create_reminder( create_reminder(
@ -604,7 +606,9 @@ pub async fn remind(
tts, tts,
) )
.await .await
} } else {
create_reminder(Context::Application(ctx), time, content, channels, interval, expires, tts)
.await
} }
} }