dotfiles/script/matrix-purge-rooms

15 lines
645 B
Bash
Executable File

#!/usr/bin/env bash
#
# matrix-purge-rooms purges Matrix rooms with no users.
# Expects to connect to Synapse on localhost:8008.
set -euo pipefail
IFS=$'\n\t'
roomstopurge=$(curl -s --header "Authorization: Bearer $SYNAPSE_ACCESS_TOKEN" 'http://localhost:8008/_synapse/admin/v1/rooms?limit=300' | jq -r '.rooms[] | select(.joined_local_members == 0) | .room_id')
for roomid in $roomstopurge; do
echo "Purging room: $roomid"
curl -X DELETE -H "Authorization: Bearer $SYNAPSE_ACCESS_TOKEN" -H "Content-Type: application/json" -d "{\"purge\": true, \"force_purge\": true}" "http://localhost:8008/_synapse/admin/v1/rooms/$roomid"
echo
done