diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index 92cdd4fb1ea205c78604d2a17b9a7200808b6a42..f0ef001a7c1639789cd769e2580e2ee992e22299 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -79,12 +79,12 @@ export class MatrixEventProcessor { } public FindMentionsInPlainBody(body: string, members: Discord.GuildMember[]): string { - const WORD_BOUNDARY = "(^|\:|\@|\#|```|\\s|$|,)"; + const WORD_BOUNDARY = "(^|\:|\#|```|\\s|$|,)"; for (const member of members) { const matcher = escapeStringRegexp(member.user.username + "#" + member.user.discriminator) + "|" + escapeStringRegexp(member.displayName); const regex = new RegExp( - `(${WORD_BOUNDARY})(${matcher})(?=${WORD_BOUNDARY})` + `(${WORD_BOUNDARY})(@?(${matcher}))(?=${WORD_BOUNDARY})` , "igmu"); body = body.replace(regex, `$1<@!${member.id}>`); diff --git a/test/test_matrixeventprocessor.ts b/test/test_matrixeventprocessor.ts index 343558cd114b3daf669d01e391cdf266d5ca874d..611a49dc79f40a175366ac2e77e060cbbacb8a2a 100644 --- a/test/test_matrixeventprocessor.ts +++ b/test/test_matrixeventprocessor.ts @@ -133,7 +133,7 @@ describe("MatrixEventProcessor", () => { body: "@testuser2 Hello!", }, }, {avatar_url: "test"}, mockChannel as any); - Chai.assert.equal(evt.description, "@<@!12345> Hello!"); + Chai.assert.equal(evt.description, "<@!12345> Hello!"); }); it("Should disable mentions if configured.", () => { @@ -232,6 +232,10 @@ describe("MatrixEventProcessor", () => { processor.FindMentionsInPlainBody("TestNickname was here with Test", members), "<@!12345> was here with <@!54321>", ); + Chai.assert.equal( + processor.FindMentionsInPlainBody("Fixing this issue provided by @Test", members), + "Fixing this issue provided by <@!54321>", + ); }); it("processes non-mentions correctly", async () => { const processor = createMatrixEventProcessor();