From 3171f103714b74e43a0fc32fbccd328000f34977 Mon Sep 17 00:00:00 2001 From: deathrow Date: Fri, 6 Jan 2023 21:03:54 -0500 Subject: [PATCH] Delete empty rooms script --- scripts/synapse/delete_empty_rooms.py | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/synapse/delete_empty_rooms.py diff --git a/scripts/synapse/delete_empty_rooms.py b/scripts/synapse/delete_empty_rooms.py new file mode 100644 index 0000000..dadb4d2 --- /dev/null +++ b/scripts/synapse/delete_empty_rooms.py @@ -0,0 +1,29 @@ +import requests +import urllib + +token = 'TOKEN' +server = 'https://matrix.anonymousland.org' +api_rooms = f'{server}/_synapse/admin/v1/rooms?dir=b&from=0&limit=20&order_by=joined_local_members&access_token={token}' +delete_api = f'{server}/_synapse/admin/v1/rooms/' + +local_users = 0 +while local_users == 0: + r = requests.get(api_rooms) + print(r.text) + rooms = r.json() + headers = { + 'authorization': f'Bearer {token}' + } + for room in rooms['rooms']: + local_users = room['joined_local_members'] + if local_users == 0: + roomid = urllib.parse.quote(room['room_id']) + print('delete', delete_api + roomid) + r = requests.delete(delete_api + roomid, headers=headers, json={}) + if r.status_code != 200: + print(r.text) + break + else: + print("there are local users in this room", room) + break +print("Done.") \ No newline at end of file