From 504c84068ceeb18064a12383461b8bfe9c5490c1 Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Mon, 23 Jun 2025 06:35:50 +0200 Subject: [PATCH] Constrain ghost PLs to the main bridge bot's PL --- src/d2m/actions/register-user.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/d2m/actions/register-user.js b/src/d2m/actions/register-user.js index 90528ac..b338f3d 100644 --- a/src/d2m/actions/register-user.js +++ b/src/d2m/actions/register-user.js @@ -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