Script that redacts (erases) every message in a room.
Go to file
2024-07-15 13:21:16 -05:00
.gitignore Initial commit 2024-06-01 11:31:32 -05:00
cinny_access_token.png Upload files to "/" 2024-07-12 03:53:40 -05:00
element_access_token.png Upload files to "/" 2024-07-12 03:42:46 -05:00
element_room_id.jpg Upload files to "/" 2024-07-12 03:49:52 -05:00
LICENSE Initial commit 2024-06-01 11:31:32 -05:00
README.md Update README.md 2024-07-15 13:21:16 -05:00
redact_matrix.py rename 2024-07-12 03:44:13 -05:00

Redact Matrix

Small script that redacts (deletes) every message written by the user in a given Matrix room.


Usage

Installation

Download the script:

git clone https://git.thisisjoes.site/cynic/redact-matrix.git
cd redact-matrix
chmod +x redact_matrix.py  # optional

Getting your access token

On Element it is found at: ⚙️ Quick settings > All Settings > Help & About > Advanced > Access Token

access token

On Cinny, for example, go to Firefox's Inspect tool, then to the Storage tab, and copy your cinny_access_token.

access token

Other clients may have a similar key with this value.

The token is different for each session and remains valid as long as you don't log out.

Getting room ID's

Room ID's look like this: !cdPNSVToruMtXqGznY:domain.tld

On Element the room ID of any room can be found at Room info > Settings > Advanced > Internal room ID

room id

On Cinny we can see this value in the source of sent messages.

Running the script

./redact_matrix.py -s matrix.org -t syt_uaY3lMW_nAyiumHhGDhXJBFLKdoY_3RRBuz \!xTDdCBHByVyZtZEmNI:matrix.org '!cdPNSVToruMtXqGznY:domain.tld'

As we can see above, it is possible to apply the command to more than one room.

Additionally, by adding the -n flag after redact_matrix.py the Nuke mode is turned on, which means that you will not be deleting just your own messages but those of other users in the room as well, so long as you have the proper permissions (e.g. admin). In other words, it attempts to "nuke" the room, so, please, be very careful with this flag.

When in doubt, see the help by passing --help or -h:

# python redact_matrix.py --help
usage: redact_matrix.py [-h] [-n] -s HOMESERVER -t ACCESS_TOKEN [room_ids ...]

positional arguments:
  room_ids              room ID's

options:
  -h, --help            show this help message and exit
  -n, --nuke            try and delete all messages in the room, not only mine

required:
  -s HOMESERVER, --homeserver HOMESERVER
                        homeserver's domain name
  -t ACCESS_TOKEN, --access-token ACCESS_TOKEN
                        Matrix access token

Note:

Once it has deleted all of your messages it may remove the room itself, if you had permissions to do so.