Created
September 30, 2023 14:27
-
-
Save Ancurio/5f33a7ed3c84b580d1d748b900a211f6 to your computer and use it in GitHub Desktop.
Revisions
-
Ancurio created this gist
Sep 30, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ I recently migrated away from t2bot.io's discord<->matrix bridging (to a self-hosted one), which after figuring out all the nice synapse and systemd related pecularities left me with one last cleanup of all the `@_discord_ID:t2bot.io` ghosts haunting my previously bridged matrix rooms. In order to automate the process I wrote two scripts that I want to share; the main one is `purge_t2bot_ghosts.sh` which you provide with a room ID (the internal ones starting with a `!` and looking like a random-generated password), and an access token with admin priviledges; also note that due to the `_synapse` API these scripts are using, they must be executed on `localhost` (this might be rewritten to be used from anywhere, idk). You can optionally specify a delay in seconds between kicks to not trigger the built-in rate limit, but I've found 4 seconds (the default) to be exactly right. Tip: Do this before setting up any replacement bridges to avoid status spams on the Discord site. `purge_t2bot_ghosts.sh` (requires jq): ```bash #!/bin/bash ROOM_ID=$1 TOKEN=$2 DELAY=${3:-4} curl 'http://localhost:8008/_synapse/admin/v1/rooms/'$ROOM_ID'/members?access_token='$TOKEN -X GET \ | jq -r '.members[]' | grep 't2bot\.io$' | \ xargs -I{} ./kick_usr.sh $ROOM_ID {} $TOKEN $DELAY ``` `kick_usr.sh`: ```bash #!/bin/bash ROOMID=$1 USERID=$2 TOKEN=$3 DELAY=$4 echo "Kicking ${USERID}" curl 'http://localhost:8008/_matrix/client/v3/rooms/'$ROOMID'/kick?access_token='$TOKEN \ -X POST --data '{"user_id": "'$USERID'"}' sleep $DELAY ```