Skip to content

Commit 9a99852

Browse files
committed
fix poise::modal::find_modal_text to support Serenity's new component types
1 parent 17fd1d7 commit 9a99852

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/modal.rs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
//! Modal trait and utility items for implementing it (mainly for the derive macro)
22
33
use crate::serenity_prelude as serenity;
4+
use serenity::all::{Component, LabelComponent};
45

56
/// Meant for use in derived [`Modal::parse`] implementation
67
///
7-
/// _Takes_ the String out of the data. Logs warnings on unexpected state
8+
/// _Takes_ the String out of the first InputText component that has the given `custom_id`.
9+
/// Logs warnings on unexpected state.
810
#[doc(hidden)]
911
pub fn find_modal_text(
1012
data: &mut serenity::ModalInteractionData,
1113
custom_id: &str,
1214
) -> Option<String> {
13-
for row in data.components.iter_mut() {
14-
let text = match row.components.get_mut(0) {
15-
Some(serenity::ActionRowComponent::InputText(text)) => text,
16-
Some(_) => {
15+
for component in data.components.iter_mut() {
16+
// text inputs can either exist in Labels or Containers
17+
match component {
18+
Component::Label(label) => match &mut label.component {
19+
LabelComponent::InputText(input_text) => {
20+
if input_text.custom_id == custom_id {
21+
return match std::mem::take(&mut input_text.value) {
22+
Some(val) if val.is_empty() => None,
23+
Some(val) => Some(val.into_string()),
24+
None => None,
25+
};
26+
}
27+
}
28+
_ => {
29+
tracing::warn!("unexpected non input text component in modal response");
30+
continue;
31+
}
32+
},
33+
_ => {
1734
tracing::warn!("unexpected non input text component in modal response");
1835
continue;
1936
}
20-
None => {
21-
tracing::warn!("empty action row in modal response");
22-
continue;
23-
}
24-
};
25-
26-
if text.custom_id == custom_id {
27-
return match std::mem::take(&mut text.value) {
28-
Some(val) if val.is_empty() => None,
29-
Some(val) => Some(val.into_string()),
30-
None => None,
31-
};
3237
}
3338
}
3439
tracing::warn!(

0 commit comments

Comments
 (0)