store the channel_id on event_message
This commit is contained in:
parent
1d6e833b22
commit
0f4f404160
5 changed files with 150 additions and 5 deletions
|
@ -45,12 +45,22 @@ async function messageToEvent(message, guild) {
|
|||
|
||||
// Text content appears first
|
||||
if (message.content) {
|
||||
const html = markdown.toHTML(message.content, {
|
||||
let content = message.content
|
||||
content = content.replace(/https:\/\/(?:ptb\.|canary\.|www\.)?discord(?:app)?\.com\/channels\/([0-9]+)\/([0-9]+)\/([0-9]+)/, (whole, guildID, channelID, messageID) => {
|
||||
const row = db.prepare("SELECT room_id, event_id FROM event_message INNER JOIN channel_room USING (channel_id) WHERE channel_id = ? AND message_id = ? AND part = 0").get(channelID, messageID)
|
||||
if (row) {
|
||||
return `https://matrix.to/#/${row.room_id}/${row.event_id}`
|
||||
} else {
|
||||
return `${whole} [event not found]`
|
||||
}
|
||||
})
|
||||
|
||||
const html = markdown.toHTML(content, {
|
||||
discordCallback: getDiscordParseCallbacks(message, true)
|
||||
}, null, null)
|
||||
|
||||
const body = markdown.toHTML(message.content, {
|
||||
discordCallback: getDiscordParseCallbacks(message, false), //TODO: library bug!!
|
||||
const body = markdown.toHTML(content, {
|
||||
discordCallback: getDiscordParseCallbacks(message, false),
|
||||
discordOnly: true,
|
||||
escapeHTML: false,
|
||||
}, null, null)
|
||||
|
|
|
@ -22,6 +22,28 @@ test("message2event: simple user mention", async t => {
|
|||
}])
|
||||
})
|
||||
|
||||
test("message2event: simple room mention", async t => {
|
||||
const events = await messageToEvent(data.message.simple_room_mention, data.guild.general)
|
||||
t.deepEqual(events, [{
|
||||
$type: "m.room.message",
|
||||
msgtype: "m.text",
|
||||
body: "@crunch god: Tell me about Phil, renowned martial arts master and creator of the Chin Trick",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: '<a href="https://matrix.to/#/@_ooye_crunch_god:cadence.moe">@crunch god</a> Tell me about Phil, renowned martial arts master and creator of the Chin Trick'
|
||||
}])
|
||||
})
|
||||
|
||||
test("message2event: simple message link", async t => {
|
||||
const events = await messageToEvent(data.message.simple_message_link, data.guild.general)
|
||||
t.deepEqual(events, [{
|
||||
$type: "m.room.message",
|
||||
msgtype: "m.text",
|
||||
body: "https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg",
|
||||
format: "org.matrix.custom.html",
|
||||
formatted_body: '<a href="https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg">https://matrix.to/#/!kLRqKKUQXcibIMtOpl:cadence.moe/$X16nfVks1wsrhq4E9SSLiqrf2N8KD0erD0scZG7U5xg</a>'
|
||||
}])
|
||||
})
|
||||
|
||||
test("message2event: attachment with no content", async t => {
|
||||
const events = await messageToEvent(data.message.attachment_no_content, data.guild.general)
|
||||
t.deepEqual(events, [{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue