Skip to content

Commit

Permalink
Fix parsing when the same user is mentioned more than once (#541)
Browse files Browse the repository at this point in the history
Before, the parser would only replace the first instance of a mention
for any given user in a message.
  • Loading branch information
Qyriad committed Aug 15, 2020
1 parent 5af02c1 commit 56d1c84
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 56d1c84

Please sign in to comment.