From e00eb15f35b36e796f3fa02d3f8ac889cad61094 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Thu, 17 Aug 2023 18:17:53 +1200 Subject: [PATCH] support up to 1 space in written mentions --- d2m/converters/message-to-event.js | 4 ++-- d2m/converters/message-to-event.test.js | 5 ++++- scripts/events.db | Bin 98304 -> 192512 bytes 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/d2m/converters/message-to-event.js b/d2m/converters/message-to-event.js index c128595f..29730d42 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 4200afe0..df941966 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 3356cbe2ba67631f1efdf34292de8256ab6ee024..d3b817d2a036453e0de94479f85f48b5b73d0bb7 100644 GIT binary patch delta 20626 zcmeHv3ve6feJ58GVTv>aOCl**w(KSRk|+|~_by;dGG7uYQ4%Fl)QdK>02aWC02Txm zq)5l19lzoz_C)#;VVtzh!_Fmk&Q5f0;wDZ!&Z9{??e*-LPJ8WKX5z+kZ6>`Wp1a;; zoTR?re;1%gOLgqHNha4M_L=~8zx^Kn@BjGyfB)~Edjj`-uk}OMG?g0~8hX$2JGkR=v2rGoeZ4_O@t1FMnk(o{h@6k zBP53+p)H{sFHG~?v-hw0L~sEOL{8z-lg6bxh09hGm##Z-*>VDx%|~&$WdfI*594yv zI4(CH#N~zqxP-@W>D-44KZ?usyK%X07cQH2;&SZ(F4y$ovT-{uS8u~*!)>^%*Kz4k z8yfC={QBn}zn(M4RyQ?X)3AC^%QemErsIv*T$oqwU?2BI$}K8HS-nql(e{ zR*$e3za_BiPxrI&KUlXG5BZO3vMvaM6y3u5{_i+D_y_G*z4<4`&GkP!_}wmUwW!1d zJ*HqBnx^X2>GfO(Yx&N#?3ur6UMq@{t_hkJ714b~6eQ)@+dpe?=f2R?v|_Sh#pH$Q zgDV0b>)amv(hck@X}!9?z%@VjHwo^p)(|yo#FS`6!>cv9da}UHsQmsCpR!Z5E_3{; zO4;R;PTpHjTB(v{=InXXwVeXpkuO_0EYA-1$z7e*C)3=PD(`Twwlp?G8d@?dzta#o zJIx0k?&u4iTjQ1G)DERX3n^H zH?~-H`aN7nwRbz$#O~C#AAmqZu3RT$p&O->Cwa4w;=8)~w{&&!Cr|pnnnmoolPA0R z5k8r9oU#?e9eqphxcGeMb3b0sB{}w@u`+OG)9u0Y*Vj6%#H46UHX=q;TI}%36IV5c zWSVa&Dx%jama@90nbU8_l;UmE#>;Y;AcyY zYw=l3aoMdTr!bMb*|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