diff --git a/d2m/converters/message-to-event.js b/d2m/converters/message-to-event.js index c128595..29730d4 100644 --- a/d2m/converters/message-to-event.js +++ b/d2m/converters/message-to-event.js @@ -131,8 +131,8 @@ async function messageToEvent(message, guild, options = {}, di) { escapeHTML: false, }, null, null) - // Mentions scenario 3: scan the message content for written @mentions of matrix users - const matches = [...content.matchAll(/@([a-z0-9._]+)\b/gi)] + // Mentions scenario 3: scan the message content for written @mentions of matrix users. Allows for up to one space between @ and mention. + const matches = [...content.matchAll(/@ ?([a-z0-9._]+)\b/gi)] if (matches.length && matches.some(m => m[1].match(/[a-z]/i))) { const writtenMentionsText = matches.map(m => m[1].toLowerCase()) const roomID = db.prepare("SELECT room_id FROM channel_room WHERE channel_id = ?").pluck().get(message.channel_id) diff --git a/d2m/converters/message-to-event.test.js b/d2m/converters/message-to-event.test.js index 4200afe..df94196 100644 --- a/d2m/converters/message-to-event.test.js +++ b/d2m/converters/message-to-event.test.js @@ -247,10 +247,12 @@ test("message2event: simple reply to matrix user, reply fallbacks disabled", asy }]) }) -test("message2event: simple written @mention for matrix user", async t => { +test("message2event: simple written @mentions for matrix users", async t => { + let called = 0 const events = await messageToEvent(data.message.simple_written_at_mention_for_matrix, data.guild.general, {}, { api: { async getJoinedMembers(roomID) { + called++ t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe") return new Promise(resolve => { setTimeout(() => { @@ -290,6 +292,7 @@ test("message2event: simple written @mention for matrix user", async t => { msgtype: "m.text", body: "@Cadence, tell me about @Phil, the creator of the Chin Trick, who has become ever more powerful under the mentorship of @botrac4r and @huck" }]) + t.equal(called, 1, "should only look up the member list once") }) test("message2event: very large attachment is linked instead of being uploaded", async t => { diff --git a/scripts/events.db b/scripts/events.db index 3356cbe..d3b817d 100644 Binary files a/scripts/events.db and b/scripts/events.db differ