Compare commits
No commits in common. "fd11e3fd10a69ad00ff82491b667a2ea7902b48a" and "789a90a893d3af38d94baa5c61a68b83e0425f4b" have entirely different histories.
fd11e3fd10
...
789a90a893
7 changed files with 56 additions and 214 deletions
|
@ -9,9 +9,9 @@ test("message2event embeds: nothing but a field", async t => {
|
|||
$type: "m.room.message",
|
||||
"m.mentions": {},
|
||||
msgtype: "m.notice",
|
||||
body: "| ### Amanda 🎵#2192 :online:"
|
||||
+ "\n| willow tree, branch 0"
|
||||
+ "\n| **❯ Uptime:**\n| 3m 55s\n| **❯ Memory:**\n| 64.45MB",
|
||||
body: "> ### Amanda 🎵#2192 :online:"
|
||||
+ "\n> willow tree, branch 0"
|
||||
+ "\n> **❯ Uptime:**\n> 3m 55s\n> **❯ Memory:**\n> 64.45MB",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: '<blockquote><p><strong>Amanda 🎵#2192 <img data-mx-emoticon height=\"32\" src=\"mxc://cadence.moe/LCEqjStXCxvRQccEkuslXEyZ\" title=\":online:\" alt=\":online:\">'
|
||||
+ '<br>willow tree, branch 0</strong>'
|
||||
|
@ -26,14 +26,14 @@ test("message2event embeds: reply with just an embed", async t => {
|
|||
$type: "m.room.message",
|
||||
msgtype: "m.notice",
|
||||
"m.mentions": {},
|
||||
body: "| ## ⏺️ dynastic (@dynastic) https://twitter.com/i/user/719631291747078145"
|
||||
+ "\n| \n| ## https://twitter.com/i/status/1707484191963648161"
|
||||
+ "\n| \n| does anyone know where to find that one video of the really mysterious yam-like object being held up to a bunch of random objects, like clocks, and they have unexplained impossible reactions to it?"
|
||||
+ "\n| \n| ### Retweets"
|
||||
+ "\n| 119"
|
||||
+ "\n| \n| ### Likes"
|
||||
+ "\n| 5581"
|
||||
+ "\n| — Twitter",
|
||||
body: "> ## ⏺️ dynastic (@dynastic) https://twitter.com/i/user/719631291747078145"
|
||||
+ "\n> \n> ## https://twitter.com/i/status/1707484191963648161"
|
||||
+ "\n> \n> does anyone know where to find that one video of the really mysterious yam-like object being held up to a bunch of random objects, like clocks, and they have unexplained impossible reactions to it?"
|
||||
+ "\n> \n> ### Retweets"
|
||||
+ "\n> 119"
|
||||
+ "\n> \n> ### Likes"
|
||||
+ "\n> 5581"
|
||||
+ "\n> — Twitter",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: '<blockquote><p><strong><a href="https://twitter.com/i/user/719631291747078145">⏺️ dynastic (@dynastic)</a></strong></p>'
|
||||
+ '<p><strong><a href="https://twitter.com/i/status/1707484191963648161">https://twitter.com/i/status/1707484191963648161</a></strong>'
|
||||
|
@ -111,12 +111,12 @@ test("message2event embeds: blockquote in embed", async t => {
|
|||
}, {
|
||||
$type: "m.room.message",
|
||||
msgtype: "m.notice",
|
||||
body: "| ## ⏺️ minimus https://matrix.to/#/!qzDBLKlildpzrrOnFZ:cadence.moe/$dVCLyj6kxb3DaAWDtjcv2kdSny8JMMHdDhCMz8mDxVo?via=cadence.moe&via=example.invalid\n| \n| reply draft\n| > The following is a message composed via consensus of the Stinker Council.\n| > \n| > For those who are not currently aware of our existence, we represent the organization known as Wonderland. Our previous mission centered around the assortment and study of puzzling objects, entities and other assorted phenomena. This mission was the focus of our organization for more than 28 years.\n| > \n| > Due to circumstances outside of our control, this directive has now changed. Our new mission will be the extermination of the stinker race.\n| > \n| > There will be no further communication.\n| \n| [Go to Message](https://matrix.to/#/!qzDBLKlildpzrrOnFZ:cadence.moe/$dVCLyj6kxb3DaAWDtjcv2kdSny8JMMHdDhCMz8mDxVo?via=cadence.moe&via=example.invalid)",
|
||||
body: "> ## ⏺️ minimus https://matrix.to/#/!qzDBLKlildpzrrOnFZ:cadence.moe/$dVCLyj6kxb3DaAWDtjcv2kdSny8JMMHdDhCMz8mDxVo?via=cadence.moe&via=example.invalid\n> \n> reply draft\n> > The following is a message composed via consensus of the Stinker Council.\n> > \n> > For those who are not currently aware of our existence, we represent the organization known as Wonderland. Our previous mission centered around the assortment and study of puzzling objects, entities and other assorted phenomena. This mission was the focus of our organization for more than 28 years.\n> > \n> > Due to circumstances outside of our control, this directive has now changed. Our new mission will be the extermination of the stinker race.\n> > \n> > There will be no further communication.\n> \n> [Go to Message](https://matrix.to/#/!qzDBLKlildpzrrOnFZ:cadence.moe/$dVCLyj6kxb3DaAWDtjcv2kdSny8JMMHdDhCMz8mDxVo?via=cadence.moe&via=example.invalid)",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: "<blockquote><p><strong><a href=\"https://matrix.to/#/!qzDBLKlildpzrrOnFZ:cadence.moe/$dVCLyj6kxb3DaAWDtjcv2kdSny8JMMHdDhCMz8mDxVo?via=cadence.moe&via=example.invalid\">⏺️ minimus</a></strong></p><p>reply draft<br><blockquote>The following is a message composed via consensus of the Stinker Council.<br><br>For those who are not currently aware of our existence, we represent the organization known as Wonderland. Our previous mission centered around the assortment and study of puzzling objects, entities and other assorted phenomena. This mission was the focus of our organization for more than 28 years.<br><br>Due to circumstances outside of our control, this directive has now changed. Our new mission will be the extermination of the stinker race.<br><br>There will be no further communication.</blockquote></p><p><a href=\"https://matrix.to/#/!qzDBLKlildpzrrOnFZ:cadence.moe/$dVCLyj6kxb3DaAWDtjcv2kdSny8JMMHdDhCMz8mDxVo?via=cadence.moe&via=example.invalid\">Go to Message</a></p></blockquote>",
|
||||
formatted_body: "<blockquote><p><strong><a href=\"https://matrix.to/#/!qzDBLKlildpzrrOnFZ:cadence.moe/$dVCLyj6kxb3DaAWDtjcv2kdSny8JMMHdDhCMz8mDxVo?via=cadence.moe&via=example.invalid\">⏺️ minimus</a></strong></p><p>reply draft<br><blockquote>The following is a message composed via consensus of the Stinker Council.<br><br>For those who are not currently aware of our existence, we represent the organization known as Wonderland. Our previous mission centered around the assortment and study of puzzling objects, entities and other assorted phenomena. This mission was the focus of our organization for more than 28 years.<br><br>Due to circumstances outside of our control, this directive has now changed. Our new mission will be the extermination of the stinker race.<br><br>There will be no further communication.</blockquote></p><p><a href=\"https://matrix.to/#/!qzDBLKlildpzrrOnFZ:cadence.moe/$dVCLyj6kxb3DaAWDtjcv2kdSny8JMMHdDhCMz8mDxVo?via=cadence.moe&via=example.invalid \">Go to Message</a></p></blockquote>",
|
||||
"m.mentions": {}
|
||||
}])
|
||||
t.equal(called, 2, "should call getStateEvent and getJoinedMembers once each")
|
||||
t.equal(called, 2)
|
||||
})
|
||||
|
||||
test("message2event embeds: crazy html is all escaped", async t => {
|
||||
|
@ -124,12 +124,12 @@ test("message2event embeds: crazy html is all escaped", async t => {
|
|||
t.deepEqual(events, [{
|
||||
$type: "m.room.message",
|
||||
msgtype: "m.notice",
|
||||
body: "| ## ⏺️ <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&) https://a.co/&<script>"
|
||||
+ "\n| \n| ## <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&) https://a.co/&<script>"
|
||||
+ "\n| \n| <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&)"
|
||||
+ "\n| \n| ### <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&)"
|
||||
+ "\n| <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&)"
|
||||
+ "\n| — <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&)",
|
||||
body: "> ## ⏺️ <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&) https://a.co/&<script>"
|
||||
+ "\n> \n> ## <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&) https://a.co/&<script>"
|
||||
+ "\n> \n> <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&)"
|
||||
+ "\n> \n> ### <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&)"
|
||||
+ "\n> <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&)"
|
||||
+ "\n> — <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&)",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: `<blockquote>`
|
||||
+ `<p><strong><a href="https://a.co/&amp;<script>">⏺️ <strong>[<span data-mx-color='#123456'>Hey<script>](https://a.co/&amp;)</a></strong></p>`
|
||||
|
|
|
@ -39,12 +39,13 @@ function getDiscordParseCallbacks(message, guild, useHTML) {
|
|||
return `@${username}:`
|
||||
}
|
||||
},
|
||||
/** @param {{id: string, type: "discordChannel", row: {room_id: string, name: string, nick: string?}?, via: string}} node */
|
||||
// FIXME: type
|
||||
/** @param {{id: string, type: "discordChannel", row: any, via: URLSearchParams}} node */
|
||||
channel: node => {
|
||||
if (!node.row) {
|
||||
return `#[channel-from-an-unknown-server]` // fallback for when this channel is not bridged
|
||||
} else if (useHTML) {
|
||||
return `<a href="https://matrix.to/#/${node.row.room_id}?${node.via}">#${node.row.nick || node.row.name}</a>`
|
||||
return `<a href="https://matrix.to/#/${node.row.room_id}?${node.via.toString()}">#${node.row.nick || node.row.name}</a>`
|
||||
} else {
|
||||
return `#${node.row.nick || node.row.name}`
|
||||
}
|
||||
|
@ -260,14 +261,10 @@ async function messageToEvent(message, guild, options = {}, di) {
|
|||
we generate a partial referenced_message based on what PK provided. we don't need everything, since this will only be used for further message-to-event converting.
|
||||
the following properties are necessary:
|
||||
- content: used for generating the reply fallback
|
||||
- author: used for the top of the reply fallback (only used for discord authors. for matrix authors, repliedToEventSenderMxid is set.)
|
||||
*/
|
||||
message.referenced_message = {
|
||||
content: message.embeds[0].description.replace(/^.*?\)\*\*\s*/, ""),
|
||||
// @ts-ignore
|
||||
author: {
|
||||
username: message.embeds[0].author.name.replace(/\s*↩️\s*$/, "")
|
||||
}
|
||||
message.referenced_message = {
|
||||
content: message.embeds[0].description.replace(/^.*?\)\*\*\s*/, "")
|
||||
}
|
||||
message.embeds.shift()
|
||||
repliedToEventRow = row
|
||||
|
@ -282,20 +279,6 @@ async function messageToEvent(message, guild, options = {}, di) {
|
|||
addMention(repliedToEventSenderMxid)
|
||||
}
|
||||
|
||||
/** @type {Map<string, Promise<string>>} */
|
||||
const viaMemo = new Map()
|
||||
/**
|
||||
* @param {string} roomID
|
||||
* @returns {Promise<string>} string encoded URLSearchParams
|
||||
*/
|
||||
function getViaServersMemo(roomID) {
|
||||
// @ts-ignore
|
||||
if (viaMemo.has(roomID)) return viaMemo.get(roomID)
|
||||
const promise = mxUtils.getViaServersQuery(roomID, di.api).then(p => p.toString())
|
||||
viaMemo.set(roomID, promise)
|
||||
return promise
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate Discord message links to Matrix event links.
|
||||
* If OOYE has handled this message in the past, this is an instant database lookup.
|
||||
|
@ -312,13 +295,12 @@ async function messageToEvent(message, guild, options = {}, di) {
|
|||
const roomID = select("channel_room", "room_id", {channel_id: channelID}).pluck().get()
|
||||
if (roomID) {
|
||||
const eventID = select("event_message", "event_id", {message_id: messageID}).pluck().get()
|
||||
const via = await getViaServersMemo(roomID)
|
||||
if (eventID && roomID) {
|
||||
result = `https://matrix.to/#/${roomID}/${eventID}?${via}`
|
||||
result = `https://matrix.to/#/${roomID}/${eventID}`
|
||||
} else {
|
||||
const ts = dUtils.snowflakeToTimestampExact(messageID)
|
||||
const {event_id} = await di.api.getEventForTimestamp(roomID, ts)
|
||||
result = `https://matrix.to/#/${roomID}/${event_id}?${via}`
|
||||
result = `https://matrix.to/#/${roomID}/${event_id}`
|
||||
}
|
||||
} else {
|
||||
result = `${match[0]} [event is from another server]`
|
||||
|
@ -355,7 +337,7 @@ async function messageToEvent(message, guild, options = {}, di) {
|
|||
if (node.type === "discordChannel") {
|
||||
node.row = select("channel_room", ["room_id", "name", "nick"], {channel_id: node.id}).get()
|
||||
if (node.row?.room_id) {
|
||||
node.via = await getViaServersMemo(node.row.room_id)
|
||||
node.via = await mxUtils.getViaServersQuery(node.row.room_id, di.api)
|
||||
}
|
||||
}
|
||||
if (Array.isArray(node.content)) {
|
||||
|
@ -538,7 +520,7 @@ async function messageToEvent(message, guild, options = {}, di) {
|
|||
|
||||
if (embed.footer?.text) rep.addLine(`— ${embed.footer.text}`, tag`— ${embed.footer.text}`)
|
||||
let {body, formatted_body: html} = rep.get()
|
||||
body = body.split("\n").map(l => "| " + l).join("\n")
|
||||
body = body.split("\n").map(l => "> " + l).join("\n")
|
||||
html = `<blockquote>${html}</blockquote>`
|
||||
|
||||
// Send as m.notice to apply the usual automated/subtle appearance, showing this wasn't actually typed by the person
|
||||
|
|
|
@ -29,8 +29,8 @@ function mockGetEvent(t, roomID_in, eventID_in, outer) {
|
|||
}
|
||||
}
|
||||
|
||||
test("message2event: pk reply to matrix is converted to native matrix reply", async t => {
|
||||
const events = await messageToEvent(data.pk_message.pk_reply_to_matrix, {}, {}, {
|
||||
test("message2event: pk reply is converted to native matrix reply", async t => {
|
||||
const events = await messageToEvent(data.pk_message.pk_reply, {}, {}, {
|
||||
api: {
|
||||
getEvent: mockGetEvent(t, "!TqlyQmifxGUggEmdBN:cadence.moe", "$NB6nPgO2tfXyIwwDSF0Ga0BUrsgX1S-0Xl-jAvI8ucU", {
|
||||
type: "m.room.message",
|
||||
|
@ -62,33 +62,3 @@ test("message2event: pk reply to matrix is converted to native matrix reply", as
|
|||
}
|
||||
}])
|
||||
})
|
||||
|
||||
test("message2event: pk reply to discord is converted to native matrix reply", async t => {
|
||||
const events = await messageToEvent(data.pk_message.pk_reply_to_discord, {}, {}, {
|
||||
api: {
|
||||
getEvent: mockGetEvent(t, "!TqlyQmifxGUggEmdBN:cadence.moe", "$NB6nPgO2tfXyIwwDSF0Ga0BUrsgX1S-0Xl-jAvI8ucU", {
|
||||
type: "m.room.message",
|
||||
sender: "@_ooye_.wing.:cadence.moe",
|
||||
content: {
|
||||
msgtype: "m.text",
|
||||
body: "some text"
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
t.deepEqual(events, [{
|
||||
$type: "m.room.message",
|
||||
msgtype: "m.text",
|
||||
"m.mentions": {},
|
||||
body: "> wing: some text\n\nthis is a reply",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: '<mx-reply><blockquote><a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$mtR8cJqM4fKno1bVsm8F4wUVqSntt2sq6jav1lyavuA">In reply to</a> wing<br>'
|
||||
+ "some text</blockquote></mx-reply>"
|
||||
+ "this is a reply",
|
||||
"m.relates_to": {
|
||||
"m.in_reply_to": {
|
||||
event_id: "$mtR8cJqM4fKno1bVsm8F4wUVqSntt2sq6jav1lyavuA"
|
||||
}
|
||||
}
|
||||
}])
|
||||
})
|
||||
|
|
|
@ -96,7 +96,7 @@ test("message2event: simple room mention", async t => {
|
|||
format: "org.matrix.custom.html",
|
||||
formatted_body: '<a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe?via=cadence.moe&via=matrix.org">#main</a>'
|
||||
}])
|
||||
t.equal(called, 2, "should call getStateEvent and getJoinedMembers once each")
|
||||
t.equal(called, 2)
|
||||
})
|
||||
|
||||
test("message2event: unknown room mention", async t => {
|
||||
|
@ -134,41 +134,15 @@ test("message2event: manually constructed unknown roles should use fallback", as
|
|||
})
|
||||
|
||||
test("message2event: simple message link", async t => {
|
||||
let called = 0
|
||||
const events = await messageToEvent(data.message.simple_message_link, data.guild.general, {}, {
|
||||
api: {
|
||||
async getStateEvent(roomID, type, key) {
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {
|
||||
users: {
|
||||
"@_ooye_bot:cadence.moe": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
async getJoinedMembers(roomID) {
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
return {
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
"@user:super.invalid": {display_name: null, avatar_url: null}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
const events = await messageToEvent(data.message.simple_message_link, data.guild.general, {})
|
||||
t.deepEqual(events, [{
|
||||
$type: "m.room.message",
|
||||
"m.mentions": {},
|
||||
msgtype: "m.text",
|
||||
body: "https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg?via=cadence.moe&via=super.invalid",
|
||||
body: "https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: '<a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg?via=cadence.moe&via=super.invalid">https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg?via=cadence.moe&via=super.invalid</a>'
|
||||
formatted_body: '<a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg">https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg</a>'
|
||||
}])
|
||||
t.equal(called, 2, "should call getStateEvent and getJoinedMembers once each")
|
||||
})
|
||||
|
||||
test("message2event: message link that OOYE doesn't know about", async t => {
|
||||
|
@ -182,27 +156,6 @@ test("message2event: message link that OOYE doesn't know about", async t => {
|
|||
event_id: "$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U",
|
||||
origin_server_ts: 1613287812754
|
||||
}
|
||||
},
|
||||
async getStateEvent(roomID, type, key) { // for ?via calculation
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
t.equal(type, "m.room.power_levels")
|
||||
t.equal(key, "")
|
||||
return {
|
||||
users: {
|
||||
"@_ooye_bot:cadence.moe": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
async getJoinedMembers(roomID) { // for ?via calculation
|
||||
called++
|
||||
t.equal(roomID, "!kLRqKKUQXcibIMtOpl:cadence.moe")
|
||||
return {
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
"@user:matrix.org": {display_name: null, avatar_url: null}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -211,12 +164,12 @@ test("message2event: message link that OOYE doesn't know about", async t => {
|
|||
"m.mentions": {},
|
||||
msgtype: "m.text",
|
||||
body: "Me: I'll scroll up to find a certain message I'll send\n_scrolls up and clicks message links for god knows how long_\n_completely forgets what they were looking for and simply begins scrolling up to find some fun moments_\n_stumbles upon:_ "
|
||||
+ "https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U?via=cadence.moe&via=matrix.org",
|
||||
+ "https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: "Me: I'll scroll up to find a certain message I'll send<br><em>scrolls up and clicks message links for god knows how long</em><br><em>completely forgets what they were looking for and simply begins scrolling up to find some fun moments</em><br><em>stumbles upon:</em> "
|
||||
+ '<a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U?via=cadence.moe&via=matrix.org">https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U?via=cadence.moe&via=matrix.org</a>'
|
||||
+ '<a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U">https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$E8IQDGFqYzOU7BwY5Z74Bg-cwaU9OthXSroaWtgYc7U</a>'
|
||||
}])
|
||||
t.equal(called, 3, "getEventForTimestamp, getStateEvent, and getJoinedMembers should be called once each")
|
||||
t.equal(called, 1, "getEventForTimestamp should be called once")
|
||||
})
|
||||
|
||||
test("message2event: message link from another server", async t => {
|
||||
|
|
|
@ -6,8 +6,6 @@ const passthrough = require("../../passthrough")
|
|||
const {discord, sync, db, select} = passthrough
|
||||
/** @type {import("../../matrix/read-registration")} */
|
||||
const reg = sync.require("../../matrix/read-registration.js")
|
||||
/** @type {import("../../m2d/converters/utils")} */
|
||||
const mxUtils = sync.require("../../m2d/converters/utils")
|
||||
|
||||
const userRegex = reg.namespaces.users.map(u => new RegExp(u.regex))
|
||||
|
||||
|
@ -31,9 +29,8 @@ async function threadToAnnouncement(parentRoomID, threadRoomID, creatorMxid, thr
|
|||
|
||||
const msgtype = creatorMxid ? "m.emote" : "m.text"
|
||||
const template = creatorMxid ? "started a thread:" : "Thread started:"
|
||||
const via = await mxUtils.getViaServersQuery(threadRoomID, di.api)
|
||||
let body = `${template} ${thread.name} https://matrix.to/#/${threadRoomID}?${via.toString()}`
|
||||
let html = `${template} <a href="https://matrix.to/#/${threadRoomID}?${via.toString()}">${thread.name}</a>`
|
||||
let body = `${template} ${thread.name} https://matrix.to/#/${threadRoomID}`
|
||||
let html = `${template} <a href="https://matrix.to/#/${threadRoomID}">${thread.name}</a>`
|
||||
|
||||
return {
|
||||
msgtype,
|
||||
|
|
|
@ -29,34 +29,16 @@ function mockGetEvent(t, roomID_in, eventID_in, outer) {
|
|||
}
|
||||
}
|
||||
|
||||
const viaApi = {
|
||||
async getStateEvent(roomID, type, key) {
|
||||
return {
|
||||
users: {
|
||||
"@_ooye_bot:cadence.moe": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
async getJoinedMembers(roomID) {
|
||||
return {
|
||||
joined: {
|
||||
"@_ooye_bot:cadence.moe": {display_name: null, avatar_url: null},
|
||||
"@user:matrix.org": {display_name: null, avatar_url: null}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test("thread2announcement: no known creator, no branched from event", async t => {
|
||||
const content = await threadToAnnouncement("!parent", "!thread", null, {
|
||||
name: "test thread",
|
||||
id: "-1"
|
||||
}, {api: viaApi})
|
||||
})
|
||||
t.deepEqual(content, {
|
||||
msgtype: "m.text",
|
||||
body: "Thread started: test thread https://matrix.to/#/!thread?via=cadence.moe&via=matrix.org",
|
||||
body: "Thread started: test thread https://matrix.to/#/!thread",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: `Thread started: <a href="https://matrix.to/#/!thread?via=cadence.moe&via=matrix.org">test thread</a>`,
|
||||
formatted_body: `Thread started: <a href="https://matrix.to/#/!thread">test thread</a>`,
|
||||
"m.mentions": {}
|
||||
})
|
||||
})
|
||||
|
@ -65,12 +47,12 @@ test("thread2announcement: known creator, no branched from event", async t => {
|
|||
const content = await threadToAnnouncement("!parent", "!thread", "@_ooye_crunch_god:cadence.moe", {
|
||||
name: "test thread",
|
||||
id: "-1"
|
||||
}, {api: viaApi})
|
||||
})
|
||||
t.deepEqual(content, {
|
||||
msgtype: "m.emote",
|
||||
body: "started a thread: test thread https://matrix.to/#/!thread?via=cadence.moe&via=matrix.org",
|
||||
body: "started a thread: test thread https://matrix.to/#/!thread",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: `started a thread: <a href="https://matrix.to/#/!thread?via=cadence.moe&via=matrix.org">test thread</a>`,
|
||||
formatted_body: `started a thread: <a href="https://matrix.to/#/!thread">test thread</a>`,
|
||||
"m.mentions": {}
|
||||
})
|
||||
})
|
||||
|
@ -88,15 +70,14 @@ test("thread2announcement: no known creator, branched from discord event", async
|
|||
msgtype: 'm.text',
|
||||
body: 'testing testing testing'
|
||||
}
|
||||
}),
|
||||
...viaApi
|
||||
})
|
||||
}
|
||||
})
|
||||
t.deepEqual(content, {
|
||||
msgtype: "m.text",
|
||||
body: "Thread started: test thread https://matrix.to/#/!thread?via=cadence.moe&via=matrix.org",
|
||||
body: "Thread started: test thread https://matrix.to/#/!thread",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: `Thread started: <a href="https://matrix.to/#/!thread?via=cadence.moe&via=matrix.org">test thread</a>`,
|
||||
formatted_body: `Thread started: <a href="https://matrix.to/#/!thread">test thread</a>`,
|
||||
"m.mentions": {},
|
||||
"m.relates_to": {
|
||||
"m.in_reply_to": {
|
||||
|
@ -119,15 +100,14 @@ test("thread2announcement: known creator, branched from discord event", async t
|
|||
msgtype: 'm.text',
|
||||
body: 'testing testing testing'
|
||||
}
|
||||
}),
|
||||
...viaApi
|
||||
})
|
||||
}
|
||||
})
|
||||
t.deepEqual(content, {
|
||||
msgtype: "m.emote",
|
||||
body: "started a thread: test thread https://matrix.to/#/!thread?via=cadence.moe&via=matrix.org",
|
||||
body: "started a thread: test thread https://matrix.to/#/!thread",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: `started a thread: <a href="https://matrix.to/#/!thread?via=cadence.moe&via=matrix.org">test thread</a>`,
|
||||
formatted_body: `started a thread: <a href="https://matrix.to/#/!thread">test thread</a>`,
|
||||
"m.mentions": {},
|
||||
"m.relates_to": {
|
||||
"m.in_reply_to": {
|
||||
|
@ -150,15 +130,14 @@ test("thread2announcement: no known creator, branched from matrix event", async
|
|||
body: "so can you reply to my webhook uwu"
|
||||
},
|
||||
sender: "@cadence:cadence.moe"
|
||||
}),
|
||||
...viaApi
|
||||
})
|
||||
}
|
||||
})
|
||||
t.deepEqual(content, {
|
||||
msgtype: "m.text",
|
||||
body: "Thread started: test thread https://matrix.to/#/!thread?via=cadence.moe&via=matrix.org",
|
||||
body: "Thread started: test thread https://matrix.to/#/!thread",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: `Thread started: <a href="https://matrix.to/#/!thread?via=cadence.moe&via=matrix.org">test thread</a>`,
|
||||
formatted_body: `Thread started: <a href="https://matrix.to/#/!thread">test thread</a>`,
|
||||
"m.mentions": {
|
||||
user_ids: ["@cadence:cadence.moe"]
|
||||
},
|
||||
|
|
41
test/data.js
41
test/data.js
|
@ -1765,7 +1765,7 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
pk_message: {
|
||||
pk_reply_to_matrix: {
|
||||
pk_reply: {
|
||||
id: "1202543812644306965",
|
||||
type: 0,
|
||||
content: "this is a reply",
|
||||
|
@ -1803,45 +1803,6 @@ module.exports = {
|
|||
components: [],
|
||||
application_id: "466378653216014359",
|
||||
webhook_id: "1195662438662680720"
|
||||
},
|
||||
pk_reply_to_discord: {
|
||||
id: "1202543812644306965",
|
||||
type: 0,
|
||||
content: "this is a reply",
|
||||
channel_id: "1160894080998461480",
|
||||
author: {
|
||||
id: "1195662438662680720",
|
||||
username: "special name",
|
||||
avatar: "6b44a106659e78a2550474c61889194d",
|
||||
discriminator: "0000",
|
||||
public_flags: 0,
|
||||
flags: 0,
|
||||
bot: true,
|
||||
global_name: null
|
||||
},
|
||||
attachments: [],
|
||||
embeds: [
|
||||
{
|
||||
type: "rich",
|
||||
description: "**[Reply to:](https://discord.com/channels/112760669178241024/112760669178241024/1141501302736695316)** some text",
|
||||
author: {
|
||||
name: "wing ↩️",
|
||||
icon_url: "https://cdn.discordapp.com/avatars/112890272819507200/47db1be7ab77e1d812a4573177af0692.png",
|
||||
proxy_icon_url: "https://images-ext-1.discordapp.net/external/wWslraV-s-bLDwphL64YxeDm30M7PIhQQy0EQa8jpDc/https/cdn.discordapp.com/avatars/112890272819507200/47db1be7ab77e1d812a4573177af0692.png"
|
||||
}
|
||||
}
|
||||
],
|
||||
mentions: [],
|
||||
mention_roles: [],
|
||||
pinned: false,
|
||||
mention_everyone: false,
|
||||
tts: false,
|
||||
timestamp: "2024-02-01T09:19:47.118000+00:00",
|
||||
edited_timestamp: null,
|
||||
flags: 0,
|
||||
components: [],
|
||||
application_id: "466378653216014359",
|
||||
webhook_id: "1195662438662680720"
|
||||
}
|
||||
},
|
||||
message_with_embeds: {
|
||||
|
|
Loading…
Reference in a new issue