Drop admin permissions correctly

This commit is contained in:
Cadence Ember 2024-07-15 15:27:21 +12:00
parent 49598c7af7
commit 8c506ed270
2 changed files with 5 additions and 3 deletions

View File

@ -197,9 +197,11 @@ async function syncUser(user, member, channel, guild, roomID) {
await api.sendState(roomID, "m.room.member", mxid, content, mxid)
// Update power levels
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
await api.sendState(roomID, "m.room.power_levels", "", powerLevelsStateContent)
const sendPowerLevelAs = powerLevel < oldPowerLevel ? mxid : undefined // bridge bot won't not have permission to demote equal power users, so do this action as themselves
await api.sendState(roomID, "m.room.power_levels", "", powerLevelsStateContent, sendPowerLevelAs)
// Update cached hash
db.prepare("UPDATE sim_member SET hashed_profile_content = ? WHERE room_id = ? AND mxid = ?").run(currentHash, roomID, mxid)
}

View File

@ -103,10 +103,10 @@ function isWebhookMessage(message) {
/**
* Ephemeral messages can be generated if a slash command is attached to the same bot that OOYE is running on
* @param {DiscordTypes.APIMessage} message
* @param {Pick<DiscordTypes.APIMessage, "flags">} message
*/
function isEphemeralMessage(message) {
return message.flags & (1 << 6);
return message.flags && (message.flags & (1 << 6));
}
/** @param {string} snowflake */