Get member data when running backfill

This commit is contained in:
Cadence Ember 2025-08-05 01:25:09 +12:00
parent 6c23c5725a
commit 67291a3736
4 changed files with 17 additions and 9 deletions

View file

@ -210,7 +210,7 @@ async function syncUser(user, member, channel, guild, roomID) {
if (hashHasChanged && !wouldOverwritePreExisting) {
// Update room member state
await api.sendState(roomID, "m.room.member", mxid, content, mxid)
// Update power levels (only if we can actually access the member roles)
// Update power levels
await api.setUserPower(roomID, mxid, powerLevel)
// Update cached hash
db.prepare("UPDATE sim_member SET hashed_profile_content = ? WHERE room_id = ? AND mxid = ?").run(currentHash, roomID, mxid)

View file

@ -62,9 +62,6 @@ class DiscordClient {
addEventLogger("error", "Error")
addEventLogger("disconnected", "Disconnected")
addEventLogger("ready", "Ready")
this.snow.requestHandler.on("requestError", (requestID, error) => {
console.error("request error:", error)
})
}
}

View file

@ -109,13 +109,24 @@ module.exports = {
})
// console.log(`[check missed messages] got ${messages.length} messages; last message that IS bridged is at position ${latestBridgedMessageIndex} in the channel`)
if (latestBridgedMessageIndex === -1) latestBridgedMessageIndex = 1 // rather than crawling the ENTIRE channel history, let's just bridge the most recent 1 message to make it up to date.
// We get member data so that we can accurately update any changes to nickname or permissions that have occurred in the meantime
// The rate limit is lax enough that the backlog will still be pretty quick (at time of writing, 5 per 1 second per guild)
/** @type {Map<string, DiscordTypes.APIGuildMember | undefined>} id -> member: cache members for the run because people talk to each other */
const members = new Map()
// Send in order
for (let i = Math.min(messages.length, latestBridgedMessageIndex)-1; i >= 0; i--) {
const simulatedGatewayDispatchData = {
const message = messages[i]
if (!members.has(message.author.id)) members.set(message.author.id, await client.snow.guild.getGuildMember(guild.id, message.author.id).catch(() => undefined))
await module.exports.MESSAGE_CREATE(client, {
guild_id: guild.id,
member: members.get(message.author.id),
// @ts-ignore
backfill: true,
...messages[i]
}
await module.exports.MESSAGE_CREATE(client, simulatedGatewayDispatchData)
...message
})
}
}
},

View file

@ -51,7 +51,7 @@ function stringifyErrorStack(err, depth = 0) {
const props = Object.getOwnPropertyNames(err).filter(p => !["message", "stack"].includes(p))
// only break into object notation if we have addtl props to dump
// only break into object notation if we have additional props to dump
if (props.length) {
const dedent = " ".repeat(depth);
const indent = " ".repeat(depth + 2);