diff --git a/m2d/converters/event-to-message.js b/m2d/converters/event-to-message.js
index 3e22093a..77475c2b 100644
--- a/m2d/converters/event-to-message.js
+++ b/m2d/converters/event-to-message.js
@@ -198,9 +198,9 @@ async function eventToMessage(event, guild, di) {
const senderName = sender.match(/@([^:]*)/)?.[1] || sender
const authorID = db.prepare("SELECT discord_id FROM sim WHERE mxid = ?").pluck().get(repliedToEvent.sender)
if (authorID) {
- replyLine += `<@${authorID}>: `
+ replyLine += `<@${authorID}>:`
} else {
- replyLine += `Ⓜ️**${senderName}**: `
+ replyLine += `Ⓜ️**${senderName}**:`
}
const repliedToContent = repliedToEvent.content.formatted_body || repliedToEvent.content.body
const contentPreviewChunks = chunk(repliedToContent.replace(/.*<\/mx-reply>/, "").replace(/(?:\n|
)+/g, " ").replace(/<[^>]+>/g, ""), 50)
diff --git a/m2d/converters/event-to-message.test.js b/m2d/converters/event-to-message.test.js
index 61da83ce..848d861a 100644
--- a/m2d/converters/event-to-message.test.js
+++ b/m2d/converters/event-to-message.test.js
@@ -29,8 +29,8 @@ function mockGetEvent(t, roomID_in, eventID_in, outer) {
}
function sameFirstContentAndWhitespace(t, a, b) {
- const a2 = JSON.stringify(a[0].content)
- const b2 = JSON.stringify(b[0].content)
+ const a2 = JSON.stringify(a.messagesToSend[0].content)
+ const b2 = JSON.stringify(b.messagesToSend[0].content)
t.equal(a2, b2)
}
@@ -50,11 +50,15 @@ test("event2message: body is used when there is no formatted_body", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "testing plaintext",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "testing plaintext",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -74,11 +78,15 @@ test("event2message: any markdown in body is escaped", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "testing \\*\\*special\\*\\* \\~\\~things\\~\\~ which \\_should\\_ \\*not\\* \\`trigger\\` @any ",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "testing \\*\\*special\\*\\* \\~\\~things\\~\\~ which \\_should\\_ \\*not\\* \\`trigger\\` @any ",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -100,11 +108,15 @@ test("event2message: basic html is converted to markdown", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "this **is** a **_test_** of ~~formatting~~",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "this **is** a **_test_** of ~~formatting~~",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -126,11 +138,15 @@ test("event2message: markdown syntax is escaped", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "this \\*\\*is\\*\\* an **_extreme_** \\\\\\*test\\\\\\* of",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "this \\*\\*is\\*\\* an **_extreme_** \\\\\\*test\\\\\\* of",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -152,11 +168,15 @@ test("event2message: html lines are bridged correctly", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "paragraph one\nline _two_\nline three\n\nparagraph two\nline _two_\nline three\n\nparagraph three\n\nparagraph four\nline two\nline three\nline four\n\nparagraph five",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "paragraph one\nline _two_\nline three\n\nparagraph two\nline _two_\nline three\n\nparagraph three\n\nparagraph four\nline two\nline three\nline four\n\nparagraph five",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -178,11 +198,15 @@ test("event2message: html lines are bridged correctly", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "line one: test test\nline two: **test** **test**\nline three: **test test**\nline four: test test\n line five",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "line one: test test\nline two: **test** **test**\nline three: **test test**\nline four: test test\n line five",
+ avatar_url: undefined
+ }]
+ }
)
})*/
@@ -205,11 +229,15 @@ test("event2message: whitespace is collapsed", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "line one: test test\nline two: **test** **test**\nline three: **test test**\nline four: test test\nline five",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "line one: test test\nline two: **test** **test**\nline three: **test test**\nline four: test test\nline five",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -233,11 +261,15 @@ test("event2message: lists are bridged correctly", async t => {
"event_id": "$l-xQPY5vNJo3SNxU9d8aOWNVD1glMslMyrp4M_JEF70",
"room_id": "!BpMdOUkWWhFxmTrENV:cadence.moe"
}),
- [{
- username: "cadence [they]",
- content: "* line one\n* line two\n* line three\n * nested one\n * nested two\n* line four",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "* line one\n* line two\n* line three\n * nested one\n * nested two\n* line four",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -257,15 +289,19 @@ test("event2message: long messages are split", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: (("a".repeat(130) + " ").repeat(15)).slice(0, -1),
- avatar_url: undefined
- }, {
- username: "cadence [they]",
- content: (("a".repeat(130) + " ").repeat(4)).slice(0, -1),
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: (("a".repeat(130) + " ").repeat(15)).slice(0, -1),
+ avatar_url: undefined
+ }, {
+ username: "cadence [they]",
+ content: (("a".repeat(130) + " ").repeat(4)).slice(0, -1),
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -287,11 +323,15 @@ test("event2message: code blocks work", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "preceding\n\n```\ncode block\n```\n\nfollowing `code` is inline",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "preceding\n\n```\ncode block\n```\n\nfollowing `code` is inline",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -314,11 +354,15 @@ test("event2message: code block contents are formatted correctly and not escaped
"event_id": "$pGkWQuGVmrPNByrFELxhzI6MCBgJecr5I2J3z88Gc2s",
"room_id": "!BpMdOUkWWhFxmTrENV:cadence.moe"
}),
- [{
- username: "cadence [they]",
- content: "```\ninput = input.replace(/(<\\/?([^ >]+)[^>]*>)?\\n(<\\/?([^ >]+)[^>]*>)?/g,\n_input_ = input = input.replace(/(<\\/?([^ >]+)[^>]*>)?\\n(<\\/?([^ >]+)[^>]*>)?/g,\n```\n\n`input = input.replace(/(<\\/?([^ >]+)[^>]*>)?\\n(<\\/?([^ >]+)[^>]*>)?/g,`",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "```\ninput = input.replace(/(<\\/?([^ >]+)[^>]*>)?\\n(<\\/?([^ >]+)[^>]*>)?/g,\n_input_ = input = input.replace(/(<\\/?([^ >]+)[^>]*>)?\\n(<\\/?([^ >]+)[^>]*>)?/g,\n```\n\n`input = input.replace(/(<\\/?([^ >]+)[^>]*>)?\\n(<\\/?([^ >]+)[^>]*>)?/g,`",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -340,11 +384,15 @@ test("event2message: quotes have an appropriate amount of whitespace", async t =
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "> Chancellor of Germany Angela Merkel, on March 17, 2017: they did not shake hands\n🤨",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "> Chancellor of Germany Angela Merkel, on March 17, 2017: they did not shake hands\n🤨",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -366,11 +414,15 @@ test("event2message: m.emote markdown syntax is escaped", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "\\* cadence \\[they\\] shows you \\*\\*her\\*\\* **_extreme_** \\\\\\*test\\\\\\* of",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "\\* cadence \\[they\\] shows you \\*\\*her\\*\\* **_extreme_** \\\\\\*test\\\\\\* of",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -409,11 +461,17 @@ test("event2message: rich reply to a sim user", async t => {
})
}
}),
- [{
- username: "cadence [they]",
- content: "<:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 <@111604486476181504>: Slow news day.\nTesting this reply, ignore",
- avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 <@111604486476181504>:"
+ + "\n> Slow news day."
+ + "\nTesting this reply, ignore",
+ avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
+ }]
+ }
)
})
@@ -454,11 +512,17 @@ test("event2message: rich reply to a matrix user's long message with formatting"
})
}
}),
- [{
- username: "cadence [they]",
- content: "<:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 Ⓜ️**cadence**: i should have a little...\n**no you can't!!!**",
- avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 Ⓜ️**cadence**:"
+ + "\n> i should have a little happy test list bold em..."
+ + "\n**no you can't!!!**",
+ avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
+ }]
+ }
)
})
@@ -499,11 +563,17 @@ test("event2message: with layered rich replies, the preview should only be the r
})
}
}),
- [{
- username: "cadence [they]",
- content: "<:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 Ⓜ️**cadence**: two\nthree",
- avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "> <:L1:1144820033948762203><:L2:1144820084079087647>https://discord.com/channels/112760669178241024/687028734322147344/1144865310588014633 Ⓜ️**cadence**:"
+ + "\n> two"
+ + "\nthree",
+ avatar_url: "https://matrix.cadence.moe/_matrix/media/r0/download/cadence.moe/azCAhThKTojXSZJRoWwZmhvU"
+ }]
+ }
)
})
@@ -525,11 +595,15 @@ test("event2message: mentioning discord users works", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "I'm just <@114147806469554185> testing mentions",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "I'm just <@114147806469554185> testing mentions",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -551,11 +625,15 @@ test("event2message: mentioning matrix users works", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "I'm just [▲]() testing mentions",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "I'm just [▲]() testing mentions",
+ avatar_url: undefined
+ }]
+ }
)
})
@@ -577,10 +655,14 @@ test("event2message: mentioning bridged rooms works", async t => {
age: 405299
}
}),
- [{
- username: "cadence [they]",
- content: "I'm just [▲]() testing mentions",
- avatar_url: undefined
- }]
+ {
+ messagesToDelete: [],
+ messagesToEdit: [],
+ messagesToSend: [{
+ username: "cadence [they]",
+ content: "I'm just [▲]() testing mentions",
+ avatar_url: undefined
+ }]
+ }
)
})