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