From 1a79d52bfbc23603dade060d7cbebb686d45fe25 Mon Sep 17 00:00:00 2001 From: Ske Date: Wed, 30 Oct 2019 14:11:24 +0100 Subject: [PATCH] Add importing of Tupperbox multibrackets --- .../Commands/ImportExportCommands.cs | 4 +-- PluralKit.Core/DataFiles.cs | 30 ++++++++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/PluralKit.Bot/Commands/ImportExportCommands.cs b/PluralKit.Bot/Commands/ImportExportCommands.cs index d07bb964..01b7b634 100644 --- a/PluralKit.Bot/Commands/ImportExportCommands.cs +++ b/PluralKit.Bot/Commands/ImportExportCommands.cs @@ -64,15 +64,13 @@ namespace PluralKit.Bot.Commands if (!tupperbox.Valid) throw Errors.InvalidImportFile; var res = tupperbox.ToPluralKit(); - if (res.HadGroups || res.HadMultibrackets || res.HadIndividualTags) + if (res.HadGroups || res.HadIndividualTags) { var issueStr = $"{Emojis.Warn} The following potential issues were detected converting your Tupperbox input file:"; if (res.HadGroups) issueStr += "\n- PluralKit does not support member groups. Members will be imported without groups."; - if (res.HadMultibrackets) - issueStr += "\n- PluralKit does not support members with multiple proxy tags. Only the first pair will be imported."; if (res.HadIndividualTags) issueStr += "\n- PluralKit does not support per-member system tags. Since you had multiple members with distinct tags, tags will not be imported. You can set your system tag using the `pk;system tag ` command later."; diff --git a/PluralKit.Core/DataFiles.cs b/PluralKit.Core/DataFiles.cs index 97960f97..6bb2d079 100644 --- a/PluralKit.Core/DataFiles.cs +++ b/PluralKit.Core/DataFiles.cs @@ -38,6 +38,7 @@ namespace PluralKit.Bot Color = m.Color, AvatarUrl = m.AvatarUrl, ProxyTags = m.ProxyTags, + KeepProxy = m.KeepProxy, Created = Formats.TimestampExportFormat.Format(m.Created), MessageCount = messageCounts.Where(x => x.Member == m.Id).Select(x => x.MessageCount).FirstOrDefault() })); @@ -151,6 +152,12 @@ namespace PluralKit.Bot { member.ProxyTags = new List { new ProxyTag(dataMember.Prefix, dataMember.Suffix) }; } + else + { + member.ProxyTags = dataMember.ProxyTags; + } + + member.KeepProxy = dataMember.KeepProxy; if (dataMember.Birthday != null) { @@ -228,7 +235,8 @@ namespace PluralKit.Bot // ^ is superseded by v [JsonProperty("proxy_tags")] public ICollection ProxyTags; - + + [JsonProperty("keep_proxy")] public bool KeepProxy; [JsonProperty("message_count")] public int MessageCount; [JsonProperty("created")] public string Created; @@ -245,7 +253,6 @@ namespace PluralKit.Bot { public bool HadGroups; public bool HadIndividualTags; - public bool HadMultibrackets; public DataFileSystem System; } @@ -265,8 +272,8 @@ namespace PluralKit.Bot output.System = new DataFileSystem { - Members = Tuppers.Select(t => t.ToPluralKit(ref lastSetTag, ref output.HadMultibrackets, - ref output.HadGroups, ref output.HadMultibrackets)).ToList(), + Members = Tuppers.Select(t => t.ToPluralKit(ref lastSetTag, ref output.HadIndividualTags, + ref output.HadGroups)).ToList(), Switches = new List(), // If we haven't had multiple tags set, use the last (and only) one we set as the system tag Tag = !output.HadIndividualTags ? lastSetTag : null @@ -279,9 +286,9 @@ namespace PluralKit.Bot { [JsonProperty("name")] public string Name; [JsonProperty("avatar_url")] public string AvatarUrl; - [JsonProperty("brackets")] public ICollection Brackets; + [JsonProperty("brackets")] public IList Brackets; [JsonProperty("posts")] public int Posts; // Not supported by PK - [JsonProperty("show_brackets")] public bool ShowBrackets; // Not supported by PK + [JsonProperty("show_brackets")] public bool ShowBrackets; [JsonProperty("birthday")] public string Birthday; [JsonProperty("description")] public string Description; [JsonProperty("tag")] public string Tag; // Not supported by PK @@ -290,7 +297,7 @@ namespace PluralKit.Bot [JsonIgnore] public bool Valid => Name != null && Brackets != null && Brackets.Count % 2 == 0; - public DataFileMember ToPluralKit(ref string lastSetTag, ref bool multipleTags, ref bool hasGroup, ref bool hasMultiBrackets) + public DataFileMember ToPluralKit(ref string lastSetTag, ref bool multipleTags, ref bool hasGroup) { // If we've set a tag before and it's not the same as this one, // then we have multiple unique tags and we pass that flag back to the caller @@ -302,8 +309,9 @@ namespace PluralKit.Bot // Brackets in Tupperbox format are arranged as a single array // [prefix1, suffix1, prefix2, suffix2, prefix3... etc] - // If there are more than two entries this member has multiple brackets and we flag that - if (Brackets.Count > 2) hasMultiBrackets = true; + var tags = new List(); + for (var i = 0; i < Brackets.Count / 2; i++) + tags.Add(new ProxyTag(Brackets[i * 2], Brackets[i * 2 + 1])); return new DataFileMember { @@ -312,8 +320,8 @@ namespace PluralKit.Bot AvatarUrl = AvatarUrl, Birthday = Birthday, Description = Description, - Prefix = Brackets.FirstOrDefault().NullIfEmpty(), - Suffix = Brackets.Skip(1).FirstOrDefault().NullIfEmpty() // TODO: can Tupperbox members have no proxies at all? + ProxyTags = tags, + KeepProxy = ShowBrackets }; } }