diff --git a/PluralKit.Bot/Commands/MemberEdit.cs b/PluralKit.Bot/Commands/MemberEdit.cs index 7295f815..100465c2 100644 --- a/PluralKit.Bot/Commands/MemberEdit.cs +++ b/PluralKit.Bot/Commands/MemberEdit.cs @@ -53,7 +53,7 @@ namespace PluralKit.Bot if (ctx.System == null) throw Errors.NoSystemError; if (target.System != ctx.System.Id) throw Errors.NotOwnMemberError; - var description = ctx.RemainderOrNull(); + var description = ctx.RemainderOrNull()?.NormalizeLineEndSpacing(); if (description.IsLongerThan(Limits.MaxDescriptionLength)) throw Errors.DescriptionTooLongError(description.Length); target.Description = description; diff --git a/PluralKit.Bot/Commands/SystemEdit.cs b/PluralKit.Bot/Commands/SystemEdit.cs index 6c1cdabe..af986cc6 100644 --- a/PluralKit.Bot/Commands/SystemEdit.cs +++ b/PluralKit.Bot/Commands/SystemEdit.cs @@ -38,7 +38,7 @@ namespace PluralKit.Bot public async Task Description(Context ctx) { ctx.CheckSystem(); - var newDescription = ctx.RemainderOrNull(); + var newDescription = ctx.RemainderOrNull()?.NormalizeLineEndSpacing(); if (newDescription != null && newDescription.Length > Limits.MaxDescriptionLength) throw Errors.DescriptionTooLongError(newDescription.Length); ctx.System.Description = newDescription; diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index 75366d3a..2124e2cf 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -56,7 +56,7 @@ namespace PluralKit.Bot { } if (system.Description != null && system.DescriptionPrivacy.CanAccess(ctx)) - eb.AddField("Description", system.Description.Truncate(1024), false); + eb.AddField("Description", system.Description.NormalizeLineEndSpacing().Truncate(1024), false); return eb.Build(); } @@ -66,7 +66,7 @@ namespace PluralKit.Bot { var timestamp = SnowflakeUtils.FromSnowflake(messageId); return new EmbedBuilder() .WithAuthor($"#{channel.Name}: {member.Name}", member.AvatarUrl) - .WithDescription(content) + .WithDescription(content?.NormalizeLineEndSpacing()) .WithFooter($"System ID: {system.Hid} | Member ID: {member.Hid} | Sender: {sender.Username}#{sender.Discriminator} ({sender.Id}) | Message ID: {messageId} | Original Message ID: {originalMsgId}") .WithTimestamp(timestamp) .Build(); @@ -122,7 +122,7 @@ namespace PluralKit.Bot { if (messageCount > 0 && member.MemberPrivacy.CanAccess(ctx)) eb.AddField("Message Count", messageCount, true); if (member.HasProxyTags) eb.AddField("Proxy Tags", string.Join('\n', proxyTagsStr).Truncate(1024), true); if (!member.Color.EmptyOrNull() && member.MemberPrivacy.CanAccess(ctx)) eb.AddField("Color", $"#{member.Color}", true); - if (!member.Description.EmptyOrNull() && member.MemberPrivacy.CanAccess(ctx)) eb.AddField("Description", member.Description, false); + if (!member.Description.EmptyOrNull() && member.MemberPrivacy.CanAccess(ctx)) eb.AddField("Description", member.Description.NormalizeLineEndSpacing(), false); return eb.Build(); } @@ -170,7 +170,7 @@ namespace PluralKit.Bot { var eb = new EmbedBuilder() .WithAuthor(msg.Member.Name, msg.Member.AvatarUrl) - .WithDescription(serverMsg?.Content ?? "*(message contents deleted or inaccessible)*") + .WithDescription(serverMsg?.Content?.NormalizeLineEndSpacing() ?? "*(message contents deleted or inaccessible)*") .WithImageUrl(serverMsg?.Attachments?.FirstOrDefault()?.Url) .AddField("System", msg.System.Name != null ? $"{msg.System.Name} (`{msg.System.Hid}`)" : $"`{msg.System.Hid}`", true) diff --git a/PluralKit.Core/Utils/StringUtils.cs b/PluralKit.Core/Utils/StringUtils.cs index 9c1dd667..dcdb70f6 100644 --- a/PluralKit.Core/Utils/StringUtils.cs +++ b/PluralKit.Core/Utils/StringUtils.cs @@ -1,5 +1,6 @@ using System; using System.Security.Cryptography; +using System.Text.RegularExpressions; namespace PluralKit.Core { @@ -60,5 +61,12 @@ namespace PluralKit.Core if (input.Trim().Length == 0) return true; return false; } + + public static string NormalizeLineEndSpacing(this string input) + { + // iOS has a weird issue on embeds rendering newlines when there are spaces *just before* it + // so we remove 'em all :) + return Regex.Replace(input, " *\n", "\n"); + } } } \ No newline at end of file