32 lines
1.0 KiB
Bash
Executable File
32 lines
1.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eou pipefail
|
|
|
|
# Get the list of rooms with no local users
|
|
empty_rooms() {
|
|
psql -d synapse -c "SELECT room_id FROM room_stats_current WHERE local_users_in_room = 0 \
|
|
ORDER BY current_state_events DESC LIMIT 10;" -t --csv
|
|
}
|
|
|
|
# Delete a room and purge its history
|
|
delete_room() {
|
|
details=$(synadm room details $1)
|
|
name=$(echo $details | jq -r '.name')
|
|
canonical_alias=$(echo $details | jq -r '.canonical_aliacanonical_alias')
|
|
topic=$(echo $details | jq -r '.topic')
|
|
joined_local_members=$(echo $details | jq -r '.joined_local_members')
|
|
state_events=$(echo $details | jq -r '.state_events')
|
|
echo "Deleting room $1 (name: $name, canonical alias: $canonical_alias, topic: $topic)[$joined_local_members]"
|
|
echo "This will remove $state_events state events"
|
|
if [[ $joined_local_members == "0" ]];
|
|
then
|
|
time synadm --yes room delete $1
|
|
else
|
|
echo "Room still had active members!!! $1"
|
|
fi
|
|
echo ""
|
|
}
|
|
|
|
for room in $(empty_rooms); do
|
|
delete_room $room
|
|
done
|