mutiny_rs/builders/
create_message.rs1use crate::builders::CreateEmbed;
2use crate::http::{Http, HttpError};
3use crate::model::channel::ChannelId;
4use crate::model::message::Message;
5use crate::model::message::Replies;
6use serde::Serialize;
7
8#[derive(Debug, Default, Serialize)]
9pub struct CreateMessage {
10 #[serde(skip_serializing_if = "Option::is_none")]
11 pub content: Option<String>,
12
13 #[serde(skip_serializing_if = "Option::is_none")]
14 pub nonce: Option<String>,
15
16 #[serde(skip_serializing_if = "Vec::is_empty")]
17 pub attachments: Vec<String>,
18
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub replies: Option<Vec<Replies>>,
21
22 #[serde(skip_serializing_if = "Vec::is_empty")]
23 pub embeds: Vec<CreateEmbed>,
24}
25impl CreateMessage {
26 pub fn new() -> Self {
27 Default::default()
28 }
29 pub fn content(mut self, content: impl Into<String>) -> Self {
30 self.content = Some(content.into());
31 self
32 }
33 pub fn nonce(mut self, nonce: Option<String>) -> Self {
34 self.nonce = nonce;
35 self
36 }
37 pub fn attachments(mut self, attachments: Vec<String>) -> Self {
38 self.attachments = attachments;
39 self
40 }
41 pub fn replies(mut self, replies: Replies) -> Self {
45 self.replies = Some(vec![replies]);
46 self
47 }
48 pub fn add_embeds(mut self, embeds: Vec<CreateEmbed>) -> Self {
53 self.embeds.extend(embeds);
54 self
55 }
56
57 pub fn embed(self, embed: CreateEmbed) -> Self {
62 self.embeds(vec![embed])
63 }
64
65 pub fn embeds(mut self, embeds: Vec<CreateEmbed>) -> Self {
70 self.embeds = embeds;
71 self
72 }
73 pub(crate) async fn execute(self, http: &Http, channel_id: &ChannelId) -> Result<Message, HttpError> {
75 let route = format!("/channels/{channel_id}/messages");
76 let response = http.post(&route, &self).await?;
77 Ok(response)
78 }
79}