Fix newline rendering in embeds on iOS
This commit is contained in:
parent
456fe8f7af
commit
de141d629b
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user