This is a script that allows you to automatically generate a blocklist (AKA moderation list) for Bluesky based on users' display names, handles or bios.
- Clone this repository:
git clone https://github.com/ndri/atproto-auto-blocklist.git
- Change into the directory:
cd atproto-auto-blocklist
- Create a virtual environment:
python3 -m venv venv
- Activate the virtual environment:
source venv/bin/activate
- Install the dependencies:
pip install -r requirements.txt
- Configure the environment variables (see below).
- Run the script:
python3 add_to_blocklist.py
You can configure the script with command line arguments, environment variables or the .env
file.
To run this script, you need to set your Bluesky login credentials, the ID of the blocklist to add users to, the search term to find users with and the query to filter the found users.
The reason for both a search term and a query is that the AT Protocol only allows you to search users with a simple text query that finds users based on their name, handle or bio and it can return some users that you don't want to block. The query is used to filter out those users and to make sure you only block the users you want to block.
See the .env.example
file for a list of environment variables that you can set.
Make a copy of the .env.example
file and name it .env
:
cp .env.example .env
Fill in the values for the environment variables:
USERNAME
- Your Bluesky username.PASSWORD
- A Bluesky app password.BLOCKLIST_ID
- The ID of the blocklist to add users to, i.e.https://bsky.app/profile/<handle>/lists/<this-part>
.SEARCH_TERM
- The search term to find users with. Note that this will find many users that don't exactly match the search term.QUERY
- A Lucene query to filter the found users with.QUIET
(optional) - If set totrue
, the script will not print any output.DRY_RUN
(optional) - If set totrue
, the script will not add any users to the blocklist, only output the users that would be added.
Command line arguments take precedence over environment variables.
options:
-h, --help show this help message and exit
-u USERNAME, --username USERNAME
Your ATProto username.
-p PASSWORD, --password PASSWORD
Your ATProto app password. Generate one at https://bsky.app/settings/app-passwords.
-l LIST_ID, --list-id LIST_ID
The ID of the blocklist to add users to, i.e. https://bsky.app/profile/<handle>/lists/<this-part>.
-s SEARCH_TERM, --search-term SEARCH_TERM
The term to search AT Protocol users for.
-q QUERY, --query QUERY
A Lucene query to filter the found users with. Necessary because the search term will find users that don't exactly match the search term.
-d, --dry-run Whether to simulate adding users to the blocklist without actually doing it. Useful for testing queries.
-x, --quiet Whether to suppress output. Useful if running as a cron job.
This script lets you use a Lucene query using Luqum to precisely match which users you want to add to the blocklist. Note that not all Lucene features are supported.
- You can query these fields:
handle
,display_name
anddescription
. - You can use negative queries to exclude certain values, e.g.
-handle:example
. - You can use
AND
,OR
andNOT
operators. - You can use parentheses to group queries.
- You can use regular expressions using
/
and/
as delimiters.
You can use the --dry-run
flag or DRY_RUN=true
environment values to see which users would be added to the blocklist without actually adding them. Maybe you'll find users who would be added, but for whom you should add a negative part to the query.
handle:example
- Match users that haveexample
in their handle.handle:example AND -display_name:example
- Match users that haveexample
in their handle but not in their display name.handle:/^example/
- Match users that have a handle that starts withexample
.handle:/example$/
- Match users that have a handle that ends withexample
.handle:/example/ OR handle:/test/
- Match users that have a handle that containsexample
ortest
.handle:/example/ AND NOT handle:/test/
- Match users that have a handle that containsexample
but nottest
.handle:example AND (display_name:example OR description:example)
- Match users that have a handle that containsexample
and haveexample
in their display name or description.description:hater AND -description:/anti[- ]hater/
- Match users that havehater
in their description but notanti-hater
oranti hater
.
See utils/test_dict_matcher.py
for some more examples.
These are some example blocklists that are generated using this script. Feel free to add yours here.
- Link: https://bsky.app/profile/andri.io/lists/3lben4phiyh26
- Search term:
e/acc
- Query:
display_name:e/acc AND -display_name:/(anti[- ]e\/acc)/ OR description:e/acc AND -description:/(anti[- ]e\/acc)/
- Full command:
python3 add_to_blocklist.py -l 3lben4phiyh26 -s e/acc -q "display_name:e/acc AND -display_name:/(anti[- ]e\/acc)/ OR description:e/acc AND -description:/(anti[- ]e\/acc)/"
- This script does not automatically update the list. Run it regularly or set up a cron job to do so.
- This script does not remove users from the blocklist if they no longer match the query. This might be added in the future.
- If you block the users in the blocklist, they will not show up in the search results anymore.
This project is licensed under the MIT License - see the LICENSE file for details.