#[cfg(feature = "http")]
use super::Builder;
use super::CreateMessage;
#[cfg(feature = "http")]
use crate::http::CacheHttp;
#[cfg(feature = "http")]
use crate::internal::prelude::*;
use crate::model::prelude::*;
#[derive(Clone, Debug, Serialize)]
#[must_use]
pub struct CreateForumPost<'a> {
name: String,
#[serde(skip_serializing_if = "Option::is_none")]
auto_archive_duration: Option<AutoArchiveDuration>,
#[serde(skip_serializing_if = "Option::is_none")]
rate_limit_per_user: Option<u16>,
message: CreateMessage,
#[serde(skip_serializing_if = "Vec::is_empty")]
applied_tags: Vec<ForumTagId>,
#[serde(skip)]
audit_log_reason: Option<&'a str>,
}
impl<'a> CreateForumPost<'a> {
pub fn new(name: impl Into<String>, message: CreateMessage) -> Self {
Self {
name: name.into(),
message,
auto_archive_duration: None,
rate_limit_per_user: None,
applied_tags: Vec::new(),
audit_log_reason: None,
}
}
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = name.into();
self
}
pub fn message(mut self, message: CreateMessage) -> Self {
self.message = message;
self
}
pub fn auto_archive_duration(mut self, duration: AutoArchiveDuration) -> Self {
self.auto_archive_duration = Some(duration);
self
}
#[doc(alias = "slowmode")]
pub fn rate_limit_per_user(mut self, seconds: u16) -> Self {
self.rate_limit_per_user = Some(seconds);
self
}
pub fn add_applied_tag(mut self, applied_tag: ForumTagId) -> Self {
self.applied_tags.push(applied_tag);
self
}
pub fn set_applied_tags(
mut self,
applied_tags: impl IntoIterator<Item = impl Into<ForumTagId>>,
) -> Self {
self.applied_tags = applied_tags.into_iter().map(Into::into).collect();
self
}
pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
self.audit_log_reason = Some(reason);
self
}
}
#[cfg(feature = "http")]
#[async_trait::async_trait]
impl Builder for CreateForumPost<'_> {
type Context<'ctx> = ChannelId;
type Built = GuildChannel;
async fn execute(
mut self,
cache_http: impl CacheHttp,
ctx: Self::Context<'_>,
) -> Result<Self::Built> {
let files = self.message.attachments.take_files();
cache_http
.http()
.create_forum_post_with_attachments(ctx, &self, files, self.audit_log_reason)
.await
}
}