1use crate::types::{Component, Embed, Id, MessageBody, MessageFlags};
4use crate::{ActionRow, Container, EmbedBuilder};
5
6#[derive(Debug, Clone)]
8pub struct Reply(pub(crate) MessageBody);
9
10impl Default for Reply {
11 fn default() -> Self {
12 Self(MessageBody {
13 content: None,
14 embeds: Vec::new(),
15 components: Vec::new(),
16 attachments: Vec::new(),
17 mentions: None,
18 flags: MessageFlags::empty(),
19 })
20 }
21}
22
23impl Reply {
24 #[must_use]
26 pub fn new() -> Self {
27 Self::default()
28 }
29
30 #[must_use]
32 pub fn content(mut self, text: impl Into<String>) -> Self {
33 self.0.content = Some(text.into());
34 self
35 }
36
37 #[must_use]
39 pub fn embed(mut self, embed: impl Into<Embed>) -> Self {
40 self.0.embeds.push(embed.into());
41 self
42 }
43
44 #[must_use]
46 pub fn row(mut self, row: ActionRow) -> Self {
47 self.0.components.push(Component::ActionRow(row.build()));
48 self
49 }
50
51 #[must_use]
53 pub fn component(mut self, component: Component) -> Self {
54 self.0.components.push(component);
55 self
56 }
57
58 #[must_use]
60 pub fn container(self, container: Container) -> Self {
61 self.v2().component(Component::Container(container.build()))
62 }
63
64 #[must_use]
66 pub fn v2(mut self) -> Self {
67 self.0.flags |= MessageFlags::COMPONENTS_V2;
68 self
69 }
70
71 #[must_use]
73 pub fn ephemeral(mut self) -> Self {
74 self.0.flags |= MessageFlags::EPHEMERAL;
75 self
76 }
77
78 #[must_use]
80 pub fn silent(mut self) -> Self {
81 self.0.flags |= MessageFlags::SUPPRESS_NOTIFICATIONS;
82 self
83 }
84
85 #[must_use]
87 pub fn attachment(mut self, id: impl Into<Id>) -> Self {
88 self.0.attachments.push(id.into());
89 self
90 }
91
92 #[must_use]
94 pub fn build(self) -> MessageBody {
95 self.0
96 }
97}
98
99impl From<&str> for Reply {
100 fn from(text: &str) -> Self {
101 Self::new().content(text)
102 }
103}
104
105impl From<String> for Reply {
106 fn from(text: String) -> Self {
107 Self::new().content(text)
108 }
109}
110
111impl From<EmbedBuilder> for Reply {
112 fn from(embed: EmbedBuilder) -> Self {
113 Self::new().embed(embed)
114 }
115}