2024-09-27 06:51:53 +00:00
2024-09-13 11:23:05 +00:00
# nsfwbot for Matrix
2024-09-27 06:51:53 +00:00
`nsfwbot` is a Matrix bot plugin that detects NSFW (Not Safe For Work) images posted in Matrix chat rooms. It uses [nudenet ](https://github.com/notAI-tech/NudeNet ), which includes a deep learning model that efficiently runs without requiring a GPU, with low resource demands.
2024-09-13 11:23:05 +00:00
## Features
2024-09-27 06:51:53 +00:00
- **Image Analysis**: Detects and analyzes images posted in Matrix chats using NudeNet.
- **Redaction of Spammed Images**: Automatically redacts images when users send more than the allowed number within a short time frame.
- **Text Message Parsing**: Analyzes images embedded in text messages.
2024-09-13 11:23:05 +00:00
- **Custom Actions**: Configurable actions for detected content, including reporting and redacting messages.
## Requirements
- **Maubot**: Runs within the Maubot framework.
2024-09-27 06:51:53 +00:00
- **Python Dependencies**: `nudenet` , `beautifulsoup4` , and `maubot` .
To install the dependencies, you can find them listed in the `requirements.txt` :
```plaintext
beautifulsoup4
nsfwdetection
maubot
```
2024-09-13 11:23:05 +00:00
## Installation
1. **Use the Custom Maubot Docker Image** :
Replace the official Maubot image with a custom Debian-based image:
```bash
docker pull ghcr.io/tcpipuk/maubot:debian
```
2024-09-27 06:51:53 +00:00
2. a. **Install pre-prepared plugin from [repository releases](https://git.buechner.me/nbuechner/matrix-nsfwbot/releases)**
2024-09-13 11:23:05 +00:00
b. **Clone the Repository** :
```bash
2024-09-27 06:51:53 +00:00
git clone https://git.buechner.me/nbuechner/matrix-nsfwbot
2024-09-13 11:23:05 +00:00
```
2024-09-27 06:51:53 +00:00
Zip the plugin files and upload through the Maubot admin interface. Ensure the plugin is configured and enabled.
2024-09-13 11:23:05 +00:00
3. **Configure the Plugin** :
2024-09-27 06:51:53 +00:00
Edit `base-config.yaml` to set:
2024-09-13 11:23:05 +00:00
2024-09-27 06:51:53 +00:00
- `max_concurrent_jobs` : Number of concurrent jobs to allow.
- `via_servers` : List of servers for `matrix.to` URLs.
- `actions` :
- `ignore_sfw` : Ignore SFW images (default: `true` ).
- `redact_nsfw` : Redact NSFW messages (default: `true` ).
- `direct_reply` : Reply directly in the same room (default: `false` ).
- `report_to_room` : Room ID for reporting (optional).
- `max_images` : The maximum number of images a user can send within a certain time window (default: `3` ).
- `time_window` : The time window (in seconds) in which the image count is tracked (default: `60` seconds).
2024-09-13 11:23:05 +00:00
2024-09-27 06:53:26 +00:00
> **Note** `report_to_room` can be a room alias (like `#room:server`), but it is more efficient to use a room ID (`!room:server`).
2024-09-13 11:23:05 +00:00
## Usage
2024-09-27 06:51:53 +00:00
Once installed and configured, `nsfwbot` will automatically analyze images posted in the chat and:
- Classify images as NSFW or SFW.
- Redact images if a user exceeds the configured spam limit (`max_images`).
- Optionally report detected NSFW content to a configured room.
Example output:
2024-09-13 11:23:05 +00:00
```markdown
mxc://matrix.org/abcd1234 in https://matrix.to/#/!roomid:matrix.org/$eventid?via=matrix.org appears NSFW with score 87.93%
```
If multiple images are detected in a text message:
```markdown
- mxc://matrix.org/abcd1234 in https://matrix.to/#/!roomid:matrix.org/$eventid?via=matrix.org appears SFW with score 2.45%
- mxc://matrix.org/efgh5678 in https://matrix.to/#/!roomid:matrix.org/$eventid?via=matrix.org appears NSFW with score 94.82%
```
2024-09-27 06:51:53 +00:00
If a user sends too many images:
```markdown
User @example:matrix .org has exceeded the image limit. Previous images redacted.
```
2024-09-13 11:23:05 +00:00