Compare commits
No commits in common. "30d28f92c72865319759575e56e04b1bd62eef23" and "07f24db4131910ec31513da0987149acd52fe83d" have entirely different histories.
30d28f92c7
...
07f24db413
9 changed files with 87 additions and 232 deletions
|
@ -37,7 +37,7 @@ async function sendMessage(message, guild) {
|
||||||
delete eventWithoutType.$type
|
delete eventWithoutType.$type
|
||||||
|
|
||||||
const eventID = await api.sendEvent(roomID, eventType, event, senderMxid)
|
const eventID = await api.sendEvent(roomID, eventType, event, senderMxid)
|
||||||
db.prepare("INSERT INTO event_message (event_id, message_id, channel_id, part, source) VALUES (?, ?, ?, ?, 1)").run(eventID, message.id, message.channel_id, eventPart) // source 1 = discord
|
db.prepare("INSERT INTO event_message (event_id, message_id, part, source) VALUES (?, ?, ?, 1)").run(eventID, message.id, eventPart) // source 1 = discord
|
||||||
|
|
||||||
eventPart = 1 // TODO: use more intelligent algorithm to determine whether primary or supporting
|
eventPart = 1 // TODO: use more intelligent algorithm to determine whether primary or supporting
|
||||||
eventIDs.push(eventID)
|
eventIDs.push(eventID)
|
||||||
|
|
|
@ -45,22 +45,12 @@ async function messageToEvent(message, guild) {
|
||||||
|
|
||||||
// Text content appears first
|
// Text content appears first
|
||||||
if (message.content) {
|
if (message.content) {
|
||||||
let content = message.content
|
const html = markdown.toHTML(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)
|
discordCallback: getDiscordParseCallbacks(message, true)
|
||||||
}, null, null)
|
}, null, null)
|
||||||
|
|
||||||
const body = markdown.toHTML(content, {
|
const body = markdown.toHTML(message.content, {
|
||||||
discordCallback: getDiscordParseCallbacks(message, false),
|
discordCallback: getDiscordParseCallbacks(message, false), //TODO: library bug!!
|
||||||
discordOnly: true,
|
discordOnly: true,
|
||||||
escapeHTML: false,
|
escapeHTML: false,
|
||||||
}, null, null)
|
}, null, null)
|
||||||
|
|
|
@ -18,29 +18,7 @@ test("message2event: simple user mention", async t => {
|
||||||
msgtype: "m.text",
|
msgtype: "m.text",
|
||||||
body: "@crunch god: Tell me about Phil, renowned martial arts master and creator of the Chin Trick",
|
body: "@crunch god: Tell me about Phil, renowned martial arts master and creator of the Chin Trick",
|
||||||
format: "org.matrix.custom.html",
|
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'
|
formatted_body: '<span class="d-mention d-user"><a href="https://matrix.to/#/@_ooye_crunch_god:cadence.moe">@crunch god</a></span> Tell me about Phil, renowned martial arts master and creator of the Chin Trick'
|
||||||
}])
|
|
||||||
})
|
|
||||||
|
|
||||||
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>'
|
|
||||||
}])
|
}])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
BIN
db/ooye.db
BIN
db/ooye.db
Binary file not shown.
|
@ -25,7 +25,7 @@ async function sendEvent(event) {
|
||||||
let eventPart = 0 // 0 is primary, 1 is supporting
|
let eventPart = 0 // 0 is primary, 1 is supporting
|
||||||
for (const message of messages) {
|
for (const message of messages) {
|
||||||
const messageResponse = await channelWebhook.sendMessageWithWebhook(channelID, message)
|
const messageResponse = await channelWebhook.sendMessageWithWebhook(channelID, message)
|
||||||
db.prepare("INSERT INTO event_message (event_id, message_id, channel_id, part, source) VALUES (?, ?, ?, ?, 0)").run(event.event_id, messageResponse.id, channelID, eventPart) // source 0 = matrix
|
db.prepare("INSERT INTO event_message (event_id, message_id, part, source) VALUES (?, ?, ?, 0)").run(event.event_id, messageResponse.id, eventPart) // source 0 = matrix
|
||||||
|
|
||||||
eventPart = 1 // TODO: use more intelligent algorithm to determine whether primary or supporting?
|
eventPart = 1 // TODO: use more intelligent algorithm to determine whether primary or supporting?
|
||||||
messageResponses.push(messageResponse)
|
messageResponses.push(messageResponse)
|
||||||
|
|
18
package-lock.json
generated
18
package-lock.json
generated
|
@ -11,7 +11,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-sqlite3": "^8.3.0",
|
"better-sqlite3": "^8.3.0",
|
||||||
"cloudstorm": "^0.8.0",
|
"cloudstorm": "^0.8.0",
|
||||||
"discord-markdown": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#df495b152fdc48fb22284ecda9a988e6df61bf99",
|
"discord-markdown": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#24508e701e91d5a00fa5e773ced874d9ee8c889b",
|
||||||
"heatsync": "^2.4.1",
|
"heatsync": "^2.4.1",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"matrix-appservice": "^2.0.0",
|
"matrix-appservice": "^2.0.0",
|
||||||
|
@ -685,11 +685,11 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/cloudstorm": {
|
"node_modules/cloudstorm": {
|
||||||
"version": "0.8.3",
|
"version": "0.8.2",
|
||||||
"resolved": "https://registry.npmjs.org/cloudstorm/-/cloudstorm-0.8.3.tgz",
|
"resolved": "https://registry.npmjs.org/cloudstorm/-/cloudstorm-0.8.2.tgz",
|
||||||
"integrity": "sha512-4c2rqFFvzM4P3pcnjnGUlYuyBjx/xnMew6imB0sFwmNLITLCTLYa3qGkrnhI1g/tM0fqg+Gr+EmDHiDZfEr9LQ==",
|
"integrity": "sha512-G/P6/+LwXjiS6AmheRG+07DmmsrpHpt21JFMhe+rW8VagFOOKemC2Bcru+Qncl/5jdjZC2gzjKpjfdTjfUm+iw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"snowtransfer": "^0.8.3"
|
"snowtransfer": "^0.8.2"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12.0.0"
|
"node": ">=12.0.0"
|
||||||
|
@ -929,7 +929,7 @@
|
||||||
},
|
},
|
||||||
"node_modules/discord-markdown": {
|
"node_modules/discord-markdown": {
|
||||||
"version": "2.4.1",
|
"version": "2.4.1",
|
||||||
"resolved": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#df495b152fdc48fb22284ecda9a988e6df61bf99",
|
"resolved": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#24508e701e91d5a00fa5e773ced874d9ee8c889b",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"simple-markdown": "^0.7.2"
|
"simple-markdown": "^0.7.2"
|
||||||
|
@ -2464,9 +2464,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/snowtransfer": {
|
"node_modules/snowtransfer": {
|
||||||
"version": "0.8.3",
|
"version": "0.8.2",
|
||||||
"resolved": "https://registry.npmjs.org/snowtransfer/-/snowtransfer-0.8.3.tgz",
|
"resolved": "https://registry.npmjs.org/snowtransfer/-/snowtransfer-0.8.2.tgz",
|
||||||
"integrity": "sha512-0X6NLFBUKppYT5VH/mVQNGX+ufv0AndunZC84MqGAR/3rfTIGQblgGJlHlDQbeCytlXdMpgRHIGQnBFlE094NQ==",
|
"integrity": "sha512-fAmaJSpFZqGwAvbrhT3XOWwhbiuHOgxN8pGeKnDDW0f8zdkPmSQT9aekXhFr1WukB94NIALYGcyIXe902p8S4A==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord-api-types": "^0.37.47",
|
"discord-api-types": "^0.37.47",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-sqlite3": "^8.3.0",
|
"better-sqlite3": "^8.3.0",
|
||||||
"cloudstorm": "^0.8.0",
|
"cloudstorm": "^0.8.0",
|
||||||
"discord-markdown": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#df495b152fdc48fb22284ecda9a988e6df61bf99",
|
"discord-markdown": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#24508e701e91d5a00fa5e773ced874d9ee8c889b",
|
||||||
"heatsync": "^2.4.1",
|
"heatsync": "^2.4.1",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"matrix-appservice": "^2.0.0",
|
"matrix-appservice": "^2.0.0",
|
||||||
|
|
113
test/data.js
113
test/data.js
|
@ -216,119 +216,6 @@ module.exports = {
|
||||||
flags: 0,
|
flags: 0,
|
||||||
components: []
|
components: []
|
||||||
},
|
},
|
||||||
simple_message_link: {
|
|
||||||
id: "1126788210308161626",
|
|
||||||
type: 0,
|
|
||||||
content: "https://ptb.discord.com/channels/112760669178241024/112760669178241024/1126786462646550579",
|
|
||||||
channel_id: "112760669178241024",
|
|
||||||
author: {
|
|
||||||
id: "113340068197859328",
|
|
||||||
username: "kumaccino",
|
|
||||||
avatar: "b48302623a12bc7c59a71328f72ccb39",
|
|
||||||
discriminator: "0",
|
|
||||||
public_flags: 128,
|
|
||||||
flags: 128,
|
|
||||||
banner: null,
|
|
||||||
accent_color: null,
|
|
||||||
global_name: "kumaccino",
|
|
||||||
avatar_decoration: null,
|
|
||||||
display_name: "kumaccino",
|
|
||||||
banner_color: null
|
|
||||||
},
|
|
||||||
attachments: [],
|
|
||||||
embeds: [],
|
|
||||||
mentions: [],
|
|
||||||
mention_roles: [],
|
|
||||||
pinned: false,
|
|
||||||
mention_everyone: false,
|
|
||||||
tts: false,
|
|
||||||
timestamp: "2023-07-07T08:14:04.050000+00:00",
|
|
||||||
edited_timestamp: null,
|
|
||||||
flags: 0,
|
|
||||||
components: []
|
|
||||||
},
|
|
||||||
simple_reply: {
|
|
||||||
id: "1126604870762369124",
|
|
||||||
type: 19,
|
|
||||||
content: "<redacted for privacy>",
|
|
||||||
channel_id: "112760669178241024",
|
|
||||||
author: {
|
|
||||||
id: "116718249567059974",
|
|
||||||
username: "rnl",
|
|
||||||
avatar: "67e70f6424eead669e076b44474164c3",
|
|
||||||
discriminator: "0",
|
|
||||||
public_flags: 768,
|
|
||||||
flags: 768,
|
|
||||||
banner: null,
|
|
||||||
accent_color: null,
|
|
||||||
global_name: "▲",
|
|
||||||
avatar_decoration: null,
|
|
||||||
display_name: "▲",
|
|
||||||
banner_color: null
|
|
||||||
},
|
|
||||||
attachments: [],
|
|
||||||
embeds: [],
|
|
||||||
mentions: [
|
|
||||||
{
|
|
||||||
id: "113340068197859328",
|
|
||||||
username: "kumaccino",
|
|
||||||
avatar: "b48302623a12bc7c59a71328f72ccb39",
|
|
||||||
discriminator: "0",
|
|
||||||
public_flags: 128,
|
|
||||||
flags: 128,
|
|
||||||
banner: null,
|
|
||||||
accent_color: null,
|
|
||||||
global_name: "kumaccino",
|
|
||||||
avatar_decoration: null,
|
|
||||||
display_name: "kumaccino",
|
|
||||||
banner_color: null
|
|
||||||
}
|
|
||||||
],
|
|
||||||
mention_roles: [],
|
|
||||||
pinned: false,
|
|
||||||
mention_everyone: false,
|
|
||||||
tts: false,
|
|
||||||
timestamp: "2023-07-06T20:05:32.496000+00:00",
|
|
||||||
edited_timestamp: null,
|
|
||||||
flags: 0,
|
|
||||||
components: [],
|
|
||||||
message_reference: {
|
|
||||||
channel_id: "112760669178241024",
|
|
||||||
message_id: "1126577139723026564",
|
|
||||||
guild_id: "112760669178241024"
|
|
||||||
},
|
|
||||||
referenced_message: {
|
|
||||||
id: "1126577139723026564",
|
|
||||||
type: 0,
|
|
||||||
content: "this message was replied to",
|
|
||||||
channel_id: "112760669178241024",
|
|
||||||
author: {
|
|
||||||
id: "113340068197859328",
|
|
||||||
username: "kumaccino",
|
|
||||||
avatar: "b48302623a12bc7c59a71328f72ccb39",
|
|
||||||
discriminator: "0",
|
|
||||||
public_flags: 128,
|
|
||||||
flags: 128,
|
|
||||||
banner: null,
|
|
||||||
accent_color: null,
|
|
||||||
global_name: "kumaccino",
|
|
||||||
avatar_decoration: null,
|
|
||||||
display_name: "kumaccino",
|
|
||||||
banner_color: null
|
|
||||||
},
|
|
||||||
attachments: [],
|
|
||||||
embeds: [],
|
|
||||||
mentions: [],
|
|
||||||
mention_roles: [],
|
|
||||||
pinned: false,
|
|
||||||
mention_everyone: false,
|
|
||||||
tts: false,
|
|
||||||
timestamp: "2023-07-06T18:15:20.901000+00:00",
|
|
||||||
edited_timestamp: null,
|
|
||||||
flags: 0,
|
|
||||||
components: []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
attachment_no_content: {
|
attachment_no_content: {
|
||||||
id: "1124628646670389348",
|
id: "1124628646670389348",
|
||||||
type: 0,
|
type: 0,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue