spectacles_model/guild/
member.rs

1use chrono::{DateTime, FixedOffset};
2
3use crate::{
4    Snowflake,
5    user::User,
6};
7
8/// A User that is part of a guild.
9#[derive(Clone, Debug, Deserialize, Serialize, Default)]
10pub struct GuildMember {
11    /// The guild ID of this guild member. (Guild Member Add)
12    #[serde(default)]
13    pub guild_id: Option<Snowflake>,
14    /// The Discord user of this guild member.
15    pub user: Option<User>,
16    /// The member's nickname, if applicable.
17    #[serde(default, rename = "nick")]
18    pub nickname: Option<String>,
19    /// The date that they joined the server.
20    pub joined_at: Option<DateTime<FixedOffset>>,
21    /// Whether or not the member is muted.
22    #[serde(default)]
23    pub mute: bool,
24    /// Whether or not the member has been deafened.
25    #[serde(default)]
26    pub deaf: bool,
27    /// A collection of roles that this member has.
28    pub roles: Vec<String>,
29}
30
31/// Options for adding a member to a guild.
32#[derive(Clone, Debug, Deserialize, Serialize, Default)]
33pub struct AddMemberOptions {
34    #[serde(skip_serializing_if = "Option::is_none")]
35    access_token: Option<String>,
36    #[serde(skip_serializing_if = "Option::is_none")]
37    nick: Option<String>,
38    #[serde(skip_serializing_if = "Option::is_none")]
39    roles: Option<Vec<Snowflake>>,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    mute: Option<bool>,
42    #[serde(skip_serializing_if = "Option::is_none")]
43    deaf: Option<bool>,
44}
45
46impl AddMemberOptions {
47    /// Sets the access token of the user which you want to add.
48    pub fn access_token(mut self, token: String) -> Self {
49        self.access_token = Some(token);
50        self
51    }
52
53    /// Sets the nickname for the newly created user.
54    pub fn nickname(mut self, name: &str) -> Self {
55        self.nick = Some(name.to_string());
56        self
57    }
58
59    /// Sets the roles that the user should have upon joining the guild.
60    pub fn roles(mut self, rls: Vec<Snowflake>) -> Self {
61        self.roles = Some(rls);
62        self
63    }
64
65    /// Sets the user's muted status when joining the guild.
66    pub fn muted(mut self, mute: bool) -> Self {
67        self.mute = Some(mute);
68        self
69    }
70
71    /// Sets the deaf status of the user when joining the guild.
72    pub fn deaf(mut self, opt: bool) -> Self {
73        self.deaf = Some(opt);
74        self
75    }
76}
77
78/// Options for modifying a guild member.
79#[derive(Clone, Debug, Deserialize, Serialize, Default)]
80pub struct ModifyMemberOptions {
81    #[serde(skip_serializing_if = "Option::is_none")]
82    nick: Option<String>,
83    #[serde(skip_serializing_if = "Option::is_none")]
84    roles: Option<Vec<Snowflake>>,
85    #[serde(skip_serializing_if = "Option::is_none")]
86    mute: Option<bool>,
87    #[serde(skip_serializing_if = "Option::is_none")]
88    deaf: Option<bool>,
89    #[serde(skip_serializing_if = "Option::is_none")]
90    channel_id: Option<Snowflake>,
91}
92
93impl ModifyMemberOptions {
94    /// Sets the new nickname of this user.
95    pub fn nick(mut self, name: &str) -> Self {
96        self.nick = Some(name.to_string());
97        self
98    }
99
100    /// Sets the roles that should be assigned to the user.
101    pub fn roles(mut self, rls: Vec<Snowflake>) -> Self {
102        self.roles = Some(rls);
103        self
104    }
105
106    /// Sets the muted status of this guild member.
107    pub fn muted(mut self, opt: bool) -> Self {
108        self.mute = Some(opt);
109        self
110    }
111
112    /// Sets the deafened status of this guild member.
113    pub fn deaf(mut self, opt: bool) -> Self {
114        self.deaf = Some(opt);
115        self
116    }
117
118    /// Sets the voice channel that this member should be moved to.
119    pub fn channel_id(mut self, id: Snowflake) -> Self {
120        self.channel_id = Some(id);
121        self
122    }
123}
124
125/// Options for requesting a list of guild members from the API.
126#[derive(Clone, Debug, Deserialize, Serialize, Default)]
127pub struct ListMembersOptions {
128    #[serde(skip_serializing_if = "Option::is_none")]
129    limit: Option<i32>,
130    #[serde(skip_serializing_if = "Option::is_none")]
131    after: Option<Snowflake>,
132}
133
134impl ListMembersOptions {
135    /// Sets the maximum amount of members for this request.
136    pub fn limit(mut self, num: i32) -> Self {
137        self.limit = Some(num);
138        self
139    }
140
141    /// Sets the the highest user id in the previous page.
142    pub fn after(mut self, id: Snowflake) -> Self {
143        self.after = Some(id);
144        self
145    }
146}
147
148/// A payload sent by the gateway when a guild member is removed from a guild.
149#[derive(Clone, Debug, Deserialize, Serialize, Default)]
150pub struct GuildMemberRemove {
151    /// The guild ID of the guild that this member belongs to.
152    pub guild_id: Snowflake,
153    /// The Discord User of this guild member.
154    pub user: User,
155}
156
157/// A payload sent by the gateway upon a RequestGuildMembers packet.
158#[derive(Clone, Debug, Deserialize, Serialize, Default)]
159pub struct GuildMembersChunk {
160    /// The guild ID of the guild that the members belong to.
161    pub guild_id: Snowflake,
162    /// The array of guild members.
163    pub members: Vec<GuildMember>
164}