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