Skip to content
Extraits de code Groupes Projets
Valider 905463a2 rédigé par Will Hunt's avatar Will Hunt
Parcourir les fichiers

v0.2.0-rc2 | Merge branch develop

parents fcf326e0 0c2f619d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -79,14 +79,15 @@ export class MatrixEventProcessor {
}
public FindMentionsInPlainBody(body: string, members: Discord.GuildMember[]): string {
const WORD_BOUNDARY = "(^|\:|\@|\#|```|\\s|$|,)";
for (const member of members) {
const matcher = escapeStringRegexp(member.user.username + "#" + member.user.discriminator) + "|" +
escapeStringRegexp(member.displayName);
body = body.replace(
new RegExp(
`\\b(${matcher})(?=\\b)`
, "mig"), `<@!${member.id}>`,
);
const regex = new RegExp(
`(${WORD_BOUNDARY})(${matcher})(?=${WORD_BOUNDARY})`
, "igmu");
body = body.replace(regex, `$1<@!${member.id}>`);
}
return body;
}
......
......@@ -204,12 +204,22 @@ describe("MatrixEventProcessor", () => {
username: "TestUsername",
id: "12345",
},
}), new Discord.GuildMember(guild, {
nick: "𝖘𝖔𝖒𝖊𝖋𝖆𝖓𝖈𝖞𝖓𝖎𝖈𝖐𝖓𝖆𝖒𝖊",
user: {
username: "SomeFancyNickname",
id: "66666",
},
})];
Chai.assert.equal(processor.FindMentionsInPlainBody("Hello TestNickname", members), "Hello <@!12345>");
Chai.assert.equal(processor.FindMentionsInPlainBody("TestNickname: Hello", members), "<@!12345>: Hello");
Chai.assert.equal(processor.FindMentionsInPlainBody("TestNickname, Hello", members), "<@!12345>, Hello");
Chai.assert.equal(processor.FindMentionsInPlainBody("TestNickname Hello", members), "<@!12345> Hello");
Chai.assert.equal(processor.FindMentionsInPlainBody("testNicKName Hello", members), "<@!12345> Hello");
Chai.assert.equal(
processor.FindMentionsInPlainBody("𝖘𝖔𝖒𝖊𝖋𝖆𝖓𝖈𝖞𝖓𝖎𝖈𝖐𝖓𝖆𝖒𝖊 Hello", members),
"<@!66666> Hello",
);
Chai.assert.equal(
processor.FindMentionsInPlainBody("I wish TestNickname was here", members),
"I wish <@!12345> was here",
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter