serenity/builder/
create_forum_post.rs1#[cfg(feature = "http")]
2use super::Builder;
3use super::CreateMessage;
4#[cfg(feature = "http")]
5use crate::http::CacheHttp;
6#[cfg(feature = "http")]
7use crate::internal::prelude::*;
8use crate::model::prelude::*;
9
10#[derive(Clone, Debug, Serialize)]
12#[must_use]
13pub struct CreateForumPost<'a> {
14 name: String,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 auto_archive_duration: Option<AutoArchiveDuration>,
17 #[serde(skip_serializing_if = "Option::is_none")]
18 rate_limit_per_user: Option<u16>,
19 message: CreateMessage,
20 #[serde(skip_serializing_if = "Vec::is_empty")]
21 applied_tags: Vec<ForumTagId>,
22
23 #[serde(skip)]
24 audit_log_reason: Option<&'a str>,
25}
26
27impl<'a> CreateForumPost<'a> {
28 pub fn new(name: impl Into<String>, message: CreateMessage) -> Self {
30 Self {
31 name: name.into(),
32 message,
33 auto_archive_duration: None,
34 rate_limit_per_user: None,
35 applied_tags: Vec::new(),
36 audit_log_reason: None,
37 }
38 }
39
40 pub fn name(mut self, name: impl Into<String>) -> Self {
44 self.name = name.into();
45 self
46 }
47
48 pub fn message(mut self, message: CreateMessage) -> Self {
52 self.message = message;
53 self
54 }
55
56 pub fn auto_archive_duration(mut self, duration: AutoArchiveDuration) -> Self {
58 self.auto_archive_duration = Some(duration);
59 self
60 }
61
62 #[doc(alias = "slowmode")]
72 pub fn rate_limit_per_user(mut self, seconds: u16) -> Self {
73 self.rate_limit_per_user = Some(seconds);
74 self
75 }
76
77 pub fn add_applied_tag(mut self, applied_tag: ForumTagId) -> Self {
78 self.applied_tags.push(applied_tag);
79 self
80 }
81
82 pub fn set_applied_tags(
83 mut self,
84 applied_tags: impl IntoIterator<Item = impl Into<ForumTagId>>,
85 ) -> Self {
86 self.applied_tags = applied_tags.into_iter().map(Into::into).collect();
87 self
88 }
89
90 pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
92 self.audit_log_reason = Some(reason);
93 self
94 }
95}
96
97#[cfg(feature = "http")]
98#[async_trait::async_trait]
99impl Builder for CreateForumPost<'_> {
100 type Context<'ctx> = ChannelId;
101 type Built = GuildChannel;
102
103 async fn execute(
109 mut self,
110 cache_http: impl CacheHttp,
111 ctx: Self::Context<'_>,
112 ) -> Result<Self::Built> {
113 let files = self.message.attachments.take_files();
114 cache_http
115 .http()
116 .create_forum_post_with_attachments(ctx, &self, files, self.audit_log_reason)
117 .await
118 }
119}