Escape markdown in user nickname and some other places

master
Dragory 2019-03-28 05:03:47 +02:00
parent 3d077cb252
commit 2a20d9fdaa
2 changed files with 10 additions and 3 deletions

View File

@ -177,14 +177,14 @@ async function createNewThreadForUser(user, quiet = false) {
for (const [guildId, guildData] of userGuildData.entries()) { for (const [guildId, guildData] of userGuildData.entries()) {
const {nickname, joinDate} = getHeaderGuildInfo(guildData.member); const {nickname, joinDate} = getHeaderGuildInfo(guildData.member);
const headerItems = [ const headerItems = [
`NICKNAME **${nickname}**`, `NICKNAME **${utils.escapeMarkdown(nickname)}**`,
`JOINED **${joinDate}** ago` `JOINED **${joinDate}** ago`
]; ];
if (guildData.member.voiceState.channelID) { if (guildData.member.voiceState.channelID) {
const voiceChannel = guildData.guild.channels.get(guildData.member.voiceState.channelID); const voiceChannel = guildData.guild.channels.get(guildData.member.voiceState.channelID);
if (voiceChannel) { 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) { if (mainGuilds.length === 1) {
infoHeader += `\n${headerStr}`; infoHeader += `\n${headerStr}`;
} else { } else {
infoHeader += `\n**[${guildData.guild.name}]** ${headerStr}`; infoHeader += `\n**[${utils.escapeMarkdown(guildData.guild.name)}]** ${headerStr}`;
} }
} }

View File

@ -294,6 +294,11 @@ function isSnowflake(str) {
const humanizeDelay = (delay, opts = {}) => humanizeDuration(delay, Object.assign({conjunction: ' and '}, opts)); const humanizeDelay = (delay, opts = {}) => humanizeDuration(delay, Object.assign({conjunction: ' and '}, opts));
const markdownCharsRegex = /([\\_*|`~])/g;
function escapeMarkdown(str) {
return str.replace(markdownCharsRegex, '\\$1');
}
module.exports = { module.exports = {
BotError, BotError,
@ -327,4 +332,6 @@ module.exports = {
isSnowflake, isSnowflake,
humanizeDelay, humanizeDelay,
escapeMarkdown,
}; };