Fix displayname/display_name discrepancy

This commit is contained in:
Cadence Ember 2023-10-04 23:23:57 +13:00
parent ac98ed02ad
commit a49b46381c
8 changed files with 122 additions and 31 deletions

View file

@ -32,7 +32,7 @@ test("edit2changes: edit by webhook", async t => {
test("edit2changes: bot response", async t => {
const {senderMxid, eventsToRedact, eventsToReplace, eventsToSend} = await editToChanges(data.message_update.bot_response, data.guild.general, {
async getJoinedMembers(roomID) {
t.equal(roomID, "!uCtjHhfGlYbVnPVlkG:cadence.moe")
t.equal(roomID, "!hYnGGlPHlbujVVfktC:cadence.moe")
return new Promise(resolve => {
setTimeout(() => {
resolve({

View file

@ -189,7 +189,7 @@ async function messageToEvent(message, guild, options = {}, di) {
if (!userRegex.some(rx => mxid.match(rx))) {
const localpart = mxid.match(/@([^:]*)/)
assert(localpart)
const displayName = member.displayname || localpart[1]
const displayName = member.display_name || localpart[1]
if (writtenMentionsText.includes(localpart[1].toLowerCase()) || writtenMentionsText.includes(displayName.toLowerCase())) addMention(mxid)
}
}

View file

@ -273,9 +273,69 @@ test("message2event: simple reply to matrix user, reply fallbacks disabled", asy
}])
})
test("message2event: simple written @mentions for matrix users", async t => {
let called = 0
test("message2event: simple written @mention for matrix user", async t => {
const events = await messageToEvent(data.message.simple_written_at_mention_for_matrix, data.guild.general, {}, {
api: {
async getJoinedMembers(roomID) {
t.equal(roomID, "!rEOspnYqdOalaIFniV:cadence.moe")
return new Promise(resolve => {
setTimeout(() => {
resolve({
joined: {
"@she_who_brings_destruction:matrix.org": {
avatar_url: "mxc://matrix.org/FKcfnfFZlEhspeMsERfYtCuO",
display_name: "ash (Old)"
},
"@tomskeleton:cadence.moe": {
avatar_url: "mxc://cadence.moe/OvYYicuOwfAACKaXKJCUPbVz",
display_name: "tomskeleton"
},
"@she_who_brings_destruction:cadence.moe": {
avatar_url: "mxc://cadence.moe/XDXLMbkieETPrjFupoeiwyyq",
display_name: "ash"
},
"@_ooye_bot:cadence.moe": {
avatar_url: "mxc://cadence.moe/jlrgFjYQHzfBvORedOmYqXVz",
display_name: "Out Of Your Element"
},
"@cadence:cadence.moe": {
avatar_url: "mxc://cadence.moe/GJDPWiryxIhyRBNJzRNYzAlh",
display_name: "cadence [they]"
},
"@_ooye_tomskeleton:cadence.moe": {
avatar_url: "mxc://cadence.moe/SdSrjjsrNVdyPTAKEGQUhKUK",
display_name: "tomskeleton"
},
"@_ooye_queergasm:cadence.moe": {
avatar_url: "mxc://cadence.moe/KqXYGbUqhPPJKifLmfpoLnmB",
display_name: "queergasm"
},
"@_ooye_.subtext:cadence.moe": {
avatar_url: "mxc://cadence.moe/heoCvaUmfCdpxdzaChwwkpEp",
display_name: ".subtext"
}
}
})
})
})
}
}
})
t.deepEqual(events, [{
$type: "m.room.message",
"m.mentions": {
user_ids: [
"@she_who_brings_destruction:cadence.moe"
]
},
msgtype: "m.text",
body: "@ash do you need anything from the store btw as I'm heading there after gym"
}])
})
test("message2event: advanced written @mentions for matrix users", async t => {
let called = 0
const events = await messageToEvent(data.message.advanced_written_at_mention_for_matrix, data.guild.general, {}, {
api: {
async getJoinedMembers(roomID) {
called++
@ -285,19 +345,19 @@ test("message2event: simple written @mentions for matrix users", async t => {
resolve({
joined: {
"@cadence:cadence.moe": {
displayname: "cadence [they]",
display_name: "cadence [they]",
avatar_url: "whatever"
},
"@huckleton:cadence.moe": {
displayname: "huck",
display_name: "huck",
avatar_url: "whatever"
},
"@_ooye_botrac4r:cadence.moe": {
displayname: "botrac4r",
display_name: "botrac4r",
avatar_url: "whatever"
},
"@_ooye_bot:cadence.moe": {
displayname: "Out Of Your Element",
display_name: "Out Of Your Element",
avatar_url: "whatever"
}
}
@ -361,7 +421,7 @@ test("message2event: type 4 channel name change", async t => {
test("message2event: thread start message reference", async t => {
const events = await messageToEvent(data.special_message.thread_start_context, data.guild.general, {}, {
api: {
getEvent: mockGetEvent(t, "!PnyBKvUBOhjuCucEfk:cadence.moe", "$FchUVylsOfmmbj-VwEs5Z9kY49_dt2zd0vWfylzy5Yo", {
getEvent: mockGetEvent(t, "!BnKuBPCvyfOkhcUjEu:cadence.moe", "$FchUVylsOfmmbj-VwEs5Z9kY49_dt2zd0vWfylzy5Yo", {
"type": "m.room.message",
"sender": "@_ooye_kyuugryphon:cadence.moe",
"content": {

View file

@ -26,6 +26,6 @@ test("orm: from: get pluck works", t => {
})
test("orm: from: join and pluck works", t => {
const mxid = from("sim").join("sim_member", "mxid").and("WHERE discord_id = ? AND room_id = ?").pluck("mxid").get("771520384671416320", "!uCtjHhfGlYbVnPVlkG:cadence.moe")
const mxid = from("sim").join("sim_member", "mxid").and("WHERE discord_id = ? AND room_id = ?").pluck("mxid").get("771520384671416320", "!hYnGGlPHlbujVVfktC:cadence.moe")
t.equal(mxid, "@_ooye_bojack_horseman:cadence.moe")
})

View file

@ -917,10 +917,10 @@ test("event2message: editing a plaintext body message", async t => {
"transaction_id": "m1693223873796.842"
},
"event_id": "$KxGwvVNzNcmlVbiI2m5kX-jMFNi3Jle71-uu1j7P7vM",
"room_id": "!PnyBKvUBOhjuCucEfk:cadence.moe"
"room_id": "!BnKuBPCvyfOkhcUjEu:cadence.moe"
}, data.guild.general, {
api: {
getEvent: mockGetEvent(t, "!PnyBKvUBOhjuCucEfk:cadence.moe", "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs", {
getEvent: mockGetEvent(t, "!BnKuBPCvyfOkhcUjEu:cadence.moe", "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs", {
type: "m.room.message",
sender: "@cadence:cadence.moe",
content: {
@ -968,10 +968,10 @@ test("event2message: editing a plaintext message to be longer", async t => {
"transaction_id": "m1693223873796.842"
},
"event_id": "$KxGwvVNzNcmlVbiI2m5kX-jMFNi3Jle71-uu1j7P7vM",
"room_id": "!PnyBKvUBOhjuCucEfk:cadence.moe"
"room_id": "!BnKuBPCvyfOkhcUjEu:cadence.moe"
}, data.guild.general, {
api: {
getEvent: mockGetEvent(t, "!PnyBKvUBOhjuCucEfk:cadence.moe", "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs", {
getEvent: mockGetEvent(t, "!BnKuBPCvyfOkhcUjEu:cadence.moe", "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs", {
type: "m.room.message",
sender: "@cadence:cadence.moe",
content: {
@ -1023,10 +1023,10 @@ test("event2message: editing a plaintext message to be shorter", async t => {
"transaction_id": "m1693223873796.842"
},
"event_id": "$KxGwvVNzNcmlVbiI2m5kX-jMFNi3Jle71-uu1j7P7vM",
"room_id": "!PnyBKvUBOhjuCucEfk:cadence.moe"
"room_id": "!BnKuBPCvyfOkhcUjEu:cadence.moe"
}, data.guild.general, {
api: {
getEvent: mockGetEvent(t, "!PnyBKvUBOhjuCucEfk:cadence.moe", "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSt", {
getEvent: mockGetEvent(t, "!BnKuBPCvyfOkhcUjEu:cadence.moe", "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSt", {
type: "m.room.message",
sender: "@cadence:cadence.moe",
content: {
@ -1078,10 +1078,10 @@ test("event2message: editing a formatted body message", async t => {
"transaction_id": "m1693223873796.842"
},
"event_id": "$KxGwvVNzNcmlVbiI2m5kX-jMFNi3Jle71-uu1j7P7vM",
"room_id": "!PnyBKvUBOhjuCucEfk:cadence.moe"
"room_id": "!BnKuBPCvyfOkhcUjEu:cadence.moe"
}, data.guild.general, {
api: {
getEvent: mockGetEvent(t, "!PnyBKvUBOhjuCucEfk:cadence.moe", "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs", {
getEvent: mockGetEvent(t, "!BnKuBPCvyfOkhcUjEu:cadence.moe", "$7LIdiJCEqjcWUrpzWzS8TELOlFfBEe4ytgS7zn2lbSs", {
type: "m.room.message",
sender: "@cadence:cadence.moe",
content: {
@ -1278,7 +1278,7 @@ test("event2message: with layered rich replies, the preview should only be the r
msgtype: "m.text",
body: "> <@cadence:cadence.moe> two\n\nthree",
format: "org.matrix.custom.html",
formatted_body: "<mx-reply><blockquote><a href=\"https://matrix.to/#/!PnyBKvUBOhjuCucEfk:cadence.moe/$f-noT-d-Eo_Xgpc05Ww89ErUXku4NwKWYGHLzWKo1kU?via=cadence.moe\">In reply to</a> <a href=\"https://matrix.to/#/@cadence:cadence.moe\">@cadence:cadence.moe</a><br>two</blockquote></mx-reply>three",
formatted_body: "<mx-reply><blockquote><a href=\"https://matrix.to/#/!BnKuBPCvyfOkhcUjEu:cadence.moe/$f-noT-d-Eo_Xgpc05Ww89ErUXku4NwKWYGHLzWKo1kU?via=cadence.moe\">In reply to</a> <a href=\"https://matrix.to/#/@cadence:cadence.moe\">@cadence:cadence.moe</a><br>two</blockquote></mx-reply>three",
"m.relates_to": {
"m.in_reply_to": {
event_id: "$Fxy8SMoJuTduwReVkHZ1uHif9EuvNx36Hg79cltiA04"
@ -1296,7 +1296,7 @@ test("event2message: with layered rich replies, the preview should only be the r
"msgtype": "m.text",
"body": "> <@cadence:cadence.moe> one\n\ntwo",
"format": "org.matrix.custom.html",
"formatted_body": "<mx-reply><blockquote><a href=\"https://matrix.to/#/!PnyBKvUBOhjuCucEfk:cadence.moe/$5UtboIC30EFlAYD_Oh0pSYVW8JqOp6GsDIJZHtT0Wls?via=cadence.moe\">In reply to</a> <a href=\"https://matrix.to/#/@cadence:cadence.moe\">@cadence:cadence.moe</a><br>one</blockquote></mx-reply>two",
"formatted_body": "<mx-reply><blockquote><a href=\"https://matrix.to/#/!BnKuBPCvyfOkhcUjEu:cadence.moe/$5UtboIC30EFlAYD_Oh0pSYVW8JqOp6GsDIJZHtT0Wls?via=cadence.moe\">In reply to</a> <a href=\"https://matrix.to/#/@cadence:cadence.moe\">@cadence:cadence.moe</a><br>one</blockquote></mx-reply>two",
"m.relates_to": {
"m.in_reply_to": {
"event_id": "$5UtboIC30EFlAYD_Oh0pSYVW8JqOp6GsDIJZHtT0Wls"
@ -1445,7 +1445,7 @@ test("event2message: mentioning bridged rooms works", async t => {
msgtype: "m.text",
body: "wrong body",
format: "org.matrix.custom.html",
formatted_body: `I'm just <a href="https://matrix.to/#/!PnyBKvUBOhjuCucEfk:cadence.moe">worm-form</a> testing channel mentions`
formatted_body: `I'm just <a href="https://matrix.to/#/!BnKuBPCvyfOkhcUjEu:cadence.moe">worm-form</a> testing channel mentions`
},
event_id: "$g07oYSZFWBkxohNEfywldwgcWj1hbhDzQ1sBAKvqOOU",
origin_server_ts: 1688301929913,
@ -1643,7 +1643,7 @@ test("event2message: text attachments work", async t => {
},
sender: "@cadence:cadence.moe",
event_id: "$c2WVyP6KcfAqh5imOa8e0xzt2C8JTR-cWbEd3GargEQ",
room_id: "!PnyBKvUBOhjuCucEfk:cadence.moe"
room_id: "!BnKuBPCvyfOkhcUjEu:cadence.moe"
}),
{
messagesToDelete: [],
@ -1677,7 +1677,7 @@ test("event2message: image attachments work", async t => {
url: "mxc://cadence.moe/IvxVJFLEuksCNnbojdSIeEvn"
},
event_id: "$CXQy3Wmg1A-gL_xAesC1HQcQTEXwICLdSwwUx55FBTI",
room_id: "!PnyBKvUBOhjuCucEfk:cadence.moe"
room_id: "!BnKuBPCvyfOkhcUjEu:cadence.moe"
}),
{
messagesToDelete: [],
@ -1726,7 +1726,7 @@ test("event2message: encrypted image attachments work", async t => {
}
},
event_id: "$JNhONhXO-5jrztZz8b7mbTMJasbU78TwQr4tog-3Mnk",
room_id: "!PnyBKvUBOhjuCucEfk:cadence.moe"
room_id: "!BnKuBPCvyfOkhcUjEu:cadence.moe"
}),
{
messagesToDelete: [],
@ -1770,7 +1770,7 @@ test("event2message: stickers work", async t => {
}
},
event_id: "$PdI-KjdQ8Z_Tb4x9_7wKRPZCsrrXym4BXtbAPekypuM",
room_id: "!PnyBKvUBOhjuCucEfk:cadence.moe"
room_id: "!BnKuBPCvyfOkhcUjEu:cadence.moe"
}),
{
messagesToDelete: [],

View file

@ -103,7 +103,7 @@ function getStateEvent(roomID, type, key) {
/**
* "Any of the AS's users must be in the room. This API is primarily for Application Services and should be faster to respond than /members as it can be implemented more efficiently on the server."
* @param {string} roomID
* @returns {Promise<{joined: {[mxid: string]: Ty.R.RoomMember}}>}
* @returns {Promise<{joined: {[mxid: string]: {avatar_url?: string, display_name?: string}}}>}
*/
function getJoinedMembers(roomID) {
return mreq.mreq("GET", `/client/v3/rooms/${roomID}/joined_members`)

View file

@ -421,6 +421,36 @@ module.exports = {
components: []
},
simple_written_at_mention_for_matrix: {
id: "1159030564049915915",
type: 0,
content: "@ash do you need anything from the store btw as I'm heading there after gym",
channel_id: "297272183716052993",
author: {
id: "221902610066571260",
username: "subtextual",
avatar: "c108f921e2fb84981197fe2b895e6a78",
discriminator: "0",
public_flags: 0,
flags: 0,
banner: null,
accent_color: null,
global_name: "subtext",
avatar_decoration_data: null,
banner_color: null
},
attachments: [],
embeds: [],
mentions: [],
mention_roles: [],
pinned: false,
mention_everyone: false,
tts: false,
timestamp: "2023-10-04T07:33:40.216000+00:00",
edited_timestamp: null,
flags: 0,
components: []
},
advanced_written_at_mention_for_matrix: {
id: "1126739682080858234",
type: 0,
content: "@Cadence, tell me about @Phil, the creator of the Chin Trick, who has become ever more powerful under the mentorship of @botrac4r and @huck",

View file

@ -5,9 +5,10 @@ INSERT INTO guild_space (guild_id, space_id) VALUES
INSERT INTO channel_room (channel_id, room_id, name, nick, thread_parent, custom_avatar) VALUES
('112760669178241024', '!kLRqKKUQXcibIMtOpl:cadence.moe', 'heave', 'main', NULL, NULL),
('497161350934560778', '!edUxjVdzgUvXDUIQCK:cadence.moe', 'amanda-spam', NULL, NULL, NULL),
('160197704226439168', '!uCtjHhfGlYbVnPVlkG:cadence.moe', 'the-stanley-parable-channel', 'bots', NULL, NULL),
('1100319550446252084', '!PnyBKvUBOhjuCucEfk:cadence.moe', 'worm-farm', NULL, NULL, NULL);
('497161350934560778', '!CzvdIdUQXgUjDVKxeU:cadence.moe', 'amanda-spam', NULL, NULL, NULL),
('160197704226439168', '!hYnGGlPHlbujVVfktC:cadence.moe', 'the-stanley-parable-channel', 'bots', NULL, NULL),
('1100319550446252084', '!BnKuBPCvyfOkhcUjEu:cadence.moe', 'worm-farm', NULL, NULL, NULL),
('297272183716052993', '!rEOspnYqdOalaIFniV:cadence.moe', 'general', NULL, NULL, NULL);
INSERT INTO sim (discord_id, sim_name, localpart, mxid) VALUES
('0', 'bot', '_ooye_bot', '@_ooye_bot:cadence.moe'),
@ -18,7 +19,7 @@ INSERT INTO sim (discord_id, sim_name, localpart, mxid) VALUES
('111604486476181504', 'kyuugryphon', '_ooye_kyuugryphon', '@_ooye_kyuugryphon:cadence.moe');;
INSERT INTO sim_member (mxid, room_id, hashed_profile_content) VALUES
('@_ooye_bojack_horseman:cadence.moe', '!uCtjHhfGlYbVnPVlkG:cadence.moe', NULL);
('@_ooye_bojack_horseman:cadence.moe', '!hYnGGlPHlbujVVfktC:cadence.moe', NULL);
INSERT INTO message_channel (message_id, channel_id) VALUES
('1106366167788044450', '122155380120748034'),
@ -83,7 +84,7 @@ INSERT INTO member_cache (room_id, mxid, displayname, avatar_url) VALUES
('!kLRqKKUQXcibIMtOpl:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', NULL),
('!BpMdOUkWWhFxmTrENV:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'malformed mxc'),
('!fGgIymcYWOqjbSRUdV:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU'),
('!PnyBKvUBOhjuCucEfk:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU'),
('!BnKuBPCvyfOkhcUjEu:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU'),
('!maggESguZBqGBZtSnr:cadence.moe', '@cadence:cadence.moe', 'cadence [they]', 'mxc://cadence.moe/azCAhThKTojXSZJRoWwZmhvU');
COMMIT;