zaun_community_protocol/command/object/
component.rs1mod check;
9mod find;
10mod kinds;
11mod serde_impl;
12
13pub use check::{check_message_components, check_modal, component_attachments};
14pub use find::{find_interactive, modal_inputs};
15pub use kinds::{
16 ActionRow, Button, ButtonStyle, Checkbox, CheckboxGroup, Container, DefaultValue,
17 DefaultValueKind, EntitySelect, FileComponent, FileUpload, Label, MediaGallery, MediaItem,
18 RadioGroup, Section, SelectOption, Separator, StringSelect, TextDisplay, TextInput,
19 TextInputStyle, Thumbnail,
20};
21
22#[derive(Debug, Clone, PartialEq, Eq)]
24pub enum Component {
25 ActionRow(ActionRow),
27 Button(Button),
29 StringSelect(StringSelect),
31 TextInput(TextInput),
33 UserSelect(EntitySelect),
35 RoleSelect(EntitySelect),
37 MentionableSelect(EntitySelect),
39 ChannelSelect(EntitySelect),
41 Section(Section),
43 TextDisplay(TextDisplay),
45 Thumbnail(Thumbnail),
47 MediaGallery(MediaGallery),
49 File(FileComponent),
51 Separator(Separator),
53 Container(Container),
55 Label(Label),
57 FileUpload(FileUpload),
59 RadioGroup(RadioGroup),
61 CheckboxGroup(CheckboxGroup),
63 Checkbox(Checkbox),
65}
66
67impl Component {
68 #[must_use]
70 pub const fn kind(&self) -> u8 {
71 match self {
72 Self::ActionRow(_) => 1,
73 Self::Button(_) => 2,
74 Self::StringSelect(_) => 3,
75 Self::TextInput(_) => 4,
76 Self::UserSelect(_) => 5,
77 Self::RoleSelect(_) => 6,
78 Self::MentionableSelect(_) => 7,
79 Self::ChannelSelect(_) => 8,
80 Self::Section(_) => 9,
81 Self::TextDisplay(_) => 10,
82 Self::Thumbnail(_) => 11,
83 Self::MediaGallery(_) => 12,
84 Self::File(_) => 13,
85 Self::Separator(_) => 14,
86 Self::Container(_) => 17,
87 Self::Label(_) => 18,
88 Self::FileUpload(_) => 19,
89 Self::RadioGroup(_) => 21,
90 Self::CheckboxGroup(_) => 22,
91 Self::Checkbox(_) => 23,
92 }
93 }
94
95 #[must_use]
97 pub fn custom_id(&self) -> Option<&str> {
98 match self {
99 Self::Button(b) => b.custom_id.as_deref(),
100 Self::StringSelect(s) => Some(&s.custom_id),
101 Self::TextInput(t) => Some(&t.custom_id),
102 Self::UserSelect(s)
103 | Self::RoleSelect(s)
104 | Self::MentionableSelect(s)
105 | Self::ChannelSelect(s) => Some(&s.custom_id),
106 Self::FileUpload(f) => Some(&f.custom_id),
107 Self::RadioGroup(r) => Some(&r.custom_id),
108 Self::CheckboxGroup(c) => Some(&c.custom_id),
109 Self::Checkbox(c) => Some(&c.custom_id),
110 _ => None,
111 }
112 }
113
114 #[must_use]
117 pub fn children(&self) -> Vec<&Self> {
118 match self {
119 Self::ActionRow(r) => r.components.iter().collect(),
120 Self::Container(c) => c.components.iter().collect(),
121 Self::Section(s) => s
122 .components
123 .iter()
124 .chain(std::iter::once(s.accessory.as_ref()))
125 .collect(),
126 Self::Label(l) => vec![l.component.as_ref()],
127 _ => Vec::new(),
128 }
129 }
130}