use Util methods for escaping inline code and code blocks
This commit is contained in:
parent
5e91a9fed3
commit
5de35f711d
11 changed files with 36 additions and 55 deletions
|
@ -22,6 +22,7 @@ import {
|
|||
TextChannel,
|
||||
ThreadChannel,
|
||||
User,
|
||||
Util,
|
||||
} from "discord.js";
|
||||
import emojiRegex from "emoji-regex";
|
||||
import { either } from "fp-ts/lib/Either";
|
||||
|
@ -785,21 +786,6 @@ export function deactivateMentions(content: string): string {
|
|||
return content.replace(/@/g, "@\u200b");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable inline code in the given string by replacing backticks/grave accents with acute accents
|
||||
* FIXME: Find a better way that keeps the grave accents? Can't use the code block approach here since it's just 1 character.
|
||||
*/
|
||||
export function disableInlineCode(content: string): string {
|
||||
return content.replace(/`/g, "\u00b4");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable code blocks in the given string by adding invisible unicode characters between backticks
|
||||
*/
|
||||
export function disableCodeBlocks(content: string): string {
|
||||
return content.replace(/`/g, "`\u200b");
|
||||
}
|
||||
|
||||
export function useMediaUrls(content: string): string {
|
||||
return content.replace(/cdn\.discord(app)?\.com/g, "media.discordapp.net");
|
||||
}
|
||||
|
@ -1336,11 +1322,11 @@ export async function confirm(channel: TextChannel, userId: string, content: Mes
|
|||
|
||||
export function messageSummary(msg: SavedMessage) {
|
||||
// Regular text content
|
||||
let result = "```\n" + (msg.data.content ? disableCodeBlocks(msg.data.content) : "<no text content>") + "```";
|
||||
let result = "```\n" + (msg.data.content ? Util.escapeCodeBlock(msg.data.content) : "<no text content>") + "```";
|
||||
|
||||
// Rich embed
|
||||
const richEmbed = (msg.data.embeds || []).find(e => (e as MessageEmbed).type === "rich");
|
||||
if (richEmbed) result += "Embed:```" + disableCodeBlocks(JSON.stringify(richEmbed)) + "```";
|
||||
if (richEmbed) result += "Embed:```" + Util.escapeCodeBlock(JSON.stringify(richEmbed)) + "```";
|
||||
|
||||
// Attachments
|
||||
if (msg.data.attachments) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue