From 1afb26aed8285808a135bc9919fa2aa684e524cb Mon Sep 17 00:00:00 2001 From: suneettipirneni Date: Wed, 15 Feb 2023 15:57:20 -0500 Subject: [PATCH] feat(cache, model): add max_stage_video_channel_users Add support for the guild field `max_stage_video_channel_users`, which functions similarly to related fields such as `max_video_channel_users`. This has been added on the `Guild` model type and the `CachedGuild` inmemory cache type. --- twilight-cache-inmemory/src/event/guild.rs | 1 + twilight-cache-inmemory/src/model/guild.rs | 8 ++++++++ twilight-cache-inmemory/src/permission.rs | 1 + twilight-cache-inmemory/src/test.rs | 1 + twilight-model/src/guild/mod.rs | 21 +++++++++++++++++++++ 5 files changed, 32 insertions(+) diff --git a/twilight-cache-inmemory/src/event/guild.rs b/twilight-cache-inmemory/src/event/guild.rs index 88a281b19f1..280d6d999a8 100644 --- a/twilight-cache-inmemory/src/event/guild.rs +++ b/twilight-cache-inmemory/src/event/guild.rs @@ -310,6 +310,7 @@ mod tests { large: false, max_members: Some(50), max_presences: Some(100), + max_stage_video_channel_users: Some(10), max_video_channel_users: None, member_count: Some(25), members: Vec::new(), diff --git a/twilight-cache-inmemory/src/model/guild.rs b/twilight-cache-inmemory/src/model/guild.rs index 3592d79e6e7..db86f81f7ff 100644 --- a/twilight-cache-inmemory/src/model/guild.rs +++ b/twilight-cache-inmemory/src/model/guild.rs @@ -38,6 +38,7 @@ pub struct CachedGuild { pub(crate) large: bool, pub(crate) max_members: Option, pub(crate) max_presences: Option, + pub(crate) max_stage_video_channel_users: Option, pub(crate) max_video_channel_users: Option, pub(crate) member_count: Option, pub(crate) mfa_level: MfaLevel, @@ -160,6 +161,11 @@ impl CachedGuild { self.max_presences } + /// Maximum number of users in a stage video channel. + pub const fn max_stage_video_channel_users(&self) -> Option { + self.max_stage_video_channel_users + } + /// Maximum number of users in a video channel. pub const fn max_video_channel_users(&self) -> Option { self.max_video_channel_users @@ -306,6 +312,7 @@ impl From for CachedGuild { large, max_members, max_presences, + max_stage_video_channel_users, max_video_channel_users, member_count, mfa_level, @@ -349,6 +356,7 @@ impl From for CachedGuild { large, max_members, max_presences, + max_stage_video_channel_users, max_video_channel_users, member_count, mfa_level, diff --git a/twilight-cache-inmemory/src/permission.rs b/twilight-cache-inmemory/src/permission.rs index e0733ff80bd..311751fc82c 100644 --- a/twilight-cache-inmemory/src/permission.rs +++ b/twilight-cache-inmemory/src/permission.rs @@ -732,6 +732,7 @@ mod tests { large: false, max_members: None, max_presences: None, + max_stage_video_channel_users: None, member_count: None, members: Vec::new(), mfa_level: MfaLevel::Elevated, diff --git a/twilight-cache-inmemory/src/test.rs b/twilight-cache-inmemory/src/test.rs index 7dd41cc27f2..c853e9c4bf6 100644 --- a/twilight-cache-inmemory/src/test.rs +++ b/twilight-cache-inmemory/src/test.rs @@ -410,6 +410,7 @@ pub fn guild(id: Id, member_count: Option) -> Guild { large: false, max_members: None, max_presences: None, + max_stage_video_channel_users: None, max_video_channel_users: None, member_count, members: Vec::new(), diff --git a/twilight-model/src/guild/mod.rs b/twilight-model/src/guild/mod.rs index 6f36264837b..7cd4e94b4ed 100644 --- a/twilight-model/src/guild/mod.rs +++ b/twilight-model/src/guild/mod.rs @@ -109,6 +109,9 @@ pub struct Guild { pub max_members: Option, #[serde(skip_serializing_if = "Option::is_none")] pub max_presences: Option, + /// Maximum number of users in a stage video channel. + #[serde(skip_serializing_if = "Option::is_none")] + pub max_stage_video_channel_users: Option, #[serde(skip_serializing_if = "Option::is_none")] pub max_video_channel_users: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -187,6 +190,7 @@ impl<'de> Deserialize<'de> for Guild { Large, MaxMembers, MaxPresences, + MaxStageVideoChannelUsers, MaxVideoChannelUsers, MemberCount, Members, @@ -250,6 +254,7 @@ impl<'de> Deserialize<'de> for Guild { let mut large = None; let mut max_members = None::>; let mut max_presences = None::>; + let mut max_stage_video_channel_users = None::>; let mut max_video_channel_users = None::>; let mut member_count = None::>; let mut members = None; @@ -435,6 +440,15 @@ impl<'de> Deserialize<'de> for Guild { max_presences = Some(map.next_value()?); } + Field::MaxStageVideoChannelUsers => { + if max_stage_video_channel_users.is_some() { + return Err(DeError::duplicate_field( + "max_stage_video_channel_users", + )); + } + + max_stage_video_channel_users = Some(map.next_value()?); + } Field::MaxVideoChannelUsers => { if max_video_channel_users.is_some() { return Err(DeError::duplicate_field("max_video_channel_users")); @@ -688,6 +702,8 @@ impl<'de> Deserialize<'de> for Guild { let joined_at = joined_at.unwrap_or_default(); let max_members = max_members.unwrap_or_default(); let max_presences = max_presences.unwrap_or_default(); + let max_stage_video_channel_users = + max_stage_video_channel_users.unwrap_or_default(); let max_video_channel_users = max_video_channel_users.unwrap_or_default(); let member_count = member_count.unwrap_or_default(); let members = members.unwrap_or_default(); @@ -748,6 +764,7 @@ impl<'de> Deserialize<'de> for Guild { large, max_members, max_presences, + max_stage_video_channel_users, max_video_channel_users, member_count, members, @@ -875,6 +892,7 @@ mod tests { large: true, max_members: Some(25_000), max_presences: Some(10_000), + max_stage_video_channel_users: Some(10), max_video_channel_users: Some(10), member_count: Some(12_000), members: Vec::new(), @@ -971,6 +989,9 @@ mod tests { Token::Str("max_presences"), Token::Some, Token::U64(10_000), + Token::Str("max_stage_video_channel_users"), + Token::Some, + Token::U64(10), Token::Str("max_video_channel_users"), Token::Some, Token::U64(10),