feat: throw user-readable error for editing a message to be empty

This commit is contained in:
rladenson 2024-12-31 05:15:21 -07:00 committed by Petal Ladenson
parent 2b5fab9689
commit 2d19142b44

View file

@ -204,7 +204,7 @@ public class ProxiedMessage
}
// Append or prepend the new content to the original message content if needed.
// If no flag is supplied, the new contents will completly overwrite the old contents
// If no flag is supplied, the new contents will completely overwrite the old contents
// If both flags are specified. the message will be prepended AND appended
if (append && prepend)
newContent = $"{newContent}{mutateSpace}{originalContent}{mutateSpace}{newContent}";
@ -216,6 +216,12 @@ public class ProxiedMessage
if (newContent.Length > 2000)
throw new PKError("PluralKit cannot proxy messages over 2000 characters in length.");
// We count as an empty message even if there's an embed because the only embeds pk proxies are reply embeds and those aren't message content
if (newContent.Trim().Length == 0 && (originalMsg.Attachments.Length == 0 || clearAttachments))
{
throw new PKError("This action would result in an empty message. If you wish to delete the message, react to it with \u274C.");
}
try
{
var editedMsg =