forked from cadence/out-of-your-element
Fix joining guessed @mentions to room
This commit is contained in:
parent
4313aa668d
commit
cd2e012b8e
3 changed files with 12 additions and 5 deletions
|
@ -505,12 +505,13 @@ async function eventToMessage(event, guild, di) {
|
|||
content = displayNameRunoff + replyLine + content
|
||||
|
||||
// Handling written @mentions: we need to look for candidate Discord members to join to the room
|
||||
let writtenMentionMatch = content.match(/(?:^|[^"<>/A-Za-z0-9])@([A-Za-z][A-Za-z0-9._\[\]\(\)-]+):?/)
|
||||
let writtenMentionMatch = content.match(/(?:^|[^"<>/A-Za-z0-9])@([A-Za-z][A-Za-z0-9._\[\]\(\)-]+):?/d) // /d flag for indices requires node.js 16+
|
||||
if (writtenMentionMatch) {
|
||||
const results = await di.snow.guild.searchGuildMembers(guild.id, {query: writtenMentionMatch[1]})
|
||||
if (results[0]) {
|
||||
assert(results[0].user)
|
||||
content = content.slice(0, writtenMentionMatch.index) + `<@${results[0].user.id}>` + content.slice(writtenMentionMatch.index + writtenMentionMatch[0].length)
|
||||
// @ts-ignore - typescript doesn't know about indices yet
|
||||
content = content.slice(0, writtenMentionMatch.indices[1][0]-1) + `<@${results[0].user.id}>` + content.slice(writtenMentionMatch.indices[1][1])
|
||||
ensureJoined.push(results[0].user)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2179,7 +2179,7 @@ test("event2message: guessed @mentions may join members to mention", async t =>
|
|||
sender: "@cadence:cadence.moe",
|
||||
content: {
|
||||
msgtype: "m.text",
|
||||
body: "@subtext: what food would you like to order?"
|
||||
body: "hey @subtext, what food would you like to order?"
|
||||
},
|
||||
event_id: "$u5gSwSzv_ZQS3eM00mnTBCor8nx_A_AwuQz7e59PZk8",
|
||||
room_id: "!kLRqKKUQXcibIMtOpl:cadence.moe"
|
||||
|
@ -2202,7 +2202,7 @@ test("event2message: guessed @mentions may join members to mention", async t =>
|
|||
messagesToEdit: [],
|
||||
messagesToSend: [{
|
||||
username: "cadence [they]",
|
||||
content: "<@321876634777218072> what food would you like to order?",
|
||||
content: "hey <@321876634777218072>, what food would you like to order?",
|
||||
avatar_url: undefined
|
||||
}],
|
||||
ensureJoined: [subtext.user]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue