forked from cadence/out-of-your-element
		
	Look harder for username data
This commit is contained in:
		
							parent
							
								
									cf39737b5a
								
							
						
					
					
						commit
						2614493646
					
				
					 4 changed files with 131 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -34,6 +34,7 @@ function getDiscordParseCallbacks(message, guild, useHTML) {
 | 
			
		|||
			const mxid = select("sim", "mxid", {user_id: node.id}).pluck().get()
 | 
			
		||||
			const interaction = message.interaction_metadata || message.interaction
 | 
			
		||||
			const username = message.mentions.find(ment => ment.id === node.id)?.username
 | 
			
		||||
				|| message.referenced_message?.mentions.find(ment => ment.id === node.id)?.username
 | 
			
		||||
				|| (interaction?.user.id === node.id ? interaction.user.username : null)
 | 
			
		||||
				|| node.id
 | 
			
		||||
			if (mxid && useHTML) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -532,6 +532,43 @@ test("message2event: simple reply to matrix user, reply fallbacks disabled", asy
 | 
			
		|||
	}])
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
test("message2event: reply to matrix user with mention", async t => {
 | 
			
		||||
	const events = await messageToEvent(data.message.reply_to_matrix_user_mention, data.guild.general, {}, {
 | 
			
		||||
		api: {
 | 
			
		||||
			getEvent: mockGetEvent(t, "!kLRqKKUQXcibIMtOpl:cadence.moe", "$7P2O_VTQNHvavX5zNJ35DV-dbJB1Ag80tGQP_JzGdhk", {
 | 
			
		||||
				type: "m.room.message",
 | 
			
		||||
				content: {
 | 
			
		||||
					msgtype: "m.text",
 | 
			
		||||
					body: "@_ooye_extremity:cadence.moe you owe me $30",
 | 
			
		||||
					format: "org.matrix.custom.html",
 | 
			
		||||
					formatted_body: "<a href=\"https://matrix.to/#/@_ooye_extremity:cadence.moe\">@_ooye_extremity:cadence.moe</a> you owe me $30"
 | 
			
		||||
				},
 | 
			
		||||
				sender: "@cadence:cadence.moe"
 | 
			
		||||
			})
 | 
			
		||||
		}
 | 
			
		||||
	})
 | 
			
		||||
	t.deepEqual(events, [{
 | 
			
		||||
		$type: "m.room.message",
 | 
			
		||||
		"m.relates_to": {
 | 
			
		||||
			"m.in_reply_to": {
 | 
			
		||||
				event_id: "$7P2O_VTQNHvavX5zNJ35DV-dbJB1Ag80tGQP_JzGdhk"
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
		"m.mentions": {
 | 
			
		||||
			user_ids: [
 | 
			
		||||
				"@cadence:cadence.moe"
 | 
			
		||||
			]
 | 
			
		||||
		},
 | 
			
		||||
		msgtype: "m.text",
 | 
			
		||||
		body: "> okay 🤍 yay 🤍: @extremity: you owe me $30\n\nkys",
 | 
			
		||||
		format: "org.matrix.custom.html",
 | 
			
		||||
		formatted_body:
 | 
			
		||||
			'<mx-reply><blockquote><a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$7P2O_VTQNHvavX5zNJ35DV-dbJB1Ag80tGQP_JzGdhk">In reply to</a> <a href="https://matrix.to/#/@cadence:cadence.moe">okay 🤍 yay 🤍</a>'
 | 
			
		||||
			+ '<br><a href="https://matrix.to/#/@_ooye_extremity:cadence.moe">@extremity</a> you owe me $30</blockquote></mx-reply>'
 | 
			
		||||
			+ 'kys'
 | 
			
		||||
	}])
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
test("message2event: reply with a video", async t => {
 | 
			
		||||
	const events = await messageToEvent(data.message.reply_with_video, data.guild.general, {
 | 
			
		||||
		api: {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										89
									
								
								test/data.js
									
										
									
									
									
								
							
							
						
						
									
										89
									
								
								test/data.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1691,6 +1691,95 @@ module.exports = {
 | 
			
		|||
			attachments: [],
 | 
			
		||||
			guild_id: "112760669178241024"
 | 
			
		||||
		},
 | 
			
		||||
		reply_to_matrix_user_mention: {
 | 
			
		||||
			type: 19,
 | 
			
		||||
			content: "kys",
 | 
			
		||||
			mentions: [],
 | 
			
		||||
			mention_roles: [],
 | 
			
		||||
			attachments: [],
 | 
			
		||||
			embeds: [],
 | 
			
		||||
			timestamp: "2025-08-04T05:31:26.506000+00:00",
 | 
			
		||||
			edited_timestamp: null,
 | 
			
		||||
			flags: 0,
 | 
			
		||||
			components: [],
 | 
			
		||||
			id: "1401799674192723998",
 | 
			
		||||
			channel_id: "112760669178241024",
 | 
			
		||||
			author: {
 | 
			
		||||
				id: "114147806469554185",
 | 
			
		||||
				username: "extremity",
 | 
			
		||||
				avatar: "e0394d500407a8fa93774e1835b8b03a",
 | 
			
		||||
				discriminator: "0",
 | 
			
		||||
				public_flags: 0,
 | 
			
		||||
				flags: 0,
 | 
			
		||||
				banner: null,
 | 
			
		||||
				accent_color: null,
 | 
			
		||||
				global_name: "Extremity",
 | 
			
		||||
				avatar_decoration_data: null,
 | 
			
		||||
				collectibles: null,
 | 
			
		||||
				display_name_styles: null,
 | 
			
		||||
				banner_color: null,
 | 
			
		||||
				clan: null,
 | 
			
		||||
				primary_guild: null
 | 
			
		||||
			},
 | 
			
		||||
			pinned: false,
 | 
			
		||||
			mention_everyone: false,
 | 
			
		||||
			tts: false,
 | 
			
		||||
			message_reference: {
 | 
			
		||||
				type: 0,
 | 
			
		||||
				channel_id: "112760669178241024",
 | 
			
		||||
				message_id: "1401760355339862066",
 | 
			
		||||
				guild_id: "112760669178241024"
 | 
			
		||||
			},
 | 
			
		||||
			referenced_message: {
 | 
			
		||||
				type: 0,
 | 
			
		||||
				content: "<@114147806469554185> you owe me $30",
 | 
			
		||||
				mentions: [
 | 
			
		||||
					{
 | 
			
		||||
						id: "114147806469554185",
 | 
			
		||||
						username: "extremity",
 | 
			
		||||
						avatar: "e0394d500407a8fa93774e1835b8b03a",
 | 
			
		||||
						discriminator: "0",
 | 
			
		||||
						public_flags: 0,
 | 
			
		||||
						flags: 0,
 | 
			
		||||
						banner: null,
 | 
			
		||||
						accent_color: null,
 | 
			
		||||
						global_name: "Extremity",
 | 
			
		||||
						avatar_decoration_data: null,
 | 
			
		||||
						collectibles: null,
 | 
			
		||||
						display_name_styles: null,
 | 
			
		||||
						banner_color: null,
 | 
			
		||||
						clan: null,
 | 
			
		||||
						primary_guild: null
 | 
			
		||||
					}
 | 
			
		||||
				],
 | 
			
		||||
				mention_roles: [],
 | 
			
		||||
				attachments: [],
 | 
			
		||||
				embeds: [],
 | 
			
		||||
				timestamp: "2025-08-04T02:55:12.161000+00:00",
 | 
			
		||||
				edited_timestamp: null,
 | 
			
		||||
				flags: 0,
 | 
			
		||||
				components: [],
 | 
			
		||||
				id: "1401760355339862066",
 | 
			
		||||
				channel_id: "112760669178241024",
 | 
			
		||||
				author: {
 | 
			
		||||
					id: "1152700216189911081",
 | 
			
		||||
					username: "okay 🤍 yay 🤍",
 | 
			
		||||
					avatar: "90bc1d6912252d4fa9f92a2f5f6d347b",
 | 
			
		||||
					discriminator: "0000",
 | 
			
		||||
					public_flags: 0,
 | 
			
		||||
					flags: 0,
 | 
			
		||||
					bot: true,
 | 
			
		||||
					global_name: null,
 | 
			
		||||
					clan: null,
 | 
			
		||||
					primary_guild: null
 | 
			
		||||
				},
 | 
			
		||||
				pinned: false,
 | 
			
		||||
				mention_everyone: false,
 | 
			
		||||
				tts: false,
 | 
			
		||||
				application_id: "684280192553844747",
 | 
			
		||||
				webhook_id: "1152700216189911081"
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
		reply_with_video: {
 | 
			
		||||
			id: "1197621094983676007",
 | 
			
		||||
			type: 19,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -72,7 +72,8 @@ INSERT INTO message_channel (message_id, channel_id) VALUES
 | 
			
		|||
('1191567971970191490', '176333891320283136'),
 | 
			
		||||
('1144874214311067708', '687028734322147344'),
 | 
			
		||||
('1339000288144658482', '176333891320283136'),
 | 
			
		||||
('1381212840957972480', '112760669178241024');
 | 
			
		||||
('1381212840957972480', '112760669178241024'),
 | 
			
		||||
('1401760355339862066', '112760669178241024');
 | 
			
		||||
 | 
			
		||||
INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part, reaction_part, source) VALUES
 | 
			
		||||
('$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg', 'm.room.message', 'm.text', '1126786462646550579', 0, 0, 1),
 | 
			
		||||
| 
						 | 
				
			
			@ -115,7 +116,8 @@ INSERT INTO event_message (event_id, event_type, event_subtype, message_id, part
 | 
			
		|||
('$tBIT8mO7XTTCgIINyiAIy6M2MSoPAdJenRl_RLyYuaE', 'm.room.message', 'm.text', '1191567971970191490', 0, 0, 1),
 | 
			
		||||
('$51gH61p_eJc2RylOdE2lAr4-ogP7dS0WJI62lCFzBvk', 'm.room.message', 'm.text', '1339000288144658482', 0, 0, 0),
 | 
			
		||||
('$AfrB8hzXkDMvuoWjSZkDdFYomjInWH7jMBPkwQMN8AI', 'm.room.message', 'm.text', '1381212840957972480', 0, 1, 1),
 | 
			
		||||
('$43baKEhJfD-RlsFQi0LB16Zxd8yMqp0HSVL00TDQOqM', 'm.room.message', 'm.image', '1381212840957972480', 1, 0, 1);
 | 
			
		||||
('$43baKEhJfD-RlsFQi0LB16Zxd8yMqp0HSVL00TDQOqM', 'm.room.message', 'm.image', '1381212840957972480', 1, 0, 1),
 | 
			
		||||
('$7P2O_VTQNHvavX5zNJ35DV-dbJB1Ag80tGQP_JzGdhk', 'm.room.message', 'm.text', '1401760355339862066', 0, 0, 0);
 | 
			
		||||
 | 
			
		||||
INSERT INTO file (discord_url, mxc_url) VALUES
 | 
			
		||||
('https://cdn.discordapp.com/attachments/497161332244742154/1124628646431297546/image.png', 'mxc://cadence.moe/qXoZktDqNtEGuOCZEADAMvhM'),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue