From efd5bc30682b4630f176eb33a3d5353046b3b5e3 Mon Sep 17 00:00:00 2001 From: keiveulbugs <114590495+keiveulbugs@users.noreply.github.com> Date: Wed, 17 Jul 2024 22:47:57 +0200 Subject: [PATCH 1/3] Added examples to the modals documentation Copied and slightly altered the examples from the git. Added these to the documentation as I believe it is a quality of life improvement for people that want to develop modals. --- src/modal.rs | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/src/modal.rs b/src/modal.rs index 0ad4c78ac4a5..bd2ed431bdd8 100644 --- a/src/modal.rs +++ b/src/modal.rs @@ -88,6 +88,33 @@ async fn execute_modal_generic< /// /// If you need more specialized behavior, you can copy paste the implementation of this function /// and adjust to your needs. The code of this function is just a starting point. +/// +/// ```rust +/// # use poise::serenity_prelude as serenity; +/// # type Data = (); +/// # type Error = serenity::Error; +/// use poise::Modal; +/// type ApplicationContext<'a> = poise::ApplicationContext<'a, Data, Error>; +/// +/// #[derive(Debug, Modal)] +/// #[name = "Modal title"] // Struct name by default +/// struct MyModal { +/// #[name = "First input label"] // Field name by default +/// #[placeholder = "Your first input goes here"] // No placeholder by default +/// #[min_length = 5] // No length restriction by default (so, 1-4000 chars) +/// #[max_length = 500] +/// first_input: String, +/// } +/// +///#[poise::command(slash_command)] +///pub async fn modal(ctx: poise::ApplicationContext<'_, Data, Error>) -> Result<(), Error> { +/// use poise::Modal as _; +/// +/// let data = MyModal::execute(ctx).await?; +/// println!("Got data: {:?}", data); +/// +/// Ok(()) +///} pub async fn execute_modal( ctx: crate::ApplicationContext<'_, U, E>, defaults: Option, @@ -119,6 +146,56 @@ pub async fn execute_modal( /// /// If you need more specialized behavior, you can copy paste the implementation of this function /// and adjust to your needs. The code of this function is just a starting point. +/// +/// # Example +/// +/// ```rust +/// # use poise::serenity_prelude as serenity; +/// # type Data = (); +/// # type Error = serenity::Error; +/// use poise::Modal; +/// type ApplicationContext<'a> = poise::ApplicationContext<'a, Data, Error>; +/// +/// #[derive(Debug, Modal)] +/// #[name = "Modal title"] // Struct name by default +/// struct MyModal { +/// #[name = "First input label"] // Field name by default +/// #[placeholder = "Your first input goes here"] // No placeholder by default +/// #[min_length = 5] // No length restriction by default (so, 1-4000 chars) +/// #[max_length = 500] +/// first_input: String, +/// } +/// +/// +///#[poise::command(prefix_command, slash_command)] +///pub async fn component_modal(ctx: crate::Context<'_>) -> Result<(), Error> { +/// // Get a component interaction through a button interaction +/// let reply = { +/// let components = vec![serenity::CreateActionRow::Buttons(vec![ +/// serenity::CreateButton::new("open_modal") +/// .label("Open modal") +/// .style(poise::serenity_prelude::ButtonStyle::Success), +/// ])]; +/// +/// poise::CreateReply::default() +/// .content("Click the button below to open the modal") +/// .components(components) +/// }; +/// +/// ctx.send(reply).await?; +/// +/// while let Some(mci) = serenity::ComponentInteractionCollector::new(ctx.serenity_context()) +/// .timeout(std::time::Duration::from_secs(120)) +/// .filter(move |mci| mci.data.custom_id == "open_modal") +/// .await +/// { +/// // Use the interaction to send a modal with a custom placeholder +/// let data = +/// poise::execute_modal_on_component_interaction::(ctx, mci, MyModal {first_input : "Updated placeholder".to_string()}, None).await?; +/// println!("Got data: {:?}", data); +/// } +/// Ok(()) +///} pub async fn execute_modal_on_component_interaction( ctx: impl AsRef, interaction: serenity::ComponentInteraction, From 603691a6982be19a991667ade3fdd2217cd72e1a Mon Sep 17 00:00:00 2001 From: keiveulbugs <114590495+keiveulbugs@users.noreply.github.com> Date: Wed, 17 Jul 2024 22:53:53 +0200 Subject: [PATCH 2/3] Forgot the Some() --- src/modal.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modal.rs b/src/modal.rs index bd2ed431bdd8..6c5c22bcc927 100644 --- a/src/modal.rs +++ b/src/modal.rs @@ -191,7 +191,7 @@ pub async fn execute_modal( /// { /// // Use the interaction to send a modal with a custom placeholder /// let data = -/// poise::execute_modal_on_component_interaction::(ctx, mci, MyModal {first_input : "Updated placeholder".to_string()}, None).await?; +/// poise::execute_modal_on_component_interaction::(ctx, mci, Some(MyModal {first_input : "Updated placeholder".to_string()}), None).await?; /// println!("Got data: {:?}", data); /// } /// Ok(()) From f6b6022468a1817eb88fb8e79a342ba5fd77b172 Mon Sep 17 00:00:00 2001 From: jamesbt365 Date: Wed, 20 Nov 2024 23:18:05 +0000 Subject: [PATCH 3/3] Re-run CI