3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

use Util methods for escaping inline code and code blocks

This commit is contained in:
almeidx 2021-07-29 17:35:27 +01:00
parent 5e91a9fed3
commit 5de35f711d
No known key found for this signature in database
GPG key ID: 8558FBFF849BD664
11 changed files with 36 additions and 55 deletions

View file

@ -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) {