-
Notifications
You must be signed in to change notification settings - Fork 564
/
member.rs
705 lines (655 loc) · 25 KB
/
member.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
#[cfg(feature = "model")]
use std::borrow::Cow;
#[cfg(feature = "cache")]
use std::cmp::Reverse;
use std::fmt;
#[cfg(feature = "model")]
use crate::builder::EditMember;
#[cfg(feature = "cache")]
use crate::cache::Cache;
#[cfg(feature = "model")]
use crate::http::{CacheHttp, Http};
#[cfg(all(feature = "cache", feature = "model"))]
use crate::internal::prelude::*;
use crate::model::permissions::Permissions;
use crate::model::prelude::*;
use crate::model::Timestamp;
/// Information about a member of a guild.
///
/// [Discord docs](https://discord.com/developers/docs/resources/guild#guild-member-object),
/// [extra fields](https://discord.com/developers/docs/topics/gateway-events#guild-member-add-guild-member-add-extra-fields).
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[non_exhaustive]
pub struct Member {
/// Attached User struct.
pub user: User,
/// The member's nickname, if present.
///
/// Can't be longer than 32 characters.
pub nick: Option<String>,
/// The guild avatar hash
pub avatar: Option<String>,
/// Vector of Ids of [`Role`]s given to the member.
pub roles: Vec<RoleId>,
/// Timestamp representing the date when the member joined.
pub joined_at: Option<Timestamp>,
/// Timestamp representing the date since the member is boosting the guild.
pub premium_since: Option<Timestamp>,
/// Indicator of whether the member can hear in voice channels.
pub deaf: bool,
/// Indicator of whether the member can speak in voice channels.
pub mute: bool,
/// Guild member flags.
pub flags: GuildMemberFlags,
/// Indicator that the member hasn't accepted the rules of the guild yet.
#[serde(default)]
pub pending: bool,
/// The total permissions of the member in a channel, including overrides.
///
/// This is only [`Some`] when returned in an [`Interaction`] object.
///
/// [`Interaction`]: crate::model::application::Interaction
pub permissions: Option<Permissions>,
/// When the user's timeout will expire and the user will be able to communicate in the guild
/// again.
///
/// Will be None or a time in the past if the user is not timed out.
pub communication_disabled_until: Option<Timestamp>,
/// The unique Id of the guild that the member is a part of.
#[serde(default)]
pub guild_id: GuildId,
}
bitflags! {
/// Flags for a guild member.
///
/// [Discord docs](https://discord.com/developers/docs/resources/guild#guild-member-object-guild-member-flags).
#[derive(Default)]
pub struct GuildMemberFlags: u32 {
/// Member has left and rejoined the guild. Not editable
const DID_REJOIN = 1 << 0;
/// Member has completed onboarding. Not editable
const COMPLETED_ONBOARDING = 1 << 1;
/// Member is exempt from guild verification requirements. Editable
const BYPASSES_VERIFICATION = 1 << 2;
/// Member has started onboarding. Not editable
const STARTED_ONBOARDING = 1 << 3;
}
}
#[cfg(feature = "model")]
impl Member {
/// Adds a [`Role`] to the member, editing its roles in-place if the request was successful.
///
/// **Note**: Requires the [Manage Roles] permission.
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission, or if a role with the given
/// Id does not exist.
///
/// [Manage Roles]: Permissions::MANAGE_ROLES
#[inline]
pub async fn add_role(
&mut self,
cache_http: impl CacheHttp,
role_id: impl Into<RoleId>,
) -> Result<()> {
self.add_roles(cache_http, &[role_id.into()]).await
}
/// Adds one or multiple [`Role`]s to the member, editing its roles in-place if the request was
/// successful.
///
/// **Note**: Requires the [Manage Roles] permission.
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission, or if a role with a given Id
/// does not exist.
///
/// [Manage Roles]: Permissions::MANAGE_ROLES
pub async fn add_roles(
&mut self,
cache_http: impl CacheHttp,
role_ids: &[RoleId],
) -> Result<()> {
let mut target_roles = self.roles.clone();
target_roles.extend_from_slice(role_ids);
let builder = EditMember::new().roles(target_roles);
self.edit(cache_http, builder).await
}
/// Ban a [`User`] from the guild, deleting a number of days' worth of messages (`dmd`) between
/// the range 0 and 7.
///
/// **Note**: Requires the [Ban Members] permission.
///
/// # Errors
///
/// Returns a [`ModelError::DeleteMessageDaysAmount`] if the `dmd` is greater than 7. Can also
/// return [`Error::Http`] if the current user lacks permission to ban this member.
///
/// [Ban Members]: Permissions::BAN_MEMBERS
#[inline]
pub async fn ban(&self, http: impl AsRef<Http>, dmd: u8) -> Result<()> {
self.ban_with_reason(http, dmd, "").await
}
/// Ban the member from the guild with a reason. Refer to [`Self::ban`] to further
/// documentation.
///
/// # Errors
///
/// In addition to the errors [`Self::ban`] may return, can also return
/// [`Error::ExceededLimit`] if the length of the reason is greater than 512.
#[inline]
pub async fn ban_with_reason(
&self,
http: impl AsRef<Http>,
dmd: u8,
reason: impl AsRef<str>,
) -> Result<()> {
self.guild_id.ban_with_reason(http, self.user.id, dmd, reason).await
}
/// Determines the member's colour.
#[cfg(feature = "cache")]
pub fn colour(&self, cache: impl AsRef<Cache>) -> Option<Colour> {
let guild = cache.as_ref().guild(self.guild_id)?;
let mut roles = self
.roles
.iter()
.filter_map(|role_id| guild.roles.get(role_id))
.collect::<Vec<&Role>>();
roles.sort_by_key(|&b| Reverse(b));
let default = Colour::default();
roles.iter().find(|r| r.colour.0 != default.0).map(|r| r.colour)
}
/// Returns the "default channel" of the guild for the member. (This returns the first channel
/// that can be read by the member, if there isn't one returns [`None`])
#[cfg(feature = "cache")]
pub fn default_channel(&self, cache: impl AsRef<Cache>) -> Option<GuildChannel> {
let guild = self.guild_id.to_guild_cached(&cache)?;
let member = guild.members.get(&self.user.id)?;
for channel in guild.channels.values() {
if channel.kind != ChannelType::Category
&& guild.user_permissions_in(channel, member).ok()?.view_channel()
{
return Some(channel.clone());
}
}
None
}
/// Times the user out until `time`.
///
/// Requires the [Moderate Members] permission.
///
/// **Note**: [Moderate Members]: crate::model::permission::Permissions::MODERATE_MEMBERS
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission or if `time` is greater than
/// 28 days from the current time.
///
/// [Moderate Members]: Permissions::MODERATE_MEMBERS
#[doc(alias = "timeout")]
pub async fn disable_communication_until_datetime(
&mut self,
cache_http: impl CacheHttp,
time: Timestamp,
) -> Result<()> {
let builder = EditMember::new().disable_communication_until_datetime(time);
match self.guild_id.edit_member(cache_http, self.user.id, builder).await {
Ok(_) => {
self.communication_disabled_until = Some(time);
Ok(())
},
Err(why) => Err(why),
}
}
/// Calculates the member's display name.
///
/// The nickname takes priority over the member's username if it exists.
#[inline]
pub fn display_name(&self) -> Cow<'_, String> {
self.nick.as_ref().map_or_else(|| Cow::Owned(self.user.name.clone()), Cow::Borrowed)
}
/// Returns the DiscordTag of a Member, taking possible nickname into account.
#[inline]
#[must_use]
pub fn distinct(&self) -> String {
if let Some(discriminator) = self.user.discriminator {
format!("{}#{:04}", self.display_name(), discriminator.get())
} else {
self.display_name().to_string()
}
}
/// Edits the member in place with the given data.
///
/// See [`EditMember`] for the permission(s) required for separate builder methods, as well as
/// usage of this.
///
/// # Examples
///
/// See [`GuildId::edit_member`] for details.
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks necessary permissions.
pub async fn edit(
&mut self,
cache_http: impl CacheHttp,
builder: EditMember<'_>,
) -> Result<()> {
*self = self.guild_id.edit_member(cache_http, self.user.id, builder).await?;
Ok(())
}
/// Allow a user to communicate, removing their timeout, if there is one.
///
/// **Note**: Requires the [Moderate Members] permission.
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission.
///
/// [Moderate Members]: Permissions::MODERATE_MEMBERS
#[doc(alias = "timeout")]
pub async fn enable_communication(&mut self, cache_http: impl CacheHttp) -> Result<()> {
let builder = EditMember::new().enable_communication();
*self = self.guild_id.edit_member(cache_http, self.user.id, builder).await?;
Ok(())
}
/// Retrieves the ID and position of the member's highest role in the hierarchy, if they have
/// one.
///
/// This _may_ return [`None`] if:
/// - the user has roles, but they are not present in the cache for cache inconsistency reasons
/// - you already have a write lock to the member's guild
///
/// The "highest role in hierarchy" is defined as the role with the highest position. If two or
/// more roles have the same highest position, then the role with the lowest ID is the highest.
#[cfg(feature = "cache")]
pub fn highest_role_info(&self, cache: impl AsRef<Cache>) -> Option<(RoleId, u32)> {
let guild = cache.as_ref().guild(self.guild_id)?;
let mut highest = None;
for role_id in &self.roles {
if let Some(role) = guild.roles.get(role_id) {
// Skip this role if this role in iteration has:
// - a position less than the recorded highest
// - a position equal to the recorded, but a higher ID
if let Some((id, pos)) = highest {
if role.position < pos || (role.position == pos && role.id > id) {
continue;
}
}
highest = Some((role.id, role.position));
}
}
highest
}
/// Kick the member from the guild.
///
/// **Note**: Requires the [Kick Members] permission.
///
/// # Examples
///
/// Kick a member from its guild:
///
/// ```rust,ignore
/// // assuming a `member` has already been bound
/// match member.kick().await {
/// Ok(()) => println!("Successfully kicked member"),
/// Err(Error::Model(ModelError::GuildNotFound)) => {
/// println!("Couldn't determine guild of member");
/// },
/// Err(Error::Model(ModelError::InvalidPermissions(missing_perms))) => {
/// println!("Didn't have permissions; missing: {:?}", missing_perms);
/// },
/// _ => {},
/// }
/// ```
///
/// # Errors
///
/// Returns a [`ModelError::GuildNotFound`] if the Id of the member's guild could not be
/// determined.
///
/// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
/// does not have permission to perform the kick.
///
/// Otherwise will return [`Error::Http`] if the current user lacks permission.
///
/// [Kick Members]: Permissions::KICK_MEMBERS
#[inline]
pub async fn kick(&self, cache_http: impl CacheHttp) -> Result<()> {
self.kick_with_reason(cache_http, "").await
}
/// Kicks the member from the guild, with a reason.
///
/// **Note**: Requires the [Kick Members] permission.
///
/// # Examples
///
/// Kicks a member from it's guild, with an optional reason:
///
/// ```rust,ignore
/// match member.kick(&ctx.http, "A Reason").await {
/// Ok(()) => println!("Successfully kicked member"),
/// Err(Error::Model(ModelError::GuildNotFound)) => {
/// println!("Couldn't determine guild of member");
/// },
/// Err(Error::Model(ModelError::InvalidPermissions(missing_perms))) => {
/// println!("Didn't have permissions; missing: {:?}", missing_perms);
/// },
/// _ => {},
/// }
/// ```
///
/// # Errors
///
/// In addition to the reasons [`Self::kick`] may return an error, can also return an error if
/// the given reason is too long.
///
/// [Kick Members]: Permissions::KICK_MEMBERS
pub async fn kick_with_reason(&self, cache_http: impl CacheHttp, reason: &str) -> Result<()> {
#[cfg(feature = "cache")]
{
if let Some(cache) = cache_http.cache() {
let lookup = cache.guild(self.guild_id).as_deref().cloned();
if let Some(guild) = lookup {
let req = Permissions::KICK_MEMBERS;
if !guild.has_perms(&cache_http, req).await {
return Err(Error::Model(ModelError::InvalidPermissions(req)));
}
guild.check_hierarchy(cache, self.user.id)?;
}
}
}
self.guild_id.kick_with_reason(cache_http.http(), self.user.id, reason).await
}
/// Moves the member to a voice channel.
///
/// Requires the [Move Members] permission.
///
/// # Errors
///
/// Returns [`Error::Http`] if the member is not currently in a voice channel, or if the
/// current user lacks permission.
///
/// [Move Members]: Permissions::MOVE_MEMBERS
pub async fn move_to_voice_channel(
&self,
cache_http: impl CacheHttp,
channel: impl Into<ChannelId>,
) -> Result<Member> {
self.guild_id.move_member(cache_http, self.user.id, channel).await
}
/// Disconnects the member from their voice channel if any.
///
/// Requires the [Move Members] permission.
///
/// # Errors
///
/// Returns [`Error::Http`] if the member is not currently in a voice channel, or if the
/// current user lacks permission.
///
/// [Move Members]: Permissions::MOVE_MEMBERS
pub async fn disconnect_from_voice(&self, cache_http: impl CacheHttp) -> Result<Member> {
self.guild_id.disconnect_member(cache_http, self.user.id).await
}
/// Returns the guild-level permissions for the member.
///
/// # Examples
///
/// ```rust,ignore
/// // assuming there's a `member` variable gotten from anything.
/// println!("The permission bits for the member are: {}",
/// member.permissions(&cache).expect("permissions").bits());
/// ```
///
/// # Errors
///
/// Returns a [`ModelError::GuildNotFound`] if the guild the member's in could not be
/// found in the cache.
///
/// And/or returns [`ModelError::ItemMissing`] if the "default channel" of the guild is not
/// found.
#[cfg(feature = "cache")]
pub fn permissions(&self, cache: impl AsRef<Cache>) -> Result<Permissions> {
match cache.as_ref().guild(self.guild_id) {
Some(guild) => Ok(guild._member_permission_from_member(self)),
None => Err(From::from(ModelError::GuildNotFound)),
}
}
/// Removes a [`Role`] from the member, editing its roles in-place if the request was
/// successful.
///
/// **Note**: Requires the [Manage Roles] permission.
///
/// # Errors
///
/// Returns [`Error::Http`] if a role with the given Id does not exist, or if the current user
/// lacks permission.
///
/// [Manage Roles]: Permissions::MANAGE_ROLES
pub async fn remove_role(
&mut self,
cache_http: impl CacheHttp,
role_id: impl Into<RoleId>,
) -> Result<()> {
self.remove_roles(cache_http, &[role_id.into()]).await
}
/// Removes one or multiple [`Role`]s from the member, editing its roles in-place if the
/// request was successful.
///
/// **Note**: Requires the [Manage Roles] permission.
///
/// # Errors
///
/// Returns [`Error::Http`] if a role with a given Id does not exist, or if the current user
/// lacks permission.
///
/// [Manage Roles]: Permissions::MANAGE_ROLES
pub async fn remove_roles(
&mut self,
cache_http: impl CacheHttp,
role_ids: &[RoleId],
) -> Result<()> {
let mut target_roles = self.roles.clone();
target_roles.retain(|r| !role_ids.contains(r));
let builder = EditMember::new().roles(target_roles);
self.edit(cache_http, builder).await
}
/// Retrieves the full role data for the user's roles.
///
/// This is shorthand for manually searching through the Cache.
///
/// If role data can not be found for the member, then [`None`] is returned.
#[cfg(feature = "cache")]
pub fn roles(&self, cache: impl AsRef<Cache>) -> Option<Vec<Role>> {
Some(
cache
.as_ref()
.guild(self.guild_id)?
.roles
.iter()
.filter(|(id, _)| self.roles.contains(id))
.map(|(_, role)| role.clone())
.collect(),
)
}
/// Unbans the [`User`] from the guild.
///
/// **Note**: Requires the [Ban Members] permission.
///
/// # Errors
///
/// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
/// does not have permission to perform bans.
///
/// [Ban Members]: Permissions::BAN_MEMBERS
#[inline]
pub async fn unban(&self, http: impl AsRef<Http>) -> Result<()> {
http.as_ref().remove_ban(self.guild_id, self.user.id, None).await
}
/// Returns the formatted URL of the member's per guild avatar, if one exists.
///
/// This will produce a WEBP image URL, or GIF if the member has a GIF avatar.
#[inline]
#[must_use]
pub fn avatar_url(&self) -> Option<String> {
avatar_url(self.guild_id, self.user.id, self.avatar.as_ref())
}
/// Retrieves the URL to the current member's avatar, falling back to the user's avatar, then
/// default avatar if needed.
///
/// This will call [`Self::avatar_url`] first, and if that returns [`None`], it then falls back
/// to [`User::face()`].
#[inline]
#[must_use]
pub fn face(&self) -> String {
self.avatar_url().unwrap_or_else(|| self.user.face())
}
}
impl fmt::Display for Member {
/// Mentions the user so that they receive a notification.
///
/// # Examples
///
/// ```rust,ignore
/// // assumes a `member` has already been bound
/// println!("{} is a member!", member);
/// ```
///
/// This is in the format of `<@USER_ID>`.
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.user.mention(), f)
}
}
/// A partial amount of data for a member.
///
/// This is used in [`Message`]s from [`Guild`]s.
///
/// [Discord docs](https://discord.com/developers/docs/resources/guild#guild-member-object),
/// subset specification unknown (field type "partial member" is used in
/// [link](https://discord.com/developers/docs/topics/gateway-events#message-create),
/// [link](https://discord.com/developers/docs/resources/invite#invite-stage-instance-object),
/// [link](https://discord.com/developers/docs/topics/gateway-events#message-create),
/// [link](https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure),
/// [link](https://discord.com/developers/docs/interactions/receiving-and-responding#message-interaction-object))
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct PartialMember {
/// Indicator of whether the member can hear in voice channels.
#[serde(default)]
pub deaf: bool,
/// Timestamp representing the date when the member joined.
pub joined_at: Option<Timestamp>,
/// Indicator of whether the member can speak in voice channels
#[serde(default)]
pub mute: bool,
/// The member's nickname, if present.
///
/// Can't be longer than 32 characters.
pub nick: Option<String>,
/// Vector of Ids of [`Role`]s given to the member.
pub roles: Vec<RoleId>,
/// Indicator that the member hasn't accepted the rules of the guild yet.
#[serde(default)]
pub pending: bool,
/// Timestamp representing the date since the member is boosting the guild.
pub premium_since: Option<Timestamp>,
/// The unique Id of the guild that the member is a part of.
///
/// Manually inserted in [`Reaction::deserialize`].
pub guild_id: Option<GuildId>,
/// Attached User struct.
pub user: Option<User>,
/// The total permissions of the member in a channel, including overrides.
///
/// This is only [`Some`] when returned in an [`Interaction`] object.
///
/// [`Interaction`]: crate::model::application::Interaction
pub permissions: Option<Permissions>,
}
impl From<PartialMember> for Member {
fn from(partial: PartialMember) -> Self {
Member {
user: partial.user.unwrap_or_default(),
nick: partial.nick,
avatar: None,
roles: partial.roles,
joined_at: partial.joined_at,
premium_since: partial.premium_since,
deaf: partial.deaf,
mute: partial.mute,
flags: GuildMemberFlags::default(),
pending: partial.pending,
permissions: partial.permissions,
communication_disabled_until: None,
guild_id: partial.guild_id.unwrap_or_default(),
}
}
}
impl From<Member> for PartialMember {
fn from(member: Member) -> Self {
PartialMember {
deaf: member.deaf,
joined_at: member.joined_at,
mute: member.mute,
nick: member.nick,
roles: member.roles,
pending: member.pending,
premium_since: member.premium_since,
guild_id: Some(member.guild_id),
user: Some(member.user),
permissions: member.permissions,
}
}
}
#[cfg(feature = "model")]
fn avatar_url(guild_id: GuildId, user_id: UserId, hash: Option<&String>) -> Option<String> {
hash.map(|hash| {
let ext = if hash.starts_with("a_") { "gif" } else { "webp" };
cdn!("/guilds/{}/users/{}/avatars/{}.{}?size=1024", guild_id.0, user_id.0, hash, ext)
})
}
/// [Discord docs](https://discord.com/developers/docs/resources/channel#thread-member-object),
/// [extra fields](https://discord.com/developers/docs/topics/gateway-events#thread-member-update-thread-member-update-event-extra-fields).
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct ThreadMember {
/// The id of the thread.
///
/// This field is omitted on the member sent within each thread in the GUILD_CREATE event.
pub id: Option<ChannelId>,
/// The id of the user.
///
/// This field is omitted on the member sent within each thread in the GUILD_CREATE event.
pub user_id: Option<UserId>,
/// The time the current user last joined the thread.
pub join_timestamp: Timestamp,
/// Any user-thread settings, currently only used for notifications
pub flags: ThreadMemberFlags,
/// Additional information about the user.
///
/// This field is omitted on the member sent within each thread in the GUILD_CREATE event.
///
/// This field is only present when `with_member` is set to `true` when calling
/// List Thread Members or Get Thread Member, or inside [`ThreadMembersUpdateEvent`].
pub member: Option<Member>,
/// ID of the guild.
///
/// Always present in [`ThreadMemberUpdateEvent`], otherwise `None`.
pub guild_id: Option<GuildId>,
// According to https://discord.com/developers/docs/topics/gateway-events#thread-members-update,
// > the thread member objects will also include the guild member and nullable presence objects
// > for each added thread member
// Which implies that ThreadMember has a presence field. But https://discord.com/developers/docs/resources/channel#thread-member-object
// says that's not true. I'm not adding the presence field here for now
}
bitflags! {
/// Describes extra features of the message.
///
/// Discord docs: flags field on [Thread Member](https://discord.com/developers/docs/resources/channel#thread-member-object).
#[derive(Default)]
pub struct ThreadMemberFlags: u64 {
// Not documented.
const NOTIFICATIONS = 1 << 0;
}
}