stoat/builders/
send_message.rs1use stoat_models::v0::{
2 DataMessageSend, Interactions, Masquerade, Message, ReplyIntent, SendableEmbed,
3};
4
5use crate::{HttpClient, error::Error};
6
7pub struct SendMessageBuilder {
8 http: HttpClient,
9 channel_id: String,
10 data: DataMessageSend,
11}
12
13impl SendMessageBuilder {
14 pub fn new(http: HttpClient, channel_id: String) -> Self {
15 Self {
16 http,
17 channel_id,
18 data: DataMessageSend {
19 content: None,
20 nonce: None,
21 attachments: None,
22 replies: None,
23 embeds: None,
24 masquerade: None,
25 interactions: None,
26 flags: None,
27 },
28 }
29 }
30
31 pub fn content(&mut self, content: String) -> &mut Self {
32 self.data.content = Some(content);
33
34 self
35 }
36
37 pub fn nonce(&mut self, nonce: String) -> &mut Self {
38 self.data.nonce = Some(nonce);
39
40 self
41 }
42
43 pub fn attachment(&mut self, file_id: String) -> &mut Self {
44 self.data.attachments.get_or_insert_default().push(file_id);
45
46 self
47 }
48
49 pub fn reply(&mut self, message_id: String, mention: bool) -> &mut Self {
50 self.data.replies.get_or_insert_default().push(ReplyIntent {
51 id: message_id,
52 mention,
53 fail_if_not_exists: None,
54 });
55
56 self
57 }
58
59 pub fn embed(&mut self, embed: SendableEmbed) -> &mut Self {
60 self.data.embeds.get_or_insert_default().push(embed);
61
62 self
63 }
64
65 pub fn masquerade(&mut self, masquerade: Masquerade) -> &mut Self {
66 self.data.masquerade = Some(masquerade);
67
68 self
69 }
70
71 pub fn interactions(&mut self, interactions: Interactions) -> &mut Self {
72 self.data.interactions = Some(interactions);
73
74 self
75 }
76
77 pub fn flags(&mut self, flags: u32) -> &mut Self {
78 self.data.flags = Some(flags);
79
80 self
81 }
82
83 pub async fn build(&self) -> Result<Message, Error> {
84 self.http.send_message(&self.channel_id, &self.data).await
85 }
86}