1use crate::types::{Embed, EmbedAuthor, EmbedField, EmbedFooter, Id};
4
5#[derive(Debug, Clone)]
7pub struct EmbedBuilder(Embed);
8
9impl Default for EmbedBuilder {
10 fn default() -> Self {
11 Self(Embed {
12 title: None,
13 description: None,
14 url: None,
15 color: None,
16 timestamp: None,
17 author: None,
18 footer: None,
19 image: None,
20 thumbnail: None,
21 fields: Vec::new(),
22 })
23 }
24}
25
26impl EmbedBuilder {
27 #[must_use]
29 pub fn new() -> Self {
30 Self::default()
31 }
32
33 #[must_use]
35 pub fn title(mut self, t: impl Into<String>) -> Self {
36 self.0.title = Some(t.into());
37 self
38 }
39
40 #[must_use]
42 pub fn description(mut self, d: impl Into<String>) -> Self {
43 self.0.description = Some(d.into());
44 self
45 }
46
47 #[must_use]
49 pub fn url(mut self, url: impl Into<String>) -> Self {
50 self.0.url = Some(url.into());
51 self
52 }
53
54 #[must_use]
56 pub fn color(mut self, rgb: u32) -> Self {
57 self.0.color = Some(rgb);
58 self
59 }
60
61 #[must_use]
63 pub fn timestamp(mut self, ms: u64) -> Self {
64 self.0.timestamp = Some(ms);
65 self
66 }
67
68 #[must_use]
70 pub fn author(mut self, name: impl Into<String>) -> Self {
71 self.0.author = Some(EmbedAuthor {
72 name: name.into(),
73 url: None,
74 icon: None,
75 });
76 self
77 }
78
79 #[must_use]
81 pub fn footer(mut self, text: impl Into<String>) -> Self {
82 self.0.footer = Some(EmbedFooter {
83 text: text.into(),
84 icon: None,
85 });
86 self
87 }
88
89 #[must_use]
91 pub fn image(mut self, attachment: impl Into<Id>) -> Self {
92 self.0.image = Some(attachment.into());
93 self
94 }
95
96 #[must_use]
98 pub fn thumbnail(mut self, attachment: impl Into<Id>) -> Self {
99 self.0.thumbnail = Some(attachment.into());
100 self
101 }
102
103 #[must_use]
105 pub fn field(
106 mut self,
107 name: impl Into<String>,
108 value: impl Into<String>,
109 inline: bool,
110 ) -> Self {
111 let field = EmbedField {
112 name: name.into(),
113 value: value.into(),
114 inline,
115 };
116 self.0.fields.push(field);
117 self
118 }
119
120 #[must_use]
122 pub fn build(self) -> Embed {
123 self.0
124 }
125}
126
127impl From<EmbedBuilder> for Embed {
128 fn from(b: EmbedBuilder) -> Self {
129 b.build()
130 }
131}