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
//! [Voice](https://docs.discord.com/developers/resources/voice): users' voice connection states
//! and the available voice regions.
use compact_str::CompactString;
use serde::{Deserialize, Serialize};
use crate::{
guild::Member,
id::{ChannelId, GuildId, UserId},
util::Timestamp,
};
/// A user's [voice state](https://docs.discord.com/developers/resources/voice#voice-state-object):
/// which voice channel they are in and whether they are muted, deafened, streaming, ….
///
/// Received in `GUILD_CREATE` (without `guild_id` and `member`), `VOICE_STATE_UPDATE` and from
/// the voice state endpoints. Absent booleans are `false` (C-023; the docs' example omits
/// `self_video`).
///
/// discord.js counterpart: `VoiceState`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct VoiceState {
/// The guild (absent in `GUILD_CREATE`, where the guild is known).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub guild_id: Option<GuildId>,
/// The connected channel (`None` once the user left).
pub channel_id: Option<ChannelId>,
/// The user.
pub user_id: UserId,
/// The user's member object (absent in `GUILD_CREATE`).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub member: Option<Box<Member>>,
/// The voice session's ID.
pub session_id: CompactString,
/// Whether the server deafened the user.
#[serde(default)]
pub deaf: bool,
/// Whether the server muted the user.
#[serde(default)]
pub mute: bool,
/// Whether the user deafened themselves.
#[serde(default)]
pub self_deaf: bool,
/// Whether the user muted themselves.
#[serde(default)]
pub self_mute: bool,
/// Whether the user is streaming with "Go Live".
#[serde(default, skip_serializing_if = "core::ops::Not::not")]
pub self_stream: bool,
/// Whether the user's camera is on.
#[serde(default)]
pub self_video: bool,
/// Whether the user's permission to speak is denied (stage audience members).
#[serde(default)]
pub suppress: bool,
/// When the user asked to speak in a stage.
pub request_to_speak_timestamp: Option<Timestamp>,
}
/// A [voice region](https://docs.discord.com/developers/resources/voice#voice-region-object):
/// a value for a voice channel's `rtc_region`.
///
/// discord.js counterpart: `VoiceRegion`.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub struct VoiceRegion {
/// The region's ID (the `rtc_region` value).
pub id: CompactString,
/// The region's name.
pub name: CompactString,
/// Whether this is the closest region to the current user's client.
pub optimal: bool,
/// Whether the region is deprecated (avoid switching to it).
pub deprecated: bool,
/// Whether this is a custom region (used for events).
pub custom: bool,
}
#[cfg(test)]
mod tests {
use core::mem::size_of;
use super::*;
#[test]
fn sizes() {
assert!(size_of::<VoiceState>() <= 96, "{}", size_of::<VoiceState>());
}
}