1#![allow(
4 clippy::new_ret_no_self,
5 reason = "unit builders named as in the zaun-bot SDK; each `new` is the component itself"
6)]
7
8use zaun_community_protocol::command::object::{
9 Component, Container as Box_, FileComponent, MediaGallery as Gallery, MediaItem,
10 Section as Sec, Separator as Sep, TextDisplay as Text, Thumbnail as Thumb,
11};
12use zaun_community_protocol::ids::AttachmentId;
13
14use super::{ActionRow, Button};
15
16#[derive(Debug, Clone, Copy)]
18pub struct TextDisplay;
19
20impl TextDisplay {
21 #[must_use]
23 pub fn new(content: impl Into<String>) -> Component {
24 Component::TextDisplay(Text {
25 id: None,
26 content: content.into(),
27 })
28 }
29}
30
31#[derive(Debug, Clone, Copy)]
33pub struct Thumbnail;
34
35impl Thumbnail {
36 #[must_use]
38 pub const fn new(media: AttachmentId) -> Component {
39 Component::Thumbnail(Thumb {
40 id: None,
41 media,
42 description: None,
43 spoiler: false,
44 })
45 }
46}
47
48#[derive(Debug, Clone, Copy)]
50pub struct MediaGallery;
51
52impl MediaGallery {
53 #[must_use]
55 pub fn new(media: &[AttachmentId]) -> Component {
56 let items = media
57 .iter()
58 .map(|m| MediaItem {
59 media: *m,
60 description: None,
61 spoiler: false,
62 })
63 .collect();
64 Component::MediaGallery(Gallery { id: None, items })
65 }
66}
67
68#[derive(Debug, Clone, Copy)]
70pub struct File;
71
72impl File {
73 #[must_use]
75 pub const fn new(file: AttachmentId) -> Component {
76 Component::File(FileComponent {
77 id: None,
78 file,
79 spoiler: false,
80 })
81 }
82}
83
84#[derive(Debug, Clone, Copy)]
86pub struct Separator;
87
88impl Separator {
89 #[must_use]
91 pub const fn line() -> Component {
92 Component::Separator(Sep {
93 id: None,
94 divider: None,
95 spacing: None,
96 })
97 }
98}
99
100#[derive(Debug, Clone, Copy)]
102pub struct Section;
103
104impl Section {
105 #[must_use]
107 pub fn with_button(texts: &[&str], button: Button) -> Component {
108 Self::with(texts, button.build())
109 }
110
111 #[must_use]
113 pub fn with(texts: &[&str], accessory: Component) -> Component {
114 let components = texts.iter().map(|t| TextDisplay::new(*t)).collect();
115 Component::Section(Sec {
116 id: None,
117 components,
118 accessory: Box::new(accessory),
119 })
120 }
121}
122
123#[derive(Debug, Clone, Default)]
125pub struct Container {
126 components: Vec<Component>,
127 accent: Option<u32>,
128}
129
130impl Container {
131 #[must_use]
133 pub fn new() -> Self {
134 Self::default()
135 }
136
137 #[must_use]
139 pub const fn accent(mut self, rgb: u32) -> Self {
140 self.accent = Some(rgb);
141 self
142 }
143
144 #[must_use]
146 pub fn text(mut self, content: impl Into<String>) -> Self {
147 self.components.push(TextDisplay::new(content));
148 self
149 }
150
151 #[must_use]
153 pub fn push(mut self, component: Component) -> Self {
154 self.components.push(component);
155 self
156 }
157
158 #[must_use]
160 pub fn row(mut self, row: ActionRow) -> Self {
161 self.components.push(row.build());
162 self
163 }
164
165 #[must_use]
167 pub fn build(self) -> Component {
168 Component::Container(Box_ {
169 id: None,
170 components: self.components,
171 accent_color: self.accent,
172 spoiler: false,
173 })
174 }
175}