Compare commits
2 commits
64671519bd
...
69922c4a14
Author | SHA1 | Date | |
---|---|---|---|
69922c4a14 | |||
98477dc0f6 |
5 changed files with 25 additions and 6 deletions
|
@ -128,7 +128,7 @@ async function memberToStateContent(pkMessage, author) {
|
||||||
async function syncUser(author, pkMessage, roomID) {
|
async function syncUser(author, pkMessage, roomID) {
|
||||||
const mxid = await ensureSimJoined(pkMessage, roomID)
|
const mxid = await ensureSimJoined(pkMessage, roomID)
|
||||||
// Update the sim_proxy table, so mentions can look up the original sender later
|
// Update the sim_proxy table, so mentions can look up the original sender later
|
||||||
db.prepare("INSERT OR IGNORE INTO sim_proxy (user_id, proxy_owner_id) VALUES (?, ?)").run(pkMessage.member.uuid, pkMessage.sender)
|
db.prepare("INSERT OR IGNORE INTO sim_proxy (user_id, proxy_owner_id, displayname) VALUES (?, ?, ?)").run(pkMessage.member.uuid, pkMessage.sender, author.username)
|
||||||
// Sync the member state
|
// Sync the member state
|
||||||
const content = await memberToStateContent(pkMessage, author)
|
const content = await memberToStateContent(pkMessage, author)
|
||||||
const currentHash = registerUser._hashProfileContent(content)
|
const currentHash = registerUser._hashProfileContent(content)
|
||||||
|
|
|
@ -252,6 +252,15 @@ async function messageToEvent(message, guild, options = {}, di) {
|
||||||
if (row) {
|
if (row) {
|
||||||
repliedToEventRow = row
|
repliedToEventRow = row
|
||||||
}
|
}
|
||||||
|
} else if (dUtils.isWebhookMessage(message) && message.embeds[0]?.author?.name?.endsWith("↩️") && message.embeds[0].description?.startsWith("**[Reply to:]")) {
|
||||||
|
const match = message.embeds[0].description.match(/\/channels\/[0-9]*\/[0-9]*\/([0-9]{2,})/)
|
||||||
|
if (match) {
|
||||||
|
const row = from("event_message").join("message_channel", "message_id").join("channel_room", "channel_id").select("event_id", "room_id", "source").and("WHERE message_id = ? AND part = 0").get(match[1])
|
||||||
|
if (row) {
|
||||||
|
message.embeds.shift()
|
||||||
|
repliedToEventRow = row
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (repliedToEventRow && repliedToEventRow.source === 0) { // reply was originally from Matrix
|
if (repliedToEventRow && repliedToEventRow.source === 0) { // reply was originally from Matrix
|
||||||
// Need to figure out who sent that event...
|
// Need to figure out who sent that event...
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
CREATE TABLE IF NOT EXISTS sim_proxy (
|
CREATE TABLE IF NOT EXISTS sim_proxy (
|
||||||
user_id TEXT NOT NULL,
|
user_id TEXT NOT NULL,
|
||||||
proxy_owner_id TEXT NOT NULL,
|
proxy_owner_id TEXT NOT NULL,
|
||||||
|
displayname TEXT NOT NULL,
|
||||||
PRIMARY KEY(user_id)
|
PRIMARY KEY(user_id)
|
||||||
) WITHOUT ROWID;
|
) WITHOUT ROWID;
|
||||||
|
|
1
db/orm-defs.d.ts
vendored
1
db/orm-defs.d.ts
vendored
|
@ -66,6 +66,7 @@ export type Models = {
|
||||||
sim_proxy: {
|
sim_proxy: {
|
||||||
user_id: string
|
user_id: string
|
||||||
proxy_owner_id: string
|
proxy_owner_id: string
|
||||||
|
displayname: string
|
||||||
}
|
}
|
||||||
|
|
||||||
webhook: {
|
webhook: {
|
||||||
|
|
|
@ -32,7 +32,7 @@ const markdownEscapes = [
|
||||||
[/^>/g, '\\>'],
|
[/^>/g, '\\>'],
|
||||||
[/_/g, '\\_'],
|
[/_/g, '\\_'],
|
||||||
[/^(\d+)\. /g, '$1\\. ']
|
[/^(\d+)\. /g, '$1\\. ']
|
||||||
]
|
]
|
||||||
|
|
||||||
const turndownService = new TurndownService({
|
const turndownService = new TurndownService({
|
||||||
hr: "----",
|
hr: "----",
|
||||||
|
@ -103,7 +103,15 @@ turndownService.addRule("inlineLink", {
|
||||||
},
|
},
|
||||||
|
|
||||||
replacement: function (content, node) {
|
replacement: function (content, node) {
|
||||||
if (node.getAttribute("data-user-id")) return `<@${node.getAttribute("data-user-id")}>`
|
if (node.getAttribute("data-user-id")) {
|
||||||
|
const user_id = node.getAttribute("data-user-id")
|
||||||
|
const row = select("sim_proxy", ["displayname", "proxy_owner_id"], {user_id}).get()
|
||||||
|
if (row) {
|
||||||
|
return `**@${row.displayname}** (<@${row.proxy_owner_id}>)`
|
||||||
|
} else {
|
||||||
|
return `<@${user_id}>`
|
||||||
|
}
|
||||||
|
}
|
||||||
if (node.getAttribute("data-message-id")) return `https://discord.com/channels/${node.getAttribute("data-guild-id")}/${node.getAttribute("data-channel-id")}/${node.getAttribute("data-message-id")}`
|
if (node.getAttribute("data-message-id")) return `https://discord.com/channels/${node.getAttribute("data-guild-id")}/${node.getAttribute("data-channel-id")}/${node.getAttribute("data-message-id")}`
|
||||||
if (node.getAttribute("data-channel-id")) return `<#${node.getAttribute("data-channel-id")}>`
|
if (node.getAttribute("data-channel-id")) return `<#${node.getAttribute("data-channel-id")}>`
|
||||||
const href = node.getAttribute("href")
|
const href = node.getAttribute("href")
|
||||||
|
@ -507,9 +515,9 @@ async function eventToMessage(event, guild, di) {
|
||||||
mxid = decodeURIComponent(mxid)
|
mxid = decodeURIComponent(mxid)
|
||||||
if (mxUtils.eventSenderIsFromDiscord(mxid)) {
|
if (mxUtils.eventSenderIsFromDiscord(mxid)) {
|
||||||
// Handle mention of an OOYE sim user by their mxid
|
// Handle mention of an OOYE sim user by their mxid
|
||||||
const userID = getUserOrProxyOwnerID(mxid)
|
const id = select("sim", "user_id", {mxid}).pluck().get()
|
||||||
if (!userID) return whole
|
if (!id) return whole
|
||||||
return `${attributeValue} data-user-id="${userID}">`
|
return `${attributeValue} data-user-id="${id}">`
|
||||||
} else {
|
} else {
|
||||||
// Handle mention of a Matrix user by their mxid
|
// Handle mention of a Matrix user by their mxid
|
||||||
// Check if this Matrix user is actually the sim user from another old bridge in the room?
|
// Check if this Matrix user is actually the sim user from another old bridge in the room?
|
||||||
|
|
Loading…
Reference in a new issue