Skip to content

Instantly share code, notes, and snippets.

@nukeador
Last active September 21, 2022 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nukeador/e774e003de0593e5ab72ced49d0ea59f to your computer and use it in GitHub Desktop.
Save nukeador/e774e003de0593e5ab72ced49d0ea59f to your computer and use it in GitHub Desktop.
Bulk-banning a user on multiple rooms from a text file using matrix-commander
#!/usr/bin/env python3
"""
Usage bulk-ban.py room-list.txt @userid:server.com
Please set the notice_room variable to the room your want to notify when
banning an user.
You will need matrix-commander installed configured before
https://github.com/8go/matrix-commander/
"""
import subprocess, sys
# Setup using a public or private room you want to notify about the ban
# set notification = False for no notifications
notifications = True
notice_room = '#yourroom:server.tld'
file_path = sys.argv[1]
user = sys.argv[2]
with open(file_path) as file:
for line in file:
room = line.replace('\n','')
subprocess.run(['matrix-commander', '--room-ban', room, '--user', user])
if notifications:
# Notice to the control room about the ban
notice_msg = '⚠️ Notice: ' + user + ' banned in all #openmapping-humanitarian-general:matrix.org rooms'
subprocess.run(['matrix-commander', '-m', notice_msg, '--room', notice_room])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment