Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cache, model): add max_stage_video_channel_users #2152

Merged
merged 2 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 22 additions & 1 deletion 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 @@ -912,7 +930,7 @@ mod tests {
&[
Token::Struct {
name: "Guild",
len: 47,
len: 48,
},
Token::Str("afk_channel_id"),
Token::Some,
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