Constrain ghost PLs to the main bridge bot's PL

This commit is contained in:
2025-06-23 06:35:50 +02:00
parent 10a3185823
commit 504c84068c

View File

@@ -199,7 +199,10 @@ function _hashProfileContent(content, powerLevel) {
async function syncUser(user, member, channel, guild, roomID) {
const mxid = await ensureSimJoined(user, roomID)
const content = await memberToStateContent(user, member, guild.id)
const powerLevel = memberToPowerLevel(user, member, guild, channel)
const discordPowerLevel = memberToPowerLevel(user, member, guild, channel)
const powerLevelsStateContent = await api.getStateEvent(roomID, "m.room.power_levels", "") // Kind of sucks we have to do this all the time
const botpl = powerLevelsStateContent.users?.[`@${reg.sender_localpart}:${reg.ooye.server_name}`] || 0
const powerLevel = Math.min(discordPowerLevel, botpl)
const currentHash = _hashProfileContent(content, powerLevel)
const existingHash = select("sim_member", "hashed_profile_content", {room_id: roomID, mxid}).safeIntegers().pluck().get()
// only do the actual sync if the hash has changed since we last looked
@@ -210,7 +213,6 @@ async function syncUser(user, member, channel, guild, roomID) {
// 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)
const powerLevelsStateContent = await api.getStateEvent(roomID, "m.room.power_levels", "")
const oldPowerLevel = powerLevelsStateContent.users?.[mxid] || 0
mixin(powerLevelsStateContent, {users: {[mxid]: powerLevel}})
if (powerLevel === 0) delete powerLevelsStateContent.users[mxid] // keep the event compact