Last active
November 19, 2016 08:05
-
-
Save rubo77/e573356625952ae57786383151c79b32 to your computer and use it in GitHub Desktop.
bash script to kick all IRC users in a matrix channel
This file contains 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 characters
#!/bin/bash | |
# crontab -e | |
# 23 4 * * * bash /home/irc-bridge/.synapse/EIGENE_purge_history_daily > /dev/null 2>&1 | |
cd /home/irc-bridge/.synapse/ | |
DOMAIN="matrix.domain.org" | |
ADMIN="@some_admin:$DOMAIN" | |
TOKEN=$(sqlite3 homeserver.db "select token from access_tokens where user_id like '$ADMIN' order by id desc limit 1;") | |
#rooms | |
ROOMS_ARRAY=( | |
'!SVAAxpxxxxxQyFaHOL:$DOMAIN' | |
'!XVAAxpxxxxxQyFaHOL:$DOMAIN' | |
) | |
BUSY="pragma busy_timeout=2000" | |
for ROOM_ID in "${ROOMS_ARRAY[@]}" | |
do | |
: | |
BUFFER=$(sqlite3 homeserver.db "$BUSY;select user_id from room_memberships "\ | |
"where room_id='$ROOM_ID' and membership not in ( 'leave') and user_id like '@irc_%' limit 50") | |
echo $BUFFER | |
USER_IDS=$(echo $BUFFER | cut -f 1 -d ' ' --complement) | |
#sleep 1 | |
for u in $USER_IDS; do | |
echo kick user $u from $ROOM_ID | |
# curl -X POST $DOMAIN':8008/_matrix/client/r0/admin/purge_history/'$ROOM_NAME'/'$EVENT_ID'?access_token='$TOKEN | |
echo curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"reason": "obsolete room","user_id": "'$u'" }' 'https://'$DOMAIN':8008/_matrix/client/r0/rooms/'$ROOM_ID'/kick?access_token='$TOKEN | |
curl -X POST -d '{"reason": "obsolete room","user_id": "'$u'" }' $DOMAIN':8008/_matrix/client/r0/rooms/'$ROOM_ID'/kick?access_token='$TOKEN | |
sleep 2 | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment