System/scripts/matrix/clean-old-rooms.sh

32 lines
1.0 KiB
Bash
Raw Normal View History

2023-06-10 20:39:02 -04:00
#!/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 \
2023-06-30 09:06:38 -04:00
ORDER BY current_state_events DESC LIMIT 10;" -t --csv
2023-06-10 20:39:02 -04:00
}
# 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
2023-06-10 20:57:05 -04:00
delete_room $room
2023-06-10 20:39:02 -04:00
done