Fix: issue when power level events are higher than bot level
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Dorian Zedler 2022-10-04 10:24:46 +02:00
parent 7ba0eb5229
commit 7728f5d16d
Signed by: dozedler
GPG key ID: 989DE36109AFA354

View file

@ -162,15 +162,27 @@ class MatrixHelper:
return False
users = await self.get_room_power_levels(room)
if not self._matrix_username in users or users[self._matrix_username] < 100:
self._admin_client.room.set_admin(room, self._matrix_username)
users = await self.get_room_power_levels(room)
users[user] = power_level
if not self._matrix_username in users:
users[self._matrix_username] = 200
room_power_level_events = MatrixHelper.ROOM_POWER_LEVEL_EVENTS
for key, value in room_power_level_events.items():
if value > users[self._matrix_username]:
room_power_level_events[key] = users[self._matrix_username]
result = await self._client.room_put_state(room, "m.room.power_levels", {
"events": MatrixHelper.ROOM_POWER_LEVEL_EVENTS,
"events": room_power_level_events,
"invite": 50,
"users": users
})
assert result.event_id is not None
if isinstance(result, nio.ErrorResponse):
logging.error(f"Error while setting power level of user {user} in room {room} to {power_level}")
logging.error(result)
logging.error(f"Current power levels: {users}")
return False
return True