twilight_model/gateway/payload/outgoing/
update_voice_state.rs

1use crate::{
2    gateway::opcode::OpCode,
3    id::{
4        marker::{ChannelMarker, GuildMarker},
5        Id,
6    },
7};
8use serde::{Deserialize, Serialize};
9
10#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
11pub struct UpdateVoiceState {
12    pub d: UpdateVoiceStateInfo,
13    pub op: OpCode,
14}
15
16impl UpdateVoiceState {
17    pub fn new(
18        guild_id: impl Into<Id<GuildMarker>>,
19        channel_id: impl Into<Option<Id<ChannelMarker>>>,
20        self_deaf: bool,
21        self_mute: bool,
22    ) -> Self {
23        Self {
24            d: UpdateVoiceStateInfo::new(guild_id, channel_id, self_deaf, self_mute),
25            op: OpCode::VoiceStateUpdate,
26        }
27    }
28}
29
30#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
31pub struct UpdateVoiceStateInfo {
32    pub channel_id: Option<Id<ChannelMarker>>,
33    pub guild_id: Id<GuildMarker>,
34    pub self_deaf: bool,
35    pub self_mute: bool,
36}
37
38impl UpdateVoiceStateInfo {
39    pub fn new(
40        guild_id: impl Into<Id<GuildMarker>>,
41        channel_id: impl Into<Option<Id<ChannelMarker>>>,
42        self_deaf: bool,
43        self_mute: bool,
44    ) -> Self {
45        Self::_new(guild_id.into(), channel_id.into(), self_deaf, self_mute)
46    }
47
48    const fn _new(
49        guild_id: Id<GuildMarker>,
50        channel_id: Option<Id<ChannelMarker>>,
51        self_deaf: bool,
52        self_mute: bool,
53    ) -> Self {
54        Self {
55            channel_id,
56            guild_id,
57            self_deaf,
58            self_mute,
59        }
60    }
61}