From 4a1937ea7c0e5b56823a0fb4ebd575b978a7e00a Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> Date: Sun, 9 Jul 2023 16:46:33 -0400 Subject: [PATCH] feat(model, cache): Support new username system (#2231) This adds the new `global_name` field and adjusts discriminator display for migrated users. --- .../src/event/interaction.rs | 3 ++ twilight-cache-inmemory/src/event/message.rs | 1 + .../src/event/voice_state.rs | 1 + twilight-cache-inmemory/src/model/member.rs | 1 + twilight-cache-inmemory/src/model/sticker.rs | 1 + twilight-cache-inmemory/src/test.rs | 4 ++ .../application_command/resolved.rs | 12 ++++- .../src/application/interaction/mod.rs | 12 ++++- .../src/channel/message/interaction.rs | 6 ++- twilight-model/src/channel/message/mod.rs | 12 ++++- .../src/channel/message/sticker/mod.rs | 6 ++- twilight-model/src/channel/webhook/mod.rs | 6 ++- twilight-model/src/gateway/event/mod.rs | 2 +- .../gateway/payload/incoming/member_add.rs | 1 + .../gateway/payload/incoming/member_chunk.rs | 8 +++ .../gateway/payload/incoming/member_update.rs | 6 ++- .../payload/incoming/thread_members_update.rs | 6 ++- .../gateway/payload/incoming/typing_start.rs | 6 ++- .../payload/incoming/voice_state_update.rs | 12 ++++- twilight-model/src/gateway/reaction.rs | 6 ++- twilight-model/src/guild/ban.rs | 4 ++ twilight-model/src/guild/emoji.rs | 12 ++++- twilight-model/src/guild/integration.rs | 12 ++++- .../src/guild/integration_application.rs | 6 ++- twilight-model/src/guild/invite/mod.rs | 12 ++++- twilight-model/src/guild/member.rs | 12 ++++- twilight-model/src/guild/template/mod.rs | 7 ++- twilight-model/src/oauth/application.rs | 6 ++- twilight-model/src/oauth/team/member.rs | 6 ++- twilight-model/src/user/mod.rs | 49 +++++++++++++++++-- twilight-model/src/voice/voice_state.rs | 6 ++- twilight-standby/src/lib.rs | 2 + 32 files changed, 214 insertions(+), 32 deletions(-) diff --git a/twilight-cache-inmemory/src/event/interaction.rs b/twilight-cache-inmemory/src/event/interaction.rs index 5c9de09df25..f161a615dbd 100644 --- a/twilight-cache-inmemory/src/event/interaction.rs +++ b/twilight-cache-inmemory/src/event/interaction.rs @@ -175,6 +175,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, @@ -253,6 +254,7 @@ mod tests { discriminator: 5678, email: None, flags: None, + global_name: Some("different name".to_owned()), id: Id::new(7), locale: None, mfa_enabled: None, @@ -290,6 +292,7 @@ mod tests { discriminator: 1234, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(6), locale: None, mfa_enabled: None, diff --git a/twilight-cache-inmemory/src/event/message.rs b/twilight-cache-inmemory/src/event/message.rs index b27be8effd6..aac715cc3d7 100644 --- a/twilight-cache-inmemory/src/event/message.rs +++ b/twilight-cache-inmemory/src/event/message.rs @@ -163,6 +163,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, diff --git a/twilight-cache-inmemory/src/event/voice_state.rs b/twilight-cache-inmemory/src/event/voice_state.rs index 801da16242e..83441bb19d1 100644 --- a/twilight-cache-inmemory/src/event/voice_state.rs +++ b/twilight-cache-inmemory/src/event/voice_state.rs @@ -309,6 +309,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, diff --git a/twilight-cache-inmemory/src/model/member.rs b/twilight-cache-inmemory/src/model/member.rs index 56cf6bd4d49..16b80441187 100644 --- a/twilight-cache-inmemory/src/model/member.rs +++ b/twilight-cache-inmemory/src/model/member.rs @@ -285,6 +285,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(1), locale: None, mfa_enabled: None, diff --git a/twilight-cache-inmemory/src/model/sticker.rs b/twilight-cache-inmemory/src/model/sticker.rs index 01f2f92891f..f59ce41699f 100644 --- a/twilight-cache-inmemory/src/model/sticker.rs +++ b/twilight-cache-inmemory/src/model/sticker.rs @@ -206,6 +206,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), + global_name: Some("test".to_owned()), id: Id::new(1), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), diff --git a/twilight-cache-inmemory/src/test.rs b/twilight-cache-inmemory/src/test.rs index dc2abb83fe6..9e8733c6ce1 100644 --- a/twilight-cache-inmemory/src/test.rs +++ b/twilight-cache-inmemory/src/test.rs @@ -49,6 +49,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, @@ -124,6 +125,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, @@ -162,6 +164,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { discriminator: 2, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(5), locale: None, mfa_enabled: None, @@ -354,6 +357,7 @@ pub fn user(id: Id) -> User { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id, locale: None, mfa_enabled: None, diff --git a/twilight-model/src/application/interaction/application_command/resolved.rs b/twilight-model/src/application/interaction/application_command/resolved.rs index a1691c4c7aa..be9729f7f02 100644 --- a/twilight-model/src/application/interaction/application_command/resolved.rs +++ b/twilight-model/src/application/interaction/application_command/resolved.rs @@ -183,6 +183,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, @@ -263,6 +264,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), + global_name: Some("test".to_owned()), id: Id::new(300), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), @@ -375,7 +377,7 @@ mod tests { Token::Str("author"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -388,6 +390,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("3"), @@ -505,7 +510,7 @@ mod tests { Token::Str("300"), Token::Struct { name: "User", - len: 14, + len: 15, }, Token::Str("accent_color"), Token::None, @@ -524,6 +529,9 @@ mod tests { Token::Str("flags"), Token::Some, Token::U64(131_584), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("300"), diff --git a/twilight-model/src/application/interaction/mod.rs b/twilight-model/src/application/interaction/mod.rs index b7d60c44672..7710ba538f2 100644 --- a/twilight-model/src/application/interaction/mod.rs +++ b/twilight-model/src/application/interaction/mod.rs @@ -538,6 +538,7 @@ mod tests { discriminator: 1111, email: None, flags: None, + global_name: Some("test".into()), id: Id::new(600), locale: None, mfa_enabled: None, @@ -576,6 +577,7 @@ mod tests { discriminator: 1111, email: None, flags: None, + global_name: Some("test".into()), id: Id::new(600), locale: None, mfa_enabled: None, @@ -687,7 +689,7 @@ mod tests { Token::Str("600"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -700,6 +702,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("1111"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("600"), @@ -753,7 +758,7 @@ mod tests { Token::Some, Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -766,6 +771,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("1111"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("600"), diff --git a/twilight-model/src/channel/message/interaction.rs b/twilight-model/src/channel/message/interaction.rs index c7292dbfdc3..6f999dfcdc6 100644 --- a/twilight-model/src/channel/message/interaction.rs +++ b/twilight-model/src/channel/message/interaction.rs @@ -68,6 +68,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), + global_name: Some("test".to_owned()), id: Id::new(3), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), @@ -125,7 +126,7 @@ mod tests { Token::Str("user"), Token::Struct { name: "User", - len: 14, + len: 15, }, Token::Str("accent_color"), Token::None, @@ -145,6 +146,9 @@ mod tests { Token::Str("flags"), Token::Some, Token::U64(131_584), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("3"), diff --git a/twilight-model/src/channel/message/mod.rs b/twilight-model/src/channel/message/mod.rs index 0b4e18cb48d..7505090a86c 100644 --- a/twilight-model/src/channel/message/mod.rs +++ b/twilight-model/src/channel/message/mod.rs @@ -231,6 +231,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, @@ -296,7 +297,7 @@ mod tests { Token::Str("author"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -309,6 +310,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("3"), @@ -426,6 +430,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, @@ -540,7 +545,7 @@ mod tests { Token::Str("author"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -553,6 +558,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("3"), diff --git a/twilight-model/src/channel/message/sticker/mod.rs b/twilight-model/src/channel/message/sticker/mod.rs index fdd6da1b23e..f3e3d12d3dc 100644 --- a/twilight-model/src/channel/message/sticker/mod.rs +++ b/twilight-model/src/channel/message/sticker/mod.rs @@ -159,6 +159,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), + global_name: Some("test".to_owned()), id: Id::new(1), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), @@ -210,7 +211,7 @@ mod tests { Token::Some, Token::Struct { name: "User", - len: 15, + len: 16, }, Token::Str("accent_color"), Token::None, @@ -229,6 +230,9 @@ mod tests { Token::Str("flags"), Token::Some, Token::U64(131_584), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("1"), diff --git a/twilight-model/src/channel/webhook/mod.rs b/twilight-model/src/channel/webhook/mod.rs index dcdee4fac3e..bbabaf62b93 100644 --- a/twilight-model/src/channel/webhook/mod.rs +++ b/twilight-model/src/channel/webhook/mod.rs @@ -162,6 +162,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(2), locale: None, mfa_enabled: None, @@ -239,7 +240,7 @@ mod tests { Token::Some, Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -251,6 +252,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("2"), diff --git a/twilight-model/src/gateway/event/mod.rs b/twilight-model/src/gateway/event/mod.rs index 3996a4764a0..a46d94d2b79 100644 --- a/twilight-model/src/gateway/event/mod.rs +++ b/twilight-model/src/gateway/event/mod.rs @@ -475,7 +475,7 @@ mod tests { // requires a variable to be used in a function, so this is a false // positive. #[allow(dead_code)] - const EVENT_THRESHOLD: usize = 184; + const EVENT_THRESHOLD: usize = 208; const_assert!(mem::size_of::() == EVENT_THRESHOLD); diff --git a/twilight-model/src/gateway/payload/incoming/member_add.rs b/twilight-model/src/gateway/payload/incoming/member_add.rs index 42d0d53a7e0..79e3b134436 100644 --- a/twilight-model/src/gateway/payload/incoming/member_add.rs +++ b/twilight-model/src/gateway/payload/incoming/member_add.rs @@ -62,6 +62,7 @@ mod tests { banner: None, bot: false, discriminator: 987, + global_name: None, name: "ab".to_string(), mfa_enabled: None, locale: None, diff --git a/twilight-model/src/gateway/payload/incoming/member_chunk.rs b/twilight-model/src/gateway/payload/incoming/member_chunk.rs index 73e7365be5e..ca837dba388 100644 --- a/twilight-model/src/gateway/payload/incoming/member_chunk.rs +++ b/twilight-model/src/gateway/payload/incoming/member_chunk.rs @@ -219,6 +219,7 @@ mod tests { "user": { "avatar": image_hash::AVATAR_INPUT, "discriminator": "0001", + "global_name": "test", "id": "5", "public_flags": 131_072, "username": "test", @@ -235,6 +236,7 @@ mod tests { "user": { "avatar": image_hash::AVATAR_INPUT, "discriminator": "0001", + "global_name": "test", "id": "6", "username": "test", }, @@ -251,6 +253,7 @@ mod tests { "avatar": image_hash::AVATAR_INPUT, "bot": true, "discriminator": "0001", + "global_name": "test", "id": "3", "username": "test", }, @@ -270,6 +273,7 @@ mod tests { "avatar": image_hash::AVATAR_INPUT, "bot": true, "discriminator": "0001", + "global_name": "test", "id": "2", "username": "test", }, @@ -336,6 +340,7 @@ mod tests { verified: None, email: None, flags: None, + global_name: Some("test".to_owned()), premium_type: None, system: None, public_flags: None, @@ -365,6 +370,7 @@ mod tests { verified: None, email: None, flags: None, + global_name: Some("test".to_owned()), premium_type: None, system: None, public_flags: None, @@ -394,6 +400,7 @@ mod tests { verified: None, email: None, flags: None, + global_name: Some("test".to_owned()), premium_type: None, system: None, public_flags: Some(UserFlags::VERIFIED_DEVELOPER), @@ -423,6 +430,7 @@ mod tests { verified: None, email: None, flags: None, + global_name: Some("test".to_owned()), premium_type: None, system: None, public_flags: None, diff --git a/twilight-model/src/gateway/payload/incoming/member_update.rs b/twilight-model/src/gateway/payload/incoming/member_update.rs index f6ee4722feb..e2b83666c00 100644 --- a/twilight-model/src/gateway/payload/incoming/member_update.rs +++ b/twilight-model/src/gateway/payload/incoming/member_update.rs @@ -68,6 +68,7 @@ mod tests { bot: false, email: None, flags: None, + global_name: Some("test".to_string()), locale: None, mfa_enabled: None, premium_type: None, @@ -112,7 +113,7 @@ mod tests { Token::Str("user"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -125,6 +126,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("1234"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("424242"), diff --git a/twilight-model/src/gateway/payload/incoming/thread_members_update.rs b/twilight-model/src/gateway/payload/incoming/thread_members_update.rs index f61e82d786f..1b8c6071ef9 100644 --- a/twilight-model/src/gateway/payload/incoming/thread_members_update.rs +++ b/twilight-model/src/gateway/payload/incoming/thread_members_update.rs @@ -130,6 +130,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, @@ -249,7 +250,7 @@ mod tests { Token::Str("user"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -261,6 +262,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "UserId" }, Token::Str("3"), diff --git a/twilight-model/src/gateway/payload/incoming/typing_start.rs b/twilight-model/src/gateway/payload/incoming/typing_start.rs index d27d755b94c..89347eb5015 100644 --- a/twilight-model/src/gateway/payload/incoming/typing_start.rs +++ b/twilight-model/src/gateway/payload/incoming/typing_start.rs @@ -58,6 +58,7 @@ mod tests { banner: None, bot: false, discriminator: 1, + global_name: Some("test".to_owned()), name: "test".to_owned(), mfa_enabled: None, locale: None, @@ -116,7 +117,7 @@ mod tests { Token::Str("user"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -129,6 +130,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("3"), diff --git a/twilight-model/src/gateway/payload/incoming/voice_state_update.rs b/twilight-model/src/gateway/payload/incoming/voice_state_update.rs index 8d5998d642f..4bbe3037a20 100644 --- a/twilight-model/src/gateway/payload/incoming/voice_state_update.rs +++ b/twilight-model/src/gateway/payload/incoming/voice_state_update.rs @@ -60,6 +60,7 @@ mod tests { banner: None, bot: false, discriminator: 909, + global_name: Some("test".to_string()), name: "foo".to_string(), mfa_enabled: None, locale: None, @@ -128,7 +129,7 @@ mod tests { Token::Str("user"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -140,6 +141,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0909"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("1"), @@ -200,6 +204,7 @@ mod tests { banner: None, bot: false, discriminator: 4242, + global_name: Some("test".to_string()), name: "Twilight Sparkle".to_string(), mfa_enabled: None, locale: None, @@ -275,7 +280,7 @@ mod tests { Token::Str("user"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -288,6 +293,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("4242"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("1234123123123"), diff --git a/twilight-model/src/gateway/reaction.rs b/twilight-model/src/gateway/reaction.rs index 3c2c4cf1250..c29acc06b54 100644 --- a/twilight-model/src/gateway/reaction.rs +++ b/twilight-model/src/gateway/reaction.rs @@ -63,6 +63,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(4), locale: None, mfa_enabled: None, @@ -128,7 +129,7 @@ mod tests { Token::Str("user"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -141,6 +142,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("4"), diff --git a/twilight-model/src/guild/ban.rs b/twilight-model/src/guild/ban.rs index 1c84de1a52e..59ec79dba2c 100644 --- a/twilight-model/src/guild/ban.rs +++ b/twilight-model/src/guild/ban.rs @@ -25,6 +25,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(100_000_000_000_000_000), locale: None, mfa_enabled: None, @@ -60,6 +61,9 @@ mod tests { Token::None, Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("100000000000000000"), diff --git a/twilight-model/src/guild/emoji.rs b/twilight-model/src/guild/emoji.rs index fac4c409665..3d514884ca8 100644 --- a/twilight-model/src/guild/emoji.rs +++ b/twilight-model/src/guild/emoji.rs @@ -53,6 +53,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(1), locale: None, mfa_enabled: None, @@ -88,7 +89,7 @@ mod tests { Token::Some, Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -100,6 +101,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("1"), @@ -129,6 +133,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(1), locale: None, mfa_enabled: None, @@ -169,7 +174,7 @@ mod tests { Token::Some, Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -181,6 +186,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("1"), diff --git a/twilight-model/src/guild/integration.rs b/twilight-model/src/guild/integration.rs index 17135507c31..54dbd254129 100644 --- a/twilight-model/src/guild/integration.rs +++ b/twilight-model/src/guild/integration.rs @@ -103,6 +103,7 @@ mod tests { discriminator: 1000, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(4), locale: None, mfa_enabled: None, @@ -176,7 +177,7 @@ mod tests { Token::Some, Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -189,6 +190,9 @@ mod tests { Token::Bool(true), Token::Str("discriminator"), Token::Str("1000"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("4"), @@ -244,6 +248,7 @@ mod tests { discriminator: 1000, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(4), locale: None, mfa_enabled: None, @@ -332,7 +337,7 @@ mod tests { Token::Some, Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -345,6 +350,9 @@ mod tests { Token::Bool(true), Token::Str("discriminator"), Token::Str("1000"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("4"), diff --git a/twilight-model/src/guild/integration_application.rs b/twilight-model/src/guild/integration_application.rs index bf50e2b1399..9e6dd694327 100644 --- a/twilight-model/src/guild/integration_application.rs +++ b/twilight-model/src/guild/integration_application.rs @@ -64,6 +64,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(2), locale: None, mfa_enabled: None, @@ -90,7 +91,7 @@ mod tests { Token::Some, Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -102,6 +103,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("2"), diff --git a/twilight-model/src/guild/invite/mod.rs b/twilight-model/src/guild/invite/mod.rs index 389a98d2644..41a1cb6df37 100644 --- a/twilight-model/src/guild/invite/mod.rs +++ b/twilight-model/src/guild/invite/mod.rs @@ -201,6 +201,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(2), locale: None, mfa_enabled: None, @@ -221,6 +222,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(2), locale: None, mfa_enabled: None, @@ -351,7 +353,7 @@ mod tests { Token::Some, Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -363,6 +365,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("2"), @@ -382,7 +387,7 @@ mod tests { Token::Some, Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -394,6 +399,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("2"), diff --git a/twilight-model/src/guild/member.rs b/twilight-model/src/guild/member.rs index a394fbfac8d..2b7ebc4c892 100644 --- a/twilight-model/src/guild/member.rs +++ b/twilight-model/src/guild/member.rs @@ -74,6 +74,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, @@ -119,7 +120,7 @@ mod tests { Token::Str("user"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -131,6 +132,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("3"), @@ -170,6 +174,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, @@ -216,7 +221,7 @@ mod tests { Token::Str("user"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -228,6 +233,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("3"), diff --git a/twilight-model/src/guild/template/mod.rs b/twilight-model/src/guild/template/mod.rs index 6cca6b1b276..a04046c4f9d 100644 --- a/twilight-model/src/guild/template/mod.rs +++ b/twilight-model/src/guild/template/mod.rs @@ -67,6 +67,7 @@ mod tests { "avatar": "{avatar}", "banner": "{banner}", "discriminator": "1111", + "global_name": "test", "id": "100", "public_flags": 0, "username": "username" @@ -186,6 +187,7 @@ mod tests { email: None, discriminator: 1111, flags: None, + global_name: Some("test".into()), id: Id::new(100), locale: None, mfa_enabled: None, @@ -444,7 +446,7 @@ mod tests { Token::Str("creator"), Token::Struct { name: "User", - len: 8, + len: 9, }, Token::Str("accent_color"), Token::None, @@ -458,6 +460,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("1111"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("100"), diff --git a/twilight-model/src/oauth/application.rs b/twilight-model/src/oauth/application.rs index f1054d6dc34..1f24fc85109 100644 --- a/twilight-model/src/oauth/application.rs +++ b/twilight-model/src/oauth/application.rs @@ -115,6 +115,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, @@ -180,7 +181,7 @@ mod tests { Token::Some, Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -192,6 +193,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("3"), diff --git a/twilight-model/src/oauth/team/member.rs b/twilight-model/src/oauth/team/member.rs index 115aeb93982..7716ff3a92a 100644 --- a/twilight-model/src/oauth/team/member.rs +++ b/twilight-model/src/oauth/team/member.rs @@ -33,6 +33,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(2), locale: None, mfa_enabled: None, @@ -63,7 +64,7 @@ mod tests { Token::Str("user"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -75,6 +76,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("2"), diff --git a/twilight-model/src/user/mod.rs b/twilight-model/src/user/mod.rs index 799dd1a7fab..7726547116e 100644 --- a/twilight-model/src/user/mod.rs +++ b/twilight-model/src/user/mod.rs @@ -108,7 +108,7 @@ impl Display for DiscriminatorDisplay { // // If the value is [1000, u16::MAX] then we don't need to pad. match self.0 { - 0..=9 => f.write_str("000")?, + 1..=9 => f.write_str("000")?, 10..=99 => f.write_str("00")?, 100..=999 => f.write_str("0")?, _ => {} @@ -131,6 +131,9 @@ pub struct User { pub bot: bool, /// Discriminator used to differentiate people with the same username. /// + /// Note: Users that have migrated to the new username system will have a + /// discriminator of `0`. + /// /// # Formatting /// /// Because discriminators are stored as an integer they're not in the @@ -151,6 +154,9 @@ pub struct User { pub email: Option, #[serde(skip_serializing_if = "Option::is_none")] pub flags: Option, + /// User's global display name, if set. For bots, this is the application name + #[serde(skip_serializing_if = "Option::is_none")] + pub global_name: Option, pub id: Id, #[serde(skip_serializing_if = "Option::is_none")] pub locale: Option, @@ -201,7 +207,7 @@ mod tests { vec![ Token::Struct { name: "User", - len: 14, + len: 15, }, Token::Str("accent_color"), Token::None, @@ -221,6 +227,9 @@ mod tests { Token::Str("flags"), Token::Some, Token::U64(131_584), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("1"), @@ -249,7 +258,7 @@ mod tests { vec![ Token::Struct { name: "User", - len: 15, + len: 16, }, Token::Str("accent_color"), Token::None, @@ -269,6 +278,9 @@ mod tests { Token::Str("flags"), Token::Some, Token::U64(131_584), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("1"), @@ -303,6 +315,7 @@ mod tests { assert_eq!("0033", DiscriminatorDisplay::new(33).to_string()); assert_eq!("0333", DiscriminatorDisplay::new(333).to_string()); assert_eq!("3333", DiscriminatorDisplay::new(3333).to_string()); + assert_eq!("0", DiscriminatorDisplay::new(0).to_string()); } #[test] @@ -315,6 +328,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), + global_name: Some("test".to_owned()), id: Id::new(1), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), @@ -335,6 +349,34 @@ mod tests { serde_test::assert_de_tokens(&value, &user_tokens(Token::U64(1))); } + #[test] + fn user_no_discriminator() { + let value = User { + accent_color: None, + avatar: Some(image_hash::AVATAR), + banner: Some(image_hash::BANNER), + bot: false, + discriminator: 0, + email: Some("address@example.com".to_owned()), + flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), + global_name: Some("test".to_owned()), + id: Id::new(1), + locale: Some("en-us".to_owned()), + mfa_enabled: Some(true), + name: "test".to_owned(), + premium_type: Some(PremiumType::Nitro), + public_flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), + system: None, + verified: Some(true), + }; + + // Users migrated to the new username system will have a placeholder discriminator of 0, + // You can check if a user has migrated by seeing if their discriminator is 0. + // Read more here: https://discord.com/developers/docs/change-log#identifying-migrated-users + serde_test::assert_tokens(&value, &user_tokens(Token::Str("0"))); + serde_test::assert_de_tokens(&value, &user_tokens(Token::U64(0))); + } + #[test] fn user_complete() { let value = User { @@ -345,6 +387,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), + global_name: Some("test".to_owned()), id: Id::new(1), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), diff --git a/twilight-model/src/voice/voice_state.rs b/twilight-model/src/voice/voice_state.rs index 32f505d5959..58f7c9c1ef9 100644 --- a/twilight-model/src/voice/voice_state.rs +++ b/twilight-model/src/voice/voice_state.rs @@ -156,6 +156,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(3), locale: None, mfa_enabled: None, @@ -224,7 +225,7 @@ mod tests { Token::Str("user"), Token::Struct { name: "User", - len: 7, + len: 8, }, Token::Str("accent_color"), Token::None, @@ -236,6 +237,9 @@ mod tests { Token::Bool(false), Token::Str("discriminator"), Token::Str("0001"), + Token::Str("global_name"), + Token::Some, + Token::Str("test"), Token::Str("id"), Token::NewtypeStruct { name: "Id" }, Token::Str("3"), diff --git a/twilight-standby/src/lib.rs b/twilight-standby/src/lib.rs index c61dbcd2b95..08a90339a94 100644 --- a/twilight-standby/src/lib.rs +++ b/twilight-standby/src/lib.rs @@ -1100,6 +1100,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(2), locale: None, mfa_enabled: None, @@ -1216,6 +1217,7 @@ mod tests { discriminator: 1, email: None, flags: None, + global_name: Some("test".to_owned()), id: Id::new(2), locale: None, mfa_enabled: None,