diff --git a/PluralKit.Bot/Commands/Lists/ContextListExt.cs b/PluralKit.Bot/Commands/Lists/ContextListExt.cs index 891dfa6e..c4ac3b8f 100644 --- a/PluralKit.Bot/Commands/Lists/ContextListExt.cs +++ b/PluralKit.Bot/Commands/Lists/ContextListExt.cs @@ -146,7 +146,7 @@ public static class ContextListExt ret += $"({m.DisplayName})"; else if (opts.IncludeBirthday && m.BirthdayFor(lookupCtx) is { } birthday) ret += $"(birthday: {m.BirthdayString})"; - else if (m.HasProxyTags) + else if (m.HasProxyTags && m.ProxyPrivacy.CanAccess(lookupCtx)) { var proxyTagsString = m.ProxyTagsString(); if (proxyTagsString.Length > 100) // arbitrary threshold for now, tweak? @@ -173,7 +173,7 @@ public static class ContextListExt if (m.BirthdayFor(lookupCtx) != null) profile.Append($"\n**Birthdate**: {m.BirthdayString}"); - if (m.ProxyTags.Count > 0) + if (m.ProxyTags.Count > 0 && m.ProxyPrivacy.CanAccess(lookupCtx)) profile.Append($"\n**Proxy tags**: {m.ProxyTagsString()}"); if ((opts.IncludeMessageCount || opts.SortProperty == SortProperty.MessageCount) && diff --git a/PluralKit.Bot/Commands/MemberEdit.cs b/PluralKit.Bot/Commands/MemberEdit.cs index 717d29bb..611c7913 100644 --- a/PluralKit.Bot/Commands/MemberEdit.cs +++ b/PluralKit.Bot/Commands/MemberEdit.cs @@ -574,11 +574,12 @@ public class MemberEdit .Field(new Embed.Field("Avatar", target.AvatarPrivacy.Explanation())) .Field(new Embed.Field("Birthday", target.BirthdayPrivacy.Explanation())) .Field(new Embed.Field("Pronouns", target.PronounPrivacy.Explanation())) + .Field(new Embed.Field("Proxy Tags", target.ProxyPrivacy.Explanation())) .Field(new Embed.Field("Meta (creation date, message count, last front, last message)", target.MetadataPrivacy.Explanation())) .Field(new Embed.Field("Visibility", target.MemberVisibility.Explanation())) .Description( - "To edit privacy settings, use the command:\n`pk;member privacy `\n\n- `subject` is one of `name`, `description`, `avatar`, `birthday`, `pronouns`, `metadata`, `visibility`, or `all`\n- `level` is either `public` or `private`.") + "To edit privacy settings, use the command:\n`pk;member privacy `\n\n- `subject` is one of `name`, `description`, `avatar`, `birthday`, `pronouns`, `proxies`, `metadata`, `visibility`, or `all`\n- `level` is either `public` or `private`.") .Build()); return; } @@ -611,6 +612,7 @@ public class MemberEdit MemberPrivacySubject.Avatar => "avatar privacy", MemberPrivacySubject.Pronouns => "pronoun privacy", MemberPrivacySubject.Birthday => "birthday privacy", + MemberPrivacySubject.Proxy => "proxy tag privacy", MemberPrivacySubject.Metadata => "metadata privacy", MemberPrivacySubject.Visibility => "visibility", _ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}") @@ -628,6 +630,8 @@ public class MemberEdit "This member's birthday is now hidden from other systems.", (MemberPrivacySubject.Pronouns, PrivacyLevel.Private) => "This member's pronouns are now hidden from other systems.", + (MemberPrivacySubject.Proxy, PrivacyLevel.Private) => + "This member's proxy tags are now hidden from other systems.", (MemberPrivacySubject.Metadata, PrivacyLevel.Private) => "This member's metadata (eg. created timestamp, message count, etc) is now hidden from other systems.", (MemberPrivacySubject.Visibility, PrivacyLevel.Private) => @@ -642,7 +646,9 @@ public class MemberEdit (MemberPrivacySubject.Birthday, PrivacyLevel.Public) => "This member's birthday is no longer hidden from other systems.", (MemberPrivacySubject.Pronouns, PrivacyLevel.Public) => - "This member's pronouns are no longer hidden other systems.", + "This member's pronouns are no longer hidden from other systems.", + (MemberPrivacySubject.Proxy, PrivacyLevel.Public) => + "This member's proxy tags are no longer hidden from other systems.", (MemberPrivacySubject.Metadata, PrivacyLevel.Public) => "This member's metadata (eg. created timestamp, message count, etc) is no longer hidden from other systems.", (MemberPrivacySubject.Visibility, PrivacyLevel.Public) => diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index 63410be6..8077c0d2 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -242,7 +242,7 @@ public class EmbedService eb.Field(new Embed.Field("Pronouns", pronouns.Truncate(1024), true)); if (member.MessageCountFor(ctx) is { } count && count > 0) eb.Field(new Embed.Field("Message Count", member.MessageCount.ToString(), true)); - if (member.HasProxyTags) + if (member.HasProxyTags && member.ProxyPrivacy.CanAccess(ctx)) eb.Field(new Embed.Field("Proxy Tags", member.ProxyTagsString("\n").Truncate(1024), true)); // --- For when this gets added to the member object itself or however they get added // if (member.LastMessage != null && member.MetadataPrivacy.CanAccess(ctx)) eb.AddField("Last message:" FormatTimestamp(DiscordUtils.SnowflakeToInstant(m.LastMessage.Value))); diff --git a/PluralKit.Core/Database/Migrations/37.sql b/PluralKit.Core/Database/Migrations/37.sql new file mode 100644 index 00000000..65e956ab --- /dev/null +++ b/PluralKit.Core/Database/Migrations/37.sql @@ -0,0 +1,7 @@ +-- database version 37 +-- add proxy tag privacy + +alter table members add column proxy_privacy integer not null default 1; +alter table members add constraint members_proxy_privacy_check check (proxy_privacy = ANY (ARRAY[1,2])); + +update info set schema_version = 37; \ No newline at end of file diff --git a/PluralKit.Core/Database/Utils/DatabaseMigrator.cs b/PluralKit.Core/Database/Utils/DatabaseMigrator.cs index e6d18c3b..09837cfb 100644 --- a/PluralKit.Core/Database/Utils/DatabaseMigrator.cs +++ b/PluralKit.Core/Database/Utils/DatabaseMigrator.cs @@ -9,7 +9,7 @@ namespace PluralKit.Core; internal class DatabaseMigrator { private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files - private const int TargetSchemaVersion = 36; + private const int TargetSchemaVersion = 37; private readonly ILogger _logger; public DatabaseMigrator(ILogger logger) diff --git a/PluralKit.Core/Models/PKMember.cs b/PluralKit.Core/Models/PKMember.cs index 9affbb35..5a69053b 100644 --- a/PluralKit.Core/Models/PKMember.cs +++ b/PluralKit.Core/Models/PKMember.cs @@ -60,8 +60,8 @@ public class PKMember public PrivacyLevel NamePrivacy { get; private set; } //ignore setting if no display name is set public PrivacyLevel BirthdayPrivacy { get; private set; } public PrivacyLevel PronounPrivacy { get; private set; } - public PrivacyLevel MetadataPrivacy { get; private set; } + public PrivacyLevel ProxyPrivacy { get; private set; } // public PrivacyLevel ColorPrivacy { get; private set; } /// Returns a formatted string representing the member's birthday, taking into account that a year of "0001" or "0004" is hidden @@ -144,8 +144,11 @@ public static class PKMemberExt o.Add("last_message_timestamp", member.LastMessageTimestampFor(ctx)?.FormatExport()); var tagArray = new JArray(); - foreach (var tag in member.ProxyTags) - tagArray.Add(new JObject { { "prefix", tag.Prefix }, { "suffix", tag.Suffix } }); + if (member.ProxyPrivacy.CanAccess(ctx)) + { + foreach (var tag in member.ProxyTags) + tagArray.Add(new JObject { { "prefix", tag.Prefix }, { "suffix", tag.Suffix } }); + } o.Add("proxy_tags", tagArray); if (includePrivacy) @@ -159,6 +162,7 @@ public static class PKMemberExt p.Add("pronoun_privacy", member.PronounPrivacy.ToJsonString()); p.Add("avatar_privacy", member.AvatarPrivacy.ToJsonString()); p.Add("metadata_privacy", member.MetadataPrivacy.ToJsonString()); + p.Add("proxy_privacy", member.ProxyPrivacy.ToJsonString()); o.Add("privacy", p); } diff --git a/PluralKit.Core/Models/Patch/MemberPatch.cs b/PluralKit.Core/Models/Patch/MemberPatch.cs index 4872b304..19a7a502 100644 --- a/PluralKit.Core/Models/Patch/MemberPatch.cs +++ b/PluralKit.Core/Models/Patch/MemberPatch.cs @@ -29,8 +29,10 @@ public class MemberPatch: PatchObject public Partial PronounPrivacy { get; set; } public Partial BirthdayPrivacy { get; set; } public Partial AvatarPrivacy { get; set; } + public Partial ProxyPrivacy { get; set; } public Partial MetadataPrivacy { get; set; } + public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper .With("name", Name) .With("hid", Hid) @@ -52,6 +54,7 @@ public class MemberPatch: PatchObject .With("pronoun_privacy", PronounPrivacy) .With("birthday_privacy", BirthdayPrivacy) .With("avatar_privacy", AvatarPrivacy) + .With("proxy_privacy", ProxyPrivacy) .With("metadata_privacy", MetadataPrivacy) ); @@ -140,6 +143,8 @@ public class MemberPatch: PatchObject patch.BirthdayPrivacy = patch.ParsePrivacy(o, "birthday_privacy"); if (o.ContainsKey("pronoun_privacy")) patch.PronounPrivacy = patch.ParsePrivacy(o, "pronoun_privacy"); + if (o.ContainsKey("proxy_privacy")) + patch.ProxyPrivacy = patch.ParsePrivacy(o, "proxy_privacy"); if (o.ContainsKey("metadata_privacy")) patch.MetadataPrivacy = patch.ParsePrivacy(o, "metadata_privacy"); } @@ -173,6 +178,9 @@ public class MemberPatch: PatchObject if (privacy.ContainsKey("pronoun_privacy")) patch.PronounPrivacy = patch.ParsePrivacy(privacy, "pronoun_privacy"); + if (privacy.ContainsKey("proxy_privacy")) + patch.ProxyPrivacy = patch.ParsePrivacy(privacy, "proxy_privacy"); + if (privacy.ContainsKey("metadata_privacy")) patch.MetadataPrivacy = patch.ParsePrivacy(privacy, "metadata_privacy"); } @@ -222,6 +230,7 @@ public class MemberPatch: PatchObject || PronounPrivacy.IsPresent || BirthdayPrivacy.IsPresent || AvatarPrivacy.IsPresent + || ProxyPrivacy.IsPresent || MetadataPrivacy.IsPresent ) { @@ -245,6 +254,9 @@ public class MemberPatch: PatchObject if (AvatarPrivacy.IsPresent) p.Add("avatar_privacy", AvatarPrivacy.Value.ToJsonString()); + if (ProxyPrivacy.IsPresent) + p.Add("proxy_privacy", ProxyPrivacy.Value.ToJsonString()); + if (MetadataPrivacy.IsPresent) p.Add("metadata_privacy", MetadataPrivacy.Value.ToJsonString()); diff --git a/PluralKit.Core/Models/Privacy/MemberPrivacySubject.cs b/PluralKit.Core/Models/Privacy/MemberPrivacySubject.cs index 986808c1..731fab2d 100644 --- a/PluralKit.Core/Models/Privacy/MemberPrivacySubject.cs +++ b/PluralKit.Core/Models/Privacy/MemberPrivacySubject.cs @@ -8,6 +8,7 @@ public enum MemberPrivacySubject Avatar, Birthday, Pronouns, + Proxy, Metadata } @@ -24,6 +25,7 @@ public static class MemberPrivacyUtils MemberPrivacySubject.Pronouns => member.PronounPrivacy = level, MemberPrivacySubject.Birthday => member.BirthdayPrivacy = level, MemberPrivacySubject.Metadata => member.MetadataPrivacy = level, + MemberPrivacySubject.Proxy => member.ProxyPrivacy = level, MemberPrivacySubject.Visibility => member.Visibility = level, _ => throw new ArgumentOutOfRangeException($"Unknown privacy subject {subject}") }; @@ -73,6 +75,12 @@ public static class MemberPrivacyUtils case "created": subject = MemberPrivacySubject.Metadata; break; + case "proxy": + case "proxies": + case "tag": + case "tags": + subject = MemberPrivacySubject.Proxy; + break; case "visibility": case "hidden": case "shown":