diff --git a/src/data/threads.js b/src/data/threads.js index 66cce60..2716c84 100644 --- a/src/data/threads.js +++ b/src/data/threads.js @@ -177,14 +177,14 @@ async function createNewThreadForUser(user, quiet = false) { for (const [guildId, guildData] of userGuildData.entries()) { const {nickname, joinDate} = getHeaderGuildInfo(guildData.member); const headerItems = [ - `NICKNAME **${nickname}**`, + `NICKNAME **${utils.escapeMarkdown(nickname)}**`, `JOINED **${joinDate}** ago` ]; if (guildData.member.voiceState.channelID) { const voiceChannel = guildData.guild.channels.get(guildData.member.voiceState.channelID); if (voiceChannel) { - headerItems.push(`VOICE CHANNEL **${voiceChannel.name}**`); + headerItems.push(`VOICE CHANNEL **${utils.escapeMarkdown(voiceChannel.name)}**`); } } @@ -193,7 +193,7 @@ async function createNewThreadForUser(user, quiet = false) { if (mainGuilds.length === 1) { infoHeader += `\n${headerStr}`; } else { - infoHeader += `\n**[${guildData.guild.name}]** ${headerStr}`; + infoHeader += `\n**[${utils.escapeMarkdown(guildData.guild.name)}]** ${headerStr}`; } } diff --git a/src/utils.js b/src/utils.js index 69f3058..fddb719 100644 --- a/src/utils.js +++ b/src/utils.js @@ -294,6 +294,11 @@ function isSnowflake(str) { const humanizeDelay = (delay, opts = {}) => humanizeDuration(delay, Object.assign({conjunction: ' and '}, opts)); +const markdownCharsRegex = /([\\_*|`~])/g; +function escapeMarkdown(str) { + return str.replace(markdownCharsRegex, '\\$1'); +} + module.exports = { BotError, @@ -327,4 +332,6 @@ module.exports = { isSnowflake, humanizeDelay, + + escapeMarkdown, };