support up to 1 space in written mentions
This commit is contained in:
		
							parent
							
								
									f5ef881cd0
								
							
						
					
					
						commit
						e00eb15f35
					
				
					 3 changed files with 6 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 => {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue