From 2bffee5450131b27c309b34421a7b0df8d19523e Mon Sep 17 00:00:00 2001 From: Iris System Date: Tue, 21 Mar 2023 23:35:15 +1300 Subject: [PATCH] fix(bot): fix import/export with incorrect webhook_avatar_url Incorrect use of `member.WebhookAvatarFor` in member JSON creation meant that exports of members without a webhook avatar set had the normal avatar URL present in both fields. This also adds a check to the importer to ignore the value of the webhook_avatar_url field if it is the same as the avatar_url field. Fixes: ccb89f50e96861d5c49e7a31277d3f0bf1b3afba (feat(bot): allow separate member avatars for proxied messages) Co-authored-by: spiral --- PluralKit.Core/Models/PKMember.cs | 2 +- PluralKit.Core/Models/Patch/MemberPatch.cs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/PluralKit.Core/Models/PKMember.cs b/PluralKit.Core/Models/PKMember.cs index ede4368c..9affbb35 100644 --- a/PluralKit.Core/Models/PKMember.cs +++ b/PluralKit.Core/Models/PKMember.cs @@ -132,7 +132,7 @@ public static class PKMemberExt o.Add("birthday", member.BirthdayFor(ctx)?.FormatExport()); o.Add("pronouns", member.PronounsFor(ctx)); o.Add("avatar_url", member.AvatarFor(ctx).TryGetCleanCdnUrl()); - o.Add("webhook_avatar_url", member.WebhookAvatarFor(ctx).TryGetCleanCdnUrl()); + o.Add("webhook_avatar_url", member.AvatarPrivacy.Get(ctx, member.WebhookAvatarUrl?.TryGetCleanCdnUrl())); o.Add("banner", member.DescriptionPrivacy.Get(ctx, member.BannerImage).TryGetCleanCdnUrl()); o.Add("description", member.DescriptionFor(ctx)); o.Add("created", member.CreatedFor(ctx)?.FormatExport()); diff --git a/PluralKit.Core/Models/Patch/MemberPatch.cs b/PluralKit.Core/Models/Patch/MemberPatch.cs index 4101a7c6..4872b304 100644 --- a/PluralKit.Core/Models/Patch/MemberPatch.cs +++ b/PluralKit.Core/Models/Patch/MemberPatch.cs @@ -98,8 +98,17 @@ public class MemberPatch: PatchObject if (o.ContainsKey("name")) patch.Name = o.Value("name"); if (o.ContainsKey("color")) patch.Color = o.Value("color").NullIfEmpty()?.ToLower(); if (o.ContainsKey("display_name")) patch.DisplayName = o.Value("display_name").NullIfEmpty(); - if (o.ContainsKey("webhook_avatar_url")) patch.WebhookAvatarUrl = o.Value("webhook_avatar_url").NullIfEmpty(); if (o.ContainsKey("avatar_url")) patch.AvatarUrl = o.Value("avatar_url").NullIfEmpty(); + if (o.ContainsKey("webhook_avatar_url")) + { + var str = o.Value("webhook_avatar_url").NullIfEmpty(); + // XXX: ignore webhook_avatar_url if it's exactly the same as avatar_url + // to work around some export files containing the value of avatar_url in + // both fields accidentally + if (str != null && patch.AvatarUrl.Value != str) patch.WebhookAvatarUrl = str; + else patch.WebhookAvatarUrl = null; + } + if (o.ContainsKey("banner")) patch.BannerImage = o.Value("banner").NullIfEmpty(); if (o.ContainsKey("birthday"))