Skip to content

Commit

Permalink
fixed non-contextual discord user mention replacement
Browse files Browse the repository at this point in the history
- would replace any `@name` substring, regardless of whether or not it should classify as a mention
  • Loading branch information
Supinic committed Jun 1, 2021
1 parent ee2e569 commit c678672
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions controllers/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ module.exports = class DiscordController extends require("./template.js") {
const sortedUsers = guildUsers.array().sort((a, b) => b.user.username.length - a.user.username.length);
for (const member of sortedUsers) {
const name = sb.User.normalizeUsername(member.user.username);
const regex = new RegExp(`@${sb.Utils.escapeRegExp(name)}`, "gi");
const regex = new RegExp(`(\\s|^)@${sb.Utils.escapeRegExp(name)}\\b`, "gi");

message = message.replace(regex, `<@${member.user.id}>`);
message = message.replace(regex, `$1<@${member.user.id}>`);
}
}

Expand Down

0 comments on commit c678672

Please sign in to comment.