Created
October 11, 2021 06:50
-
-
Save hifi/dc9fbb62bdb11dc9075222b31512f919 to your computer and use it in GitHub Desktop.
Upgrade Matrix rooms with custom power level override for yourself (aka hijack a room with upgrade)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
mx_get() { | |
curl -s -H "Authorization: Bearer $TOKEN" $HS/$1 | |
} | |
mx_post() { | |
curl -s -X POST -H "Authorization: Bearer $TOKEN" -H "Content-type: application/json" -d "$1" $HS/$2 | |
} | |
mx_put() { | |
curl -s -X PUT -H "Authorization: Bearer $TOKEN" -H "Content-type: application/json" -d "$1" $HS/$2 | |
} | |
create_room() { | |
local data=' | |
{ | |
"visibility": "public", | |
"creation_content": { | |
"predecessor": { | |
"event_id": "'$2'", | |
"room_id": "'$1'" | |
} | |
}, | |
"room_version": "6", | |
"power_level_content_override": { | |
"users": { | |
"'$3'": 9001 | |
} | |
} | |
} | |
' | |
mx_post "$data" _matrix/client/r0/createRoom | |
} | |
tombstone() { | |
local data=' | |
{ | |
"body": "This room has been replaced", | |
"replacement_room": "'$2'" | |
} | |
' | |
local quote_room_id=$(echo -n $1 | jq -sRr @uri) | |
echo $quote_room_id | |
mx_put "$data" _matrix/client/r0/rooms/$quote_room_id/state/m.room.tombstone/ | |
} | |
echo -n "Give your HS address: " | |
read HS | |
echo -n "Give your acccess token: " | |
read TOKEN | |
echo -n "Testing connection: " | |
WHOAMI=$(mx_get _matrix/client/r0/account/whoami) | |
USER_ID=$(echo $WHOAMI | jq -r .user_id) | |
echo "Upgrade is being done as $USER_ID, hit enter if correct." | |
read line | |
echo -n "Give old room ID: " | |
read OLD_ROOM_ID | |
LAST_EVENT=$(mx_get "_matrix/client/r0/sync?filter=%7B%22room%22:%7B%22rooms%22:%5B%22$OLD_ROOM_ID%22%5D%7D%7D" | jq -r '.rooms.join[].timeline.events[-1]') | |
echo -n "Last event: " | |
echo $LAST_EVENT | jq | |
LAST_EVENT_ID=$(echo $LAST_EVENT | jq -r .event_id) | |
echo "Last event of old room ($OLD_ROOM_ID): $LAST_EVENT_ID" | |
echo | |
echo "If this all looks good, hit enter to continue to create new room and tombstone the old" | |
read line | |
NEW_ROOM_ID=$(create_room $OLD_ROOM_ID $LAST_EVENT_ID $USER_ID | jq -r .room_id) | |
tombstone $OLD_ROOM_ID $NEW_ROOM_ID | |
echo $NEW_ROOM_ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment