···11-MOD_DID=did:plc:xxx
22-OZONE_URL=ozone.example.xyz
33-OZONE_PDS=mushroom.us-region.host.bsky.network
44-BSKY_HANDLE=mod.example.xyz
55-BSKY_PASSWORD=xxxx
11+MOD_DID=
22+OZONE_URL=
33+OZONE_PDS=
44+BSKY_HANDLE=
55+BSKY_PASSWORD=
66HOST=127.0.0.1
77-PORT=4000 // Not currently used
77+PORT=4000
88METRICS_PORT=4001
99-FIREHOSE_URL=wss://jetstream1.us-east.bsky.network/subscribe
99+FIREHOSE_URL=
1010CURSOR_UPDATE_INTERVAL=10000
1111LABEL_LIMIT=2900 * 1000
1212LABEL_LIMIT_WAIT=300 * 1000
+83-21
README.md
···11-# skywatch-tools
11+# Skywatch Automod
2233-This is a rewrite of the original skywatch-tools project in TypeScript. The original project was written in Bash. The purpose of this project is to automate the moderation by the Bluesky independent labeler skywatch.blue
33+This project provides tools for automating moderation of the Bluesky social network. It listens to the Bluesky firehose stream, analyzes various types of content against user-defined rules, and performs moderation actions such as applying labels, reporting content, or leaving comments.
4455-## Installation and Setup
55+## Features
6677-To install dependencies:
77+- **Real-time Moderation:** Monitors the Bluesky firehose in real-time.
88+- **Content-Aware Analysis:** Analyzes posts, user profiles (display names, descriptions), and handles
99+- **Flexible Rule Engine:** Uses regular expressions for defining moderation checks.
1010+- **Variety of Actions:** Can apply labels, create reports (for posts or accounts), and post comments on accounts.
1111+- **Configurable:** Highly configurable through environment variables and a central constants file.
1212+- **Allowlisting:** Supports allowlisting for DIDs and text patterns to reduce false positives.
1313+- **URL Unshortening:** Automatically resolves shortened URLs in posts before checking them.
1414+- **Monitoring:** Exposes a Prometheus metrics endpoint to monitor its activity. (untested)
1515+- **Resilient:** Persists the firehose cursor to gracefully handle restarts without missing events.
1616+1717+## How It Works
1818+1919+The application connects to the Bluesky firehose and subscribes to a set of collections (e.g., posts, profiles). When a new event is received, it is passed through a series of checks defined in `src/constants.ts`. These checks are categorized by content type:
2020+2121+- `POST_CHECKS`: For post content and links.
2222+- `HANDLE_CHECKS`: For user handles.
2323+- `PROFILE_CHECKS`: For user display names and descriptions.
2424+2525+If the content matches a check's criteria (and is not excluded by an allowlist), a corresponding moderation action is triggered. These actions (labeling, reporting, etc.) are performed using the Bluesky API.
2626+2727+## Getting Started
2828+2929+### Prerequisites
3030+3131+- Node.js (v20 or higher recommended)
3232+- `bun` package manager
3333+- A Bluesky account for the bot.
3434+- A Bluesky labeler account
3535+3636+### 1. Installation
3737+3838+Clone the repository and install the dependencies:
839940```bash
1010-bun i
4141+git clone <repository-url>
4242+cd skywatch-automod-public
4343+bun install
1144```
12451313-Modify .env.example with your own values and rename it to .env
4646+### Configuration
4747+4848+There are two main configuration files you need to set up:
4949+5050+- **Checks (`src/constants.ts`):**
5151+ This file defines the rules for your automod. You need to create it by copying the example file:
5252+5353+ ```bash
5454+ cp src/constants.ts.example src/constants.ts
5555+ ```
5656+5757+ Then, edit `src/constants.ts` to define your own checks. For detailed instructions on how to create checks, please see [developing_checks.md](./src/developing_checks.md).
5858+5959+- **Environment Variables (`.env`):**
6060+ This file contains credentials and other runtime configuration. You will need to create a `.env` file and populate it with your specific values. You can use `.env.example` as a reference if it exists in the
6161+6262+### 3. Running the Application
6363+6464+Once configured, you can start the automod with:
14651566```bash
1667bun run start
1768```
18691919-To run in docker:
7070+### 4. Running with Docker
7171+7272+You can also build and run the application as a Docker container.
20732174```bash
2222-docker build -pull -t skywatch-automod .
2323-docker run -d -p 4101:4101 skywatch-automod
7575+docker compose up --build
2476```
25772626-## Brief overview
7878+To run it in the background, add the `-d` flag:
27792828-Currently this tooling does one thing. It monitors the bluesky firehose and analyzes content for phrases which fit Skywatch's criteria for moderation. If the criteria is met, it can automatically label the content with the appropriate label.
2929-3030-In certain cases, where regexp will create too many false positives, it will flag content as a report against related to the account, so that it can be reviewed later.
8080+```bash
8181+docker compose up --build -d
8282+```
31833232-For information on how to set-up your own checks, please see the [developing_checks.md](./src/developing_checks.md) file.
8484+Make sure your `.env` file is present when building the Docker image, as it will be copied into the container. We recommend creating an empty `cursor.txt` file in the application root directory as well.
33853434-_TODO_:
8686+#### Configuration Variables
35873636-- [ ] Remove unused types
3737-- [ ] Update the types needed to be more specific to the checks rather than bluesky content types
3838-- [ ] Consider how to write directly to OzonePDS database rather than using the API. May require running the same instance as Ozone to allow for direct database access.
3939-- [ ] Add compose.yaml for easy deployment
4040-- [ ] Make the metrics server work (or remove it)
8888+The following environment variables are used for configuration:
41894242-Create a seperate program to watch OZONE_PDS firehose labels, and update the lists as needed. This will remove dependency on broken ruby tools created by aegis.
9090+| Variable | Description | Default |
9191+| ------------------------ | ---------------------------------------------------------------- | ----------------------------------------- |
9292+| `DID` | The DID of your moderation service for atproto-proxy headers. | `""` |
9393+| `OZONE_URL` | The URL of the Ozone service. | `""` |
9494+| `OZONE_PDS` | The Public Downstream Service for Ozone. | `""` |
9595+| `BSKY_HANDLE` | The handle (username) of the bot's Bluesky account. | `""` |
9696+| `BSKY_PASSWORD` | The app password for the bot's Bluesky account. | `""` |
9797+| `HOST` | The host on which the server runs. | `127.0.0.1` |
9898+| `PORT` | The port for the main application (currently unused). | `4100` |
9999+| `METRICS_PORT` | The port for the Prometheus metrics server. | `4101` |
100100+| `FIREHOSE_URL` | The WebSocket URL for the Bluesky firehose. | `FIREHOSE_URL=wss://jetstream1.us-east.bsky.network/subscribe` |
101101+| `CURSOR_UPDATE_INTERVAL` | How often to save the firehose cursor to disk (in milliseconds). | `60000` |
102102+| `LABEL_LIMIT` | (Optional) API call limit for labeling. | `undefined` |
103103+| `LABEL_LIMIT_WAIT` | (Optional) Wait time when label limit is hit. | `undefined` |
104104+| `LOG_LEVEL` | The logging level. | `info` |
+1-1
src/config.ts
···1111 ? Number(process.env.METRICS_PORT)
1212 : 4101; // Left this intact from the code I adapted this from
1313export const FIREHOSE_URL =
1414- process.env.FIREHOSE_URL ?? "wss://jetstream.atproto.tools/subscribe";
1414+ process.env.FIREHOSE_URL ?? "wss://jetstream1.us-east.bsky.network/subscribe";
1515export const WANTED_COLLECTION = [
1616 "app.bsky.feed.post",
1717 "app.bsky.actor.defs",