From 01f1b203a564554e549264dec898f21974932614 Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Thu, 9 Jan 2025 14:50:31 +0100 Subject: [PATCH] fix: add missing primary_guild field Fixes DISCATSHARP-2EM Fixes DISCATSHARP-2EK --- DisCatSharp.Experimental/DiscordApiClientHook.cs | 1 + DisCatSharp/Clients/DiscordClient.Dispatch.cs | 3 +++ DisCatSharp/Clients/DiscordClient.cs | 4 ++++ DisCatSharp/Entities/Guild/DiscordGuild.cs | 1 + DisCatSharp/Entities/Guild/DiscordMember.cs | 10 ++++++++++ DisCatSharp/Entities/User/DiscordUser.cs | 7 +++++++ .../Net/Abstractions/Transport/TransportUser.cs | 6 ++++++ DisCatSharp/Net/Rest/DiscordApiClient.cs | 1 + 8 files changed, 33 insertions(+) diff --git a/DisCatSharp.Experimental/DiscordApiClientHook.cs b/DisCatSharp.Experimental/DiscordApiClientHook.cs index 9b5279e474..0e7b383a4a 100644 --- a/DisCatSharp.Experimental/DiscordApiClientHook.cs +++ b/DisCatSharp.Experimental/DiscordApiClientHook.cs @@ -236,6 +236,7 @@ internal async Task SearchGuildMembersAsync(u old.Locale = usr.Locale; old.GlobalName = usr.GlobalName; old.Clan = usr.Clan; + old.PrimaryGuild = usr.PrimaryGuild; return old; }); } diff --git a/DisCatSharp/Clients/DiscordClient.Dispatch.cs b/DisCatSharp/Clients/DiscordClient.Dispatch.cs index af9779ca0d..aa5894ac07 100644 --- a/DisCatSharp/Clients/DiscordClient.Dispatch.cs +++ b/DisCatSharp/Clients/DiscordClient.Dispatch.cs @@ -771,6 +771,7 @@ internal async Task OnReadyEventAsync(ReadyPayload ready, JArray rawGuilds) old.Locale = usr.Locale; old.GlobalName = usr.GlobalName; old.Clan = usr.Clan; + old.PrimaryGuild = usr.PrimaryGuild; return old; }); @@ -1971,6 +1972,7 @@ internal async Task OnGuildMemberAddEventAsync(TransportMember member, DiscordGu old.Locale = usr.Locale; old.GlobalName = usr.GlobalName; old.Clan = usr.Clan; + old.PrimaryGuild = usr.PrimaryGuild; return old; }); @@ -2045,6 +2047,7 @@ internal async Task OnGuildMemberUpdateEventAsync(TransportMember member, Discor old.Locale = usr.Locale; old.GlobalName = usr.GlobalName; old.Clan = usr.Clan; + old.PrimaryGuild = usr.PrimaryGuild; return old; }); diff --git a/DisCatSharp/Clients/DiscordClient.cs b/DisCatSharp/Clients/DiscordClient.cs index 2d4d1dc7d3..2f7701dfc4 100644 --- a/DisCatSharp/Clients/DiscordClient.cs +++ b/DisCatSharp/Clients/DiscordClient.cs @@ -538,6 +538,7 @@ public async Task GetUserAsync(ulong userId, bool fetch = false) old.Pronouns = usr.Pronouns; old.GlobalName = usr.GlobalName; old.Clan = usr.Clan; + old.PrimaryGuild = usr.PrimaryGuild; return old; }); @@ -1624,6 +1625,7 @@ private DiscordUser UpdateUser(DiscordUser usr, ulong? guildId, DiscordGuild? gu old.Locale = usr.Locale; old.GlobalName = usr.GlobalName; old.Clan = usr.Clan; + old.PrimaryGuild = usr.PrimaryGuild; return old; }); @@ -1662,6 +1664,7 @@ private DiscordUser UpdateUser(DiscordUser usr, ulong? guildId, DiscordGuild? gu old.Locale = usr.Locale; old.GlobalName = usr.GlobalName; old.Clan = usr.Clan; + old.PrimaryGuild = usr.PrimaryGuild; return old; }); @@ -1841,6 +1844,7 @@ private void UpdateCachedGuild(DiscordGuild newGuild, JArray? rawMembers) old.Locale = usr.Locale; old.GlobalName = usr.GlobalName; old.Clan = usr.Clan; + old.PrimaryGuild = usr.PrimaryGuild; return old; }); diff --git a/DisCatSharp/Entities/Guild/DiscordGuild.cs b/DisCatSharp/Entities/Guild/DiscordGuild.cs index c8b656975a..62786abc79 100644 --- a/DisCatSharp/Entities/Guild/DiscordGuild.cs +++ b/DisCatSharp/Entities/Guild/DiscordGuild.cs @@ -2078,6 +2078,7 @@ public async Task> GetAllMembersAsync() old.Locale = usr.Locale; old.GlobalName = usr.GlobalName; old.Clan = usr.Clan; + old.PrimaryGuild = usr.PrimaryGuild; return old; }); var mbr = new DiscordMember(xtm) diff --git a/DisCatSharp/Entities/Guild/DiscordMember.cs b/DisCatSharp/Entities/Guild/DiscordMember.cs index 1834e720cc..64f2f29fec 100644 --- a/DisCatSharp/Entities/Guild/DiscordMember.cs +++ b/DisCatSharp/Entities/Guild/DiscordMember.cs @@ -794,6 +794,16 @@ public override DiscordClan? Clan internal set => this.User.Clan = value; } + /// + /// Gets the member's primary guild. + /// + [JsonIgnore] + public override DiscordClan? PrimaryGuild + { + get => this.User.PrimaryGuild; + internal set => this.User.PrimaryGuild = value; + } + /// /// Gets whether the member is a bot. /// diff --git a/DisCatSharp/Entities/User/DiscordUser.cs b/DisCatSharp/Entities/User/DiscordUser.cs index 15c1b9a011..c574ace20b 100644 --- a/DisCatSharp/Entities/User/DiscordUser.cs +++ b/DisCatSharp/Entities/User/DiscordUser.cs @@ -65,6 +65,7 @@ internal DiscordUser(TransportUser transport) this.Pronouns = transport.Pronouns; this.GlobalName = transport.GlobalName; this.Clan = transport.Clan; + this.PrimaryGuild = transport.PrimaryGuild; } /// @@ -156,6 +157,12 @@ public string? BannerUrl [JsonProperty("clan", NullValueHandling = NullValueHandling.Ignore), DiscordUnreleased] public virtual DiscordClan? Clan { get; internal set; } + /// + /// Gets the users primary guild. + /// + [JsonProperty("primary_guild", NullValueHandling = NullValueHandling.Ignore), DiscordUnreleased] + public virtual DiscordClan? PrimaryGuild { get; internal set; } + /// /// Gets the user's avatar hash. /// diff --git a/DisCatSharp/Net/Abstractions/Transport/TransportUser.cs b/DisCatSharp/Net/Abstractions/Transport/TransportUser.cs index b8229cc39f..ed039ece2b 100644 --- a/DisCatSharp/Net/Abstractions/Transport/TransportUser.cs +++ b/DisCatSharp/Net/Abstractions/Transport/TransportUser.cs @@ -175,6 +175,12 @@ internal string UsernameWithGlobalName [JsonProperty("clan", NullValueHandling = NullValueHandling.Ignore)] public DiscordClan? Clan { get; internal set; } + /// + /// Gets the users primary guild. + /// + [JsonProperty("primary_guild", NullValueHandling = NullValueHandling.Ignore), DiscordUnreleased] + public DiscordClan? PrimaryGuild { get; internal set; } + /// /// Gets the users pronouns. /// diff --git a/DisCatSharp/Net/Rest/DiscordApiClient.cs b/DisCatSharp/Net/Rest/DiscordApiClient.cs index 79ad62e6e4..140a7cb3e4 100644 --- a/DisCatSharp/Net/Rest/DiscordApiClient.cs +++ b/DisCatSharp/Net/Rest/DiscordApiClient.cs @@ -476,6 +476,7 @@ internal async Task> SearchGuildMembersAsync(ulong old.Locale = usr.Locale; old.GlobalName = usr.GlobalName; old.Clan = usr.Clan; + old.PrimaryGuild = usr.PrimaryGuild; return old; });