Skip to content

Commit

Permalink
Implement VOICE_CHANNEL_STATUS_UPDATE
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbt365 committed Oct 16, 2023
1 parent 171e1b7 commit 62fb38e
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/cache/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::model::event::{
ThreadDeleteEvent,
ThreadUpdateEvent,
UserUpdateEvent,
VoiceChannelStatusUpdateEvent,
VoiceStateUpdateEvent,
};
use crate::model::gateway::ShardInfo;
Expand Down Expand Up @@ -624,3 +625,19 @@ impl CacheUpdate for VoiceStateUpdateEvent {
}
}
}

impl CacheUpdate for VoiceChannelStatusUpdateEvent {
type Output = String;

fn update(&mut self, cache: &Cache) -> Option<Self::Output> {
if let Some(mut channel) = cache.channels.get_mut(&self.id) {
let old = channel.status.clone();
channel.status = self.status.clone();
// Discord updates topic but doesn't fire ChannelUpdate.
channel.topic = self.status.clone();
old
} else {
None
}
}
}
12 changes: 12 additions & 0 deletions src/client/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,18 @@ fn update_cache_with_event(ctx: Context, event: Event) -> Option<(FullEvent, Opt
new: event.voice_state,
}
},
Event::VoiceChannelStatusUpdate(mut event) => {
let old = if_cache!(update_cache(&ctx, &mut event));

FullEvent::VoiceChannelStatusUpdate {
ctx,
old,
status: event.status,
id: event.id,
guild_id: event.guild_id,
}
},

Event::WebhookUpdate(event) => FullEvent::WebhookUpdate {
ctx,
guild_id: event.guild_id,
Expand Down
5 changes: 5 additions & 0 deletions src/client/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ event_handler! {
/// [`GatewayIntents::GUILDS`] is enabled) and the new state of the guild's voice channels.
async fn voice_state_update(&self, VoiceStateUpdate { ctx: Context, old: Option<VoiceState>, new: VoiceState });

/// Dispatched when a voice channel's status is updated.
///
/// Provides the status, channel's id and the guild's id.
async fn voice_channel_status_update(&self, VoiceChannelStatusUpdate { ctx: Context, old: Option<String>, status: Option<String>, id: ChannelId, guild_id: GuildId });

/// Dispatched when a guild's webhook is updated.
///
/// Provides the guild's id and the channel's id the webhook belongs in.
Expand Down
4 changes: 4 additions & 0 deletions src/model/channel/guild_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ pub struct GuildChannel {
///
/// **Note**: This is only available in a forum or text channel.
pub default_thread_rate_limit_per_user: Option<u16>,
/// The status of a voice channel.
///
/// **Note**: This is only available in voice channels.
pub status: Option<String>,
/// The default sort order type used to order posts
///
/// **Note**: This is only available in a forum.
Expand Down
13 changes: 13 additions & 0 deletions src/model/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,17 @@ pub struct VoiceStateUpdateEvent {
pub voice_state: VoiceState,
}

/// Requires IDK
///
/// Pending documentation.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct VoiceChannelStatusUpdateEvent {
pub status: Option<String>,
pub id: ChannelId,
pub guild_id: GuildId,
}

/// Requires [`GatewayIntents::GUILD_WEBHOOKS`].
///
/// [Discord docs](https://discord.com/developers/docs/topics/gateway-events#webhooks-update).
Expand Down Expand Up @@ -1149,6 +1160,8 @@ pub enum Event {
VoiceStateUpdate(VoiceStateUpdateEvent),
/// Voice server information is available
VoiceServerUpdate(VoiceServerUpdateEvent),
/// Fired when the status of a Voice Channel changes.
VoiceChannelStatusUpdate(VoiceChannelStatusUpdateEvent),
/// A webhook for a [channel][`GuildChannel`] was updated in a [`Guild`].
WebhookUpdate(WebhookUpdateEvent),
/// An interaction was created.
Expand Down
14 changes: 14 additions & 0 deletions src/model/guild/audit_log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub enum Action {
ScheduledEvent(ScheduledEventAction),
Thread(ThreadAction),
AutoMod(AutoModAction),
VoiceChannelStatus(VoiceChannelStatusAction),
Unknown(u8),
}

Expand All @@ -57,6 +58,7 @@ impl Action {
Self::ScheduledEvent(x) => x as u8,
Self::Thread(x) => x as u8,
Self::AutoMod(x) => x as u8,
Self::VoiceChannelStatus(x) => x as u8,
Self::Unknown(x) => x,
}
}
Expand All @@ -79,6 +81,7 @@ impl Action {
100..=102 => Action::ScheduledEvent(unsafe { transmute(value) }),
110..=112 => Action::Thread(unsafe { transmute(value) }),
140..=145 => Action::AutoMod(unsafe { transmute(value) }),
192..=193 => Action::VoiceChannelStatus(unsafe { transmute(value) }),
_ => Action::Unknown(value),
}
}
Expand Down Expand Up @@ -248,6 +251,15 @@ pub enum AutoModAction {
UserCommunicationDisabled = 145,
}

/// Pending documentation merge.
#[derive(Copy, Clone, Debug)]
#[non_exhaustive]
#[repr(u8)]
pub enum VoiceChannelStatusAction {
StatusUpdate = 192,
StatusDelete = 193,
}

/// [Discord docs](https://discord.com/developers/docs/resources/audit-log#audit-log-object).
#[derive(Debug, Deserialize, Serialize)]
#[non_exhaustive]
Expand Down Expand Up @@ -346,6 +358,8 @@ pub struct Options {
/// Name of the role if type is "role"
#[serde(default)]
pub role_name: Option<String>,
#[serde(default)]
pub status: String,
}

#[cfg(test)]
Expand Down

0 comments on commit 62fb38e

Please sign in to comment.