From adc54909faca8b4a0a4137ce0b134421377b8a08 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Mon, 17 Aug 2020 01:53:21 +0300 Subject: [PATCH] Tidy up edit/deletion styles --- src/formatters.js | 27 ++++++++++++++++++++++----- src/utils.js | 5 +++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/formatters.js b/src/formatters.js index 6a4009b..f484216 100644 --- a/src/formatters.js +++ b/src/formatters.js @@ -119,15 +119,32 @@ const defaultFormatters = { }, formatStaffReplyEditNotificationThreadMessage(threadMessage, newText, moderator) { - let content = `**${moderator.user.username}#${moderator.user.discriminator}** (\`${moderator.id}\`) edited reply \`[${threadMessage.message_number}]\`:`; - content += `\n\nBefore:\n\`\`\`${utils.disableCodeBlocks(threadMessage.body)}\`\`\``; - content += `\nAfter:\n\`\`\`${utils.disableCodeBlocks(newText)}\`\`\``; + let content = `**${moderator.user.username}#${moderator.user.discriminator}** (\`${moderator.id}\`) edited reply \`${threadMessage.message_number}\``; + + if (threadMessage.body.length < 200 && newText.length < 200) { + // Show edits of small messages inline + content += ` from \`${utils.disableInlineCode(threadMessage.body)}\` to \`${newText}\``; + } else { + // Show edits of long messages in two code blocks + content += ":"; + content += `\n\nBefore:\n\`\`\`${utils.disableCodeBlocks(threadMessage.body)}\`\`\``; + content += `\nAfter:\n\`\`\`${utils.disableCodeBlocks(newText)}\`\`\``; + } + return content; }, formatStaffReplyDeletionNotificationThreadMessage(threadMessage, moderator) { - let content = `**${moderator.user.username}#${moderator.user.discriminator}** (\`${moderator.id}\`) deleted reply \`[${threadMessage.message_number}]\`:`; - content += "```" + utils.disableCodeBlocks(threadMessage.body) + "```"; + let content = `**${moderator.user.username}#${moderator.user.discriminator}** (\`${moderator.id}\`) deleted reply \`[${threadMessage.message_number}]\``; + + if (threadMessage.body.length < 200) { + // Show the original content of deleted small messages inline + content += ` (message content: \`${utils.disableInlineCode(threadMessage.body)}\`)`; + } else { + // Show the original content of deleted large messages in a code block + content += ":\n```" + utils.disableCodeBlocks(threadMessage.body) + "```"; + } + return content; }, diff --git a/src/utils.js b/src/utils.js index 2a8bddb..6c537cf 100644 --- a/src/utils.js +++ b/src/utils.js @@ -306,6 +306,10 @@ function escapeMarkdown(str) { return str.replace(markdownCharsRegex, "\\$1"); } +function disableInlineCode(str) { + return str.replace(/`/g, "'"); +} + function disableCodeBlocks(str) { return str.replace(/`/g, "`\u200b"); } @@ -351,6 +355,7 @@ module.exports = { humanizeDelay, escapeMarkdown, + disableInlineCode, disableCodeBlocks, readMultilineConfigValue,