spectacles_model/message/
embed.rs1use chrono::{DateTime, Utc};
2
3#[derive(Serialize, Deserialize, Clone, Debug, Default)]
5pub struct Embed {
6 #[serde(default, skip_serializing_if = "Option::is_none")]
8 pub title: Option<String>,
9 #[serde(default, rename = "type", skip_serializing_if = "Option::is_none")]
11 pub kind: Option<String>,
12 #[serde(default, skip_serializing_if = "Option::is_none")]
14 pub description: Option<String>,
15 #[serde(default, skip_serializing_if = "Option::is_none")]
17 pub url: Option<String>,
18 #[serde(default, skip_serializing_if = "Option::is_none")]
20 pub timestamp: Option<DateTime<Utc>>,
21 #[serde(default, skip_serializing_if = "Option::is_none")]
23 pub color: Option<i32>,
24 #[serde(default, skip_serializing_if = "Option::is_none")]
26 pub footer: Option<EmbedFooter>,
27 #[serde(default, skip_serializing_if = "Option::is_none")]
29 pub image: Option<EmbedImage>,
30 #[serde(default, skip_serializing_if = "Option::is_none")]
32 pub thumbnail: Option<EmbedThumbnail>,
33 #[serde(default, skip_serializing_if = "Option::is_none")]
35 pub video: Option<EmbedVideo>,
36 #[serde(default)]
38 pub provider: Option<EmbedProvider>,
39 #[serde(default, skip_serializing_if = "Option::is_none")]
41 pub author: Option<EmbedAuthor>,
42 #[serde(default)]
44 pub fields: Vec<EmbedField>
45}
46
47impl Embed {
48 pub fn new() -> Self {
49 Embed::default()
50 }
51
52 pub fn set_title(mut self, text: impl Into<String>) -> Self {
54 self.title = Some(text.into());
55 self
56 }
57
58 pub fn set_description(mut self, text: impl Into<String>) -> Self {
60 self.description = Some(text.into());
61 self
62 }
63
64 pub fn set_color(mut self, code: i32) -> Self {
66 self.color = Some(code);
67 self
68 }
69
70 pub fn add_field<F: FnOnce(EmbedField) -> EmbedField>(mut self, builder: F) -> Self {
72 let new_field = builder(EmbedField::default());
73 self.fields.push(new_field);
74 self
75 }
76
77 pub fn set_author<F>(mut self, author: F) -> Self
79 where F: FnOnce(EmbedAuthor) -> EmbedAuthor
80 {
81 self.author = Some(author(EmbedAuthor::default()));
82 self
83 }
84
85 pub fn set_footer<F>(mut self, footer: F) -> Self
87 where F: FnOnce(EmbedFooter) -> EmbedFooter
88 {
89 self.footer = Some(footer(EmbedFooter::default()));
90 self
91 }
92
93 pub fn set_thumbnail<T>(mut self, thumb: T) -> Self
95 where T: FnOnce(EmbedThumbnail) -> EmbedThumbnail
96 {
97 self.thumbnail = Some(thumb(EmbedThumbnail::default()));
98 self
99 }
100
101 pub fn set_image<F>(mut self, img: F) -> Self
103 where F: FnOnce(EmbedImage) -> EmbedImage
104 {
105 self.image = Some(img(EmbedImage::default()));
106 self
107 }
108
109 pub fn set_current_timestamp(mut self) -> Self {
110 self.timestamp = Some(chrono::Utc::now());
111
112 self
113 }
114
115 pub fn set_timestamp(mut self, time: DateTime<Utc>) -> Self {
116 self.timestamp = Some(time);
117
118 self
119 }
120
121
122}
123#[derive(Serialize, Deserialize, Clone, Debug, Default)]
125pub struct EmbedFooter {
126 pub text: String,
128 #[serde(default)]
130 pub icon_url: String,
131 #[serde(default)]
133 pub proxy_icon_url: String
134
135}
136
137impl EmbedFooter {
138 pub fn set_text(mut self, txt: impl Into<String>) -> Self {
140 self.text = txt.into();
141 self
142 }
143
144 pub fn set_icon_url(mut self, url: impl Into<String>) -> Self {
146 self.icon_url = url.into();
147 self
148 }
149}
150#[derive(Serialize, Deserialize, Clone, Debug, Default)]
152pub struct EmbedImage {
153 #[serde(default)]
155 pub url: Option<String>,
156 #[serde(default)]
158 pub proxy_url: Option<String>,
159 #[serde(default)]
161 pub height: Option<i32>,
162 #[serde(default)]
164 pub width: Option<i32>
165}
166
167impl EmbedImage {
168 pub fn set_url(mut self, url: impl Into<String>) -> Self {
170 self.url = Some(url.into());
171 self
172 }
173}
174
175#[derive(Serialize, Deserialize, Clone, Debug, Default)]
177pub struct EmbedThumbnail {
178 #[serde(default)]
180 pub url: Option<String>,
181 #[serde(default)]
182 pub proxy_url: Option<String>,
184 #[serde(default)]
186 pub height: Option<i32>,
187 #[serde(default)]
189 pub width: Option<i32>
190}
191
192impl EmbedThumbnail {
193 pub fn set_url(mut self, url: impl Into<String>) -> Self {
195 self.url = Some(url.into());
196 self
197 }
198}
199#[derive(Serialize, Deserialize, Clone, Debug, Default)]
201pub struct EmbedVideo {
202 #[serde(default)]
204 pub url: Option<String>,
205 #[serde(default)]
207 pub height: Option<i32>,
208 #[serde(default)]
210 pub width: Option<i32>
211}
212
213#[derive(Serialize, Deserialize, Clone, Debug, Default)]
215pub struct EmbedProvider {
216 #[serde(default)]
218 pub name: Option<String>,
219 #[serde(default)]
221 pub url: Option<String>
222}
223
224#[derive(Serialize, Deserialize, Clone, Debug, Default)]
226pub struct EmbedAuthor {
227 #[serde(default)]
229 pub name: Option<String>,
230 #[serde(default)]
232 pub url: Option<String>,
233 #[serde(default)]
235 pub icon_url: Option<String>,
236 #[serde(default)]
238 pub proxy_icon_url: Option<String>
239}
240
241impl EmbedAuthor {
242 pub fn set_name(mut self, name: impl Into<String>) -> Self {
244 self.name = Some(name.into());
245 self
246 }
247
248 pub fn set_url(mut self, url: impl Into<String>) -> Self {
250 self.url = Some(url.into());
251 self
252 }
253
254 pub fn set_icon_url(mut self, url: impl Into<String>) -> Self {
256 self.icon_url = Some(url.into());
257 self
258 }
259}
260
261#[derive(Serialize, Deserialize, Clone, Debug, Default)]
263pub struct EmbedField {
264 pub name: String,
266 pub value: String,
268 #[serde(default)]
270 pub inline: Option<bool>
271}
272
273impl EmbedField {
274 pub fn set_name(mut self, name: impl Into<String>) -> Self {
276 self.name = name.into();
277 self
278 }
279
280 pub fn set_value(mut self, val: impl Into<String>) -> Self {
281 self.value = val.into();
282 self
283 }
284
285 pub fn set_inline(mut self, inline: bool) -> Self {
287 self.inline = Some(inline);
288
289 self
290 }
291}