serenity/builder/
edit_thread.rs

1#[cfg(feature = "http")]
2use super::Builder;
3#[cfg(feature = "http")]
4use crate::http::CacheHttp;
5#[cfg(feature = "http")]
6use crate::internal::prelude::*;
7use crate::model::prelude::*;
8
9/// [Discord docs](https://discord.com/developers/docs/resources/channel#modify-channel-json-params-thread).
10#[derive(Clone, Debug, Default, Serialize)]
11#[must_use]
12pub struct EditThread<'a> {
13    #[serde(skip_serializing_if = "Option::is_none")]
14    name: Option<String>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    archived: Option<bool>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    auto_archive_duration: Option<AutoArchiveDuration>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    locked: Option<bool>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    invitable: Option<bool>,
23    #[serde(skip_serializing_if = "Option::is_none")]
24    rate_limit_per_user: Option<u16>,
25    #[serde(skip_serializing_if = "Option::is_none")]
26    flags: Option<ChannelFlags>,
27    #[serde(skip_serializing_if = "Option::is_none")]
28    applied_tags: Option<Vec<ForumTagId>>,
29
30    #[serde(skip)]
31    audit_log_reason: Option<&'a str>,
32}
33
34impl<'a> EditThread<'a> {
35    /// Equivalent to [`Self::default`].
36    pub fn new() -> Self {
37        Self::default()
38    }
39
40    /// The name of the thread.
41    ///
42    /// **Note**: Must be between 2 and 100 characters long.
43    pub fn name(mut self, name: impl Into<String>) -> Self {
44        self.name = Some(name.into());
45        self
46    }
47
48    /// Duration in minutes to automatically archive the thread after recent activity.
49    pub fn auto_archive_duration(mut self, duration: AutoArchiveDuration) -> Self {
50        self.auto_archive_duration = Some(duration);
51        self
52    }
53
54    /// The archive status of the thread.
55    ///
56    /// **Note**: A thread that is `locked` can only be unarchived if the user has the
57    /// `MANAGE_THREADS` permission.
58    pub fn archived(mut self, archived: bool) -> Self {
59        self.archived = Some(archived);
60        self
61    }
62
63    /// The lock status of the thread.
64    pub fn locked(mut self, lock: bool) -> Self {
65        self.locked = Some(lock);
66        self
67    }
68
69    /// Whether non-moderators can add other non-moderators to a thread.
70    ///
71    /// **Note**: Only available on private threads.
72    pub fn invitable(mut self, invitable: bool) -> Self {
73        self.invitable = Some(invitable);
74        self
75    }
76
77    /// Amount of seconds a user has to wait before sending another message (0-21600); bots, as well
78    /// as users with the permission manage_messages, manage_thread, or manage_channel, are
79    /// unaffected
80    pub fn rate_limit_per_user(mut self, rate_limit_per_user: u16) -> Self {
81        self.rate_limit_per_user = Some(rate_limit_per_user);
82        self
83    }
84
85    /// Channel flags combined as a bitfield; [`ChannelFlags::PINNED`] can only be set for threads
86    /// in forum channels
87    pub fn flags(mut self, flags: ChannelFlags) -> Self {
88        self.flags = Some(flags);
89        self
90    }
91
92    /// If this is a forum post, edits the assigned tags of this forum post.
93    pub fn applied_tags(mut self, applied_tags: impl IntoIterator<Item = ForumTagId>) -> Self {
94        self.applied_tags = Some(applied_tags.into_iter().collect());
95        self
96    }
97
98    /// Sets the request's audit log reason.
99    pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
100        self.audit_log_reason = Some(reason);
101        self
102    }
103}
104
105#[cfg(feature = "http")]
106#[async_trait::async_trait]
107impl Builder for EditThread<'_> {
108    type Context<'ctx> = ChannelId;
109    type Built = GuildChannel;
110
111    /// Edits the thread.
112    ///
113    /// # Errors
114    ///
115    /// Returns [`Error::Http`] if the current user lacks permission.
116    async fn execute(
117        self,
118        cache_http: impl CacheHttp,
119        ctx: Self::Context<'_>,
120    ) -> Result<Self::Built> {
121        cache_http.http().edit_thread(ctx, &self, self.audit_log_reason).await
122    }
123}