Fix parsing when the same user is mentioned more than once (#541)

Before, the parser would only replace the first instance of a mention
for any given user in a message.
This commit is contained in:
Mikaela Szekely 2020-08-14 18:35:48 -06:00 committed by GitHub
parent 5af02c16c6
commit 56d1c84147
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -275,9 +275,8 @@ class Bot {
parseText(message) {
const text = message.mentions.users.reduce((content, mention) => {
const displayName = Bot.getDiscordNicknameOnServer(mention, message.guild);
return content.replace(`<@${mention.id}>`, `@${displayName}`)
.replace(`<@!${mention.id}>`, `@${displayName}`)
.replace(`<@&${mention.id}>`, `@${displayName}`);
const userMentionRegex = RegExp(`<@(&|!)?${mention.id}>`, 'g');
return content.replace(userMentionRegex, `@${displayName}`);
}, message.content);
return text