titanium_model/builder/
member.rs

1use crate::TitanString;
2
3/// Payload for modifying a guild member.
4#[derive(Debug, Clone, serde::Serialize, Default)]
5pub struct ModifyMember<'a> {
6    #[serde(skip_serializing_if = "Option::is_none")]
7    pub nick: Option<TitanString<'a>>,
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub roles: Option<Vec<crate::Snowflake>>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub mute: Option<bool>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub deaf: Option<bool>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub channel_id: Option<crate::Snowflake>, // Move to voice channel
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub communication_disabled_until: Option<TitanString<'a>>, // Timeout
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub flags: Option<u64>,
20}
21
22/// Builder for modifying a `GuildMember`.
23#[derive(Debug, Clone, Default)]
24#[must_use]
25pub struct ModifyMemberBuilder<'a> {
26    params: ModifyMember<'a>,
27}
28
29impl<'a> ModifyMemberBuilder<'a> {
30    /// Create a new `ModifyMemberBuilder`.
31    pub fn new() -> Self {
32        Self::default()
33    }
34
35    /// Set nickname.
36    pub fn nick(mut self, nick: impl Into<TitanString<'a>>) -> Self {
37        self.params.nick = Some(nick.into());
38        self
39    }
40
41    /// Set roles (replaces all roles).
42    pub fn roles(mut self, roles: Vec<crate::Snowflake>) -> Self {
43        self.params.roles = Some(roles);
44        self
45    }
46
47    /// Mute or unmute.
48    pub fn mute(mut self, mute: bool) -> Self {
49        self.params.mute = Some(mute);
50        self
51    }
52
53    /// Deafen or undeafen.
54    pub fn deaf(mut self, deaf: bool) -> Self {
55        self.params.deaf = Some(deaf);
56        self
57    }
58
59    /// Move to voice channel (or disconnect if null, but we use strict type here).
60    pub fn move_to_channel(mut self, channel_id: impl Into<crate::Snowflake>) -> Self {
61        self.params.channel_id = Some(channel_id.into());
62        self
63    }
64
65    /// Timeout user until timestamp (ISO8601).
66    pub fn timeout_until(mut self, timestamp: impl Into<TitanString<'a>>) -> Self {
67        self.params.communication_disabled_until = Some(timestamp.into());
68        self
69    }
70
71    /// Build the `ModifyMember` payload.
72    #[must_use]
73    pub fn build(self) -> ModifyMember<'a> {
74        self.params
75    }
76}