···11-# skywatch-tools
11+# Skywatch Automod
22+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.
44+55+## Features
66+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
23033-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
3131+- Node.js (v20 or higher recommended)
3232+- `bun` package manager
3333+- A Bluesky account for the bot.
3434+- A Bluesky labeler account
43555-## Installation and Setup
3636+### 1. Installation
63777-To install dependencies:
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
7575+# Build the container
2276docker build -pull -t skywatch-automod .
7777+7878+# Run the container
2379docker run -d -p 4101:4101 skywatch-automod
2480```
25812626-## Brief overview
8282+Make sure your `.env` file is present when building the Docker image, as it will be copied into the container.
27832828-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.
8484+#### Configuration Variables
29853030-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.
8686+The following environment variables are used for configuration:
31873232-For information on how to set-up your own checks, please see the [developing_checks.md](./src/developing_checks.md) file.
3333-3434-_TODO_:
3535-3636-- [ ] 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)
4141-4242-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.
8888+| Variable | Description | Default |
8989+| ------------------------ | ---------------------------------------------------------------- | ----------------------------------------- |
9090+| `DID` | The DID of your moderation service for atproto-proxy headers. | `""` |
9191+| `OZONE_URL` | The URL of the Ozone service. | `""` |
9292+| `OZONE_PDS` | The Public Downstream Service for Ozone. | `""` |
9393+| `BSKY_HANDLE` | The handle (username) of the bot's Bluesky account. | `""` |
9494+| `BSKY_PASSWORD` | The app password for the bot's Bluesky account. | `""` |
9595+| `HOST` | The host on which the server runs. | `127.0.0.1` |
9696+| `PORT` | The port for the main application (currently unused). | `4100` |
9797+| `METRICS_PORT` | The port for the Prometheus metrics server. | `4101` |
9898+| `FIREHOSE_URL` | The WebSocket URL for the Bluesky firehose. | `wss://jetstream.atproto.tools/subscribe` |
9999+| `CURSOR_UPDATE_INTERVAL` | How often to save the firehose cursor to disk (in milliseconds). | `60000` |
100100+| `LABEL_LIMIT` | (Optional) API call limit for labeling. | `undefined` |
101101+| `LABEL_LIMIT_WAIT` | (Optional) Wait time when label limit is hit. | `undefined` |
102102+| `LOG_LEVEL` | The logging level. | `info` |