zaun_community_protocol/command/object/component/
find.rs1use super::Component;
4
5#[must_use]
9pub fn find_interactive<'a>(components: &'a [Component], custom_id: &str) -> Option<&'a Component> {
10 let mut stack: Vec<&Component> = components.iter().collect();
11 while let Some(c) = stack.pop() {
12 let enabled = match c {
13 Component::Button(b) => !b.disabled && b.custom_id.is_some(),
14 Component::StringSelect(s) => !s.disabled,
15 Component::UserSelect(s)
16 | Component::RoleSelect(s)
17 | Component::MentionableSelect(s)
18 | Component::ChannelSelect(s) => !s.disabled,
19 _ => {
20 stack.extend(c.children());
21 continue;
22 }
23 };
24 if enabled && c.custom_id() == Some(custom_id) {
25 return Some(c);
26 }
27 }
28 None
29}
30
31#[must_use]
33pub fn modal_inputs(components: &[Component]) -> Vec<&Component> {
34 components
35 .iter()
36 .filter_map(|c| match c {
37 Component::Label(l) => Some(l.component.as_ref()),
38 _ => None,
39 })
40 .collect()
41}