Automatic keyword filtering for Mastodon trending topics.
For the longest time I've been manually keyword filtering posts in the trending topics section to remove inflammatory trending topics that aren't topical to our server. There currently isn't an API endpoint to manage this, so this script uses Puppeteer to log in using a moderator account and navigate the admin section manually.
This script needs:
- a username & password for an account with moderator access. This is not amazingly secure, so probably make a new one rather than using your admin account.
- public API access to retrieve posts as json
- install dependencies with
npm ci
- Set environment variables (see .env-example for examples)
npm start
Env var | Description |
---|---|
MASTODON_SERVER | server to connect to (e.g. "bne.social") |
MASTODON_EMAIL | user to log in as (e.g. "[email protected]") |
MASTODON_PASS | password to the user account |
ALLOWLISTED_SERVERS | servers that get automatically approved |
REJECTED_KEYWORDS | comma separated keywords to reject. case insensitive. (e.g. "trump,musk,uspol") |
REJECTED_KEYWORDS_CASE_SENSITIVE | comma separated keywords to reject. case sensitive. (e.g. "USA") |
OVERRIDE_KEYWORDS | comma separated keywords that override a rejection. case insensitive. (e.g. "auspol") |
CRON | optional crontab syntax to rerun this script |
LANGUAGES | optional languages to allow, others will be filtered out |