Skip to content

Commit

Permalink
feat(cache, model): add max_stage_video_channel_users
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
suneettipirneni authored and Gelbpunkt committed Sep 9, 2024
1 parent 956ad94 commit 1afb26a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions twilight-cache-inmemory/src/event/guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 8 additions & 0 deletions twilight-cache-inmemory/src/model/guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub struct CachedGuild {
pub(crate) large: bool,
pub(crate) max_members: Option<u64>,
pub(crate) max_presences: Option<u64>,
pub(crate) max_stage_video_channel_users: Option<u64>,
pub(crate) max_video_channel_users: Option<u64>,
pub(crate) member_count: Option<u64>,
pub(crate) mfa_level: MfaLevel,
Expand Down Expand Up @@ -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<u64> {
self.max_stage_video_channel_users
}

/// Maximum number of users in a video channel.
pub const fn max_video_channel_users(&self) -> Option<u64> {
self.max_video_channel_users
Expand Down Expand Up @@ -306,6 +312,7 @@ impl From<Guild> for CachedGuild {
large,
max_members,
max_presences,
max_stage_video_channel_users,
max_video_channel_users,
member_count,
mfa_level,
Expand Down Expand Up @@ -349,6 +356,7 @@ impl From<Guild> for CachedGuild {
large,
max_members,
max_presences,
max_stage_video_channel_users,
max_video_channel_users,
member_count,
mfa_level,
Expand Down
1 change: 1 addition & 0 deletions twilight-cache-inmemory/src/permission.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions twilight-cache-inmemory/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ pub fn guild(id: Id<GuildMarker>, member_count: Option<u64>) -> 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(),
Expand Down
21 changes: 21 additions & 0 deletions twilight-model/src/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ pub struct Guild {
pub max_members: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_presences: Option<u64>,
/// Maximum number of users in a stage video channel.
#[serde(skip_serializing_if = "Option::is_none")]
pub max_stage_video_channel_users: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_video_channel_users: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -187,6 +190,7 @@ impl<'de> Deserialize<'de> for Guild {
Large,
MaxMembers,
MaxPresences,
MaxStageVideoChannelUsers,
MaxVideoChannelUsers,
MemberCount,
Members,
Expand Down Expand Up @@ -250,6 +254,7 @@ impl<'de> Deserialize<'de> for Guild {
let mut large = None;
let mut max_members = None::<Option<_>>;
let mut max_presences = None::<Option<_>>;
let mut max_stage_video_channel_users = None::<Option<_>>;
let mut max_video_channel_users = None::<Option<_>>;
let mut member_count = None::<Option<_>>;
let mut members = None;
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 1afb26a

Please sign in to comment.