Feat: write default permissions in new rooms
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
7f8e4fa825
commit
4be48f41d6
1 changed files with 27 additions and 3 deletions
|
@ -20,6 +20,25 @@ class MatrixAdminClient:
|
||||||
|
|
||||||
|
|
||||||
class MatrixHelper:
|
class MatrixHelper:
|
||||||
|
|
||||||
|
ROOM_POWER_LEVEL_EVENTS = {
|
||||||
|
"m.room.encryption": 200,
|
||||||
|
"m.room.avatar": 50,
|
||||||
|
"m.room.name": 50,
|
||||||
|
"m.room.canonical_alias": 50,
|
||||||
|
"m.space.child": 50,
|
||||||
|
"m.room.history_visibility": 50,
|
||||||
|
"m.room.power_levels": 50,
|
||||||
|
"m.room.topic": 50,
|
||||||
|
"m.room.tombstone": 50,
|
||||||
|
"m.room.server_acl": 50,
|
||||||
|
"m.room.pinned_events": 50,
|
||||||
|
"m.reaction": 0,
|
||||||
|
"m.room.redaction": 0,
|
||||||
|
"im.vector.modular.widgets": 50,
|
||||||
|
"io.element.voice_broadcast_info": 50
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, server: str, username, space_id: str, matrix_username: str) -> None:
|
def __init__(self, server: str, username, space_id: str, matrix_username: str) -> None:
|
||||||
self._client = nio.AsyncClient(server, username)
|
self._client = nio.AsyncClient(server, username)
|
||||||
self._loggedIn = False
|
self._loggedIn = False
|
||||||
|
@ -76,6 +95,8 @@ class MatrixHelper:
|
||||||
{
|
{
|
||||||
"type": "m.room.power_levels",
|
"type": "m.room.power_levels",
|
||||||
"content": {
|
"content": {
|
||||||
|
"events": MatrixHelper.ROOM_POWER_LEVEL_EVENTS,
|
||||||
|
"invite": 50,
|
||||||
"users": {
|
"users": {
|
||||||
self._matrix_username: 200,
|
self._matrix_username: 200,
|
||||||
}
|
}
|
||||||
|
@ -140,13 +161,16 @@ class MatrixHelper:
|
||||||
if power_level != 100 and power_level != 50 and power_level != 0:
|
if power_level != 100 and power_level != 50 and power_level != 0:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
users = await self.get_room_power_levels(room)
|
users = await self.get_room_power_levels(room)
|
||||||
users[user] = power_level
|
users[user] = power_level
|
||||||
if not self._matrix_username in users:
|
if not self._matrix_username in users:
|
||||||
users[self._matrix_username] = 200
|
users[self._matrix_username] = 200
|
||||||
|
|
||||||
|
result = await self._client.room_put_state(room, "m.room.power_levels", {
|
||||||
return await self._client.room_put_state(room, "m.room.power_levels", {
|
"events": MatrixHelper.ROOM_POWER_LEVEL_EVENTS,
|
||||||
|
"invite": 50,
|
||||||
"users": users
|
"users": users
|
||||||
})
|
})
|
||||||
|
assert result.event_id is not None
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
Loading…
Reference in a new issue