- small fixes
- README.md update
This commit is contained in:
parent
a548d8fc91
commit
bb8e2411f2
3 changed files with 45 additions and 29 deletions
70
README.md
70
README.md
|
@ -1,23 +1,29 @@
|
|||
|
||||
# nsfwbot for Matrix
|
||||
|
||||
`nsfwbot` is a Matrix bot plugin that attempts to detect NSFW (Not Safe For Work) images posted in
|
||||
Matrix chat rooms. It uses [nsfwdetection](https://github.com/gsarridis/NSFW-Detection-Pytorch),
|
||||
which includes a small model that can run without a GPU with low resource requirements.
|
||||
`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.
|
||||
|
||||
## Features
|
||||
|
||||
- **Image Analysis**: Detects and analyses images posted in Matrix chats.
|
||||
- **Text Message Parsing**: Analyses images embedded in text messages.
|
||||
- **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.
|
||||
- **Configurable Concurrency**: Controls concurrent image processing tasks.
|
||||
- **Custom Actions**: Configurable actions for detected content, including reporting and redacting messages.
|
||||
|
||||
## Requirements
|
||||
|
||||
- **Maubot**: Runs within the Maubot framework.
|
||||
- **Python Dependencies**: `nsfwdetection` and `beautifulsoup4`.
|
||||
> **Note**: `nsfwdetection` will not run on Alpine Linux. This means the default Maubot Docker
|
||||
> image will not work. I have built a custom Debian-based Maubot in the
|
||||
> `ghcr.io/tcpipuk/maubot:debian` Docker image.
|
||||
- **Python Dependencies**: `nudenet`, `beautifulsoup4`, and `maubot`.
|
||||
|
||||
> **Note**: The `nudenet` package and other dependencies will not run on Alpine Linux, so use the custom Debian-based Maubot Docker image.
|
||||
|
||||
To install the dependencies, you can find them listed in the `requirements.txt`:
|
||||
```plaintext
|
||||
beautifulsoup4
|
||||
nsfwdetection
|
||||
maubot
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
|
@ -28,38 +34,40 @@ which includes a small model that can run without a GPU with low resource requir
|
|||
docker pull ghcr.io/tcpipuk/maubot:debian
|
||||
```
|
||||
|
||||
2. a. **Install pre-prepared plugin from [repository releases](https://github.com/tcpipuk/matrix-nsfwbot/releases)**
|
||||
2. a. **Install pre-prepared plugin from [repository releases](https://git.buechner.me/nbuechner/matrix-nsfwbot/releases)**
|
||||
|
||||
b. **Clone the Repository**:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/tcpipuk/matrix-nsfwbot
|
||||
git clone https://git.buechner.me/nbuechner/matrix-nsfwbot
|
||||
```
|
||||
|
||||
Zip the plugin files and upload through the Maubot admin interface. Ensure the plugin is
|
||||
configured and enabled.
|
||||
Zip the plugin files and upload through the Maubot admin interface. Ensure the plugin is configured and enabled.
|
||||
|
||||
3. **Configure the Plugin**:
|
||||
See configuration section below for a summary of settings in the Maubot UI.
|
||||
Edit `base-config.yaml` to set:
|
||||
|
||||
## Configuration
|
||||
- `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).
|
||||
|
||||
Edit `base-config.yaml` to set:
|
||||
|
||||
- `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: `false`).
|
||||
- `direct_reply`: Reply directly in the same room (default: `false`).
|
||||
- `report_to_room`: Room ID for reporting (not enabled by default).
|
||||
> **Note**: This can be a room alias (like `#room:server`) but this is far less efficient,
|
||||
as the bot will need to find the room ID (like `!room:server`) to send messages.
|
||||
> **Note**: `report_to_room` can be a room alias (like `#room:server`), but it is more efficient to use a room ID (`!room:server`).
|
||||
|
||||
## Usage
|
||||
|
||||
Once installed and configured, `nsfwbot` will automatically analyse images posted in the chat and
|
||||
reply with a classification result, e.g.
|
||||
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:
|
||||
|
||||
```markdown
|
||||
mxc://matrix.org/abcd1234 in https://matrix.to/#/!roomid:matrix.org/$eventid?via=matrix.org appears NSFW with score 87.93%
|
||||
|
@ -72,6 +80,12 @@ If multiple images are detected in a text message:
|
|||
- mxc://matrix.org/efgh5678 in https://matrix.to/#/!roomid:matrix.org/$eventid?via=matrix.org appears NSFW with score 94.82%
|
||||
```
|
||||
|
||||
If a user sends too many images:
|
||||
|
||||
```markdown
|
||||
User @example:matrix.org has exceeded the image limit. Previous images redacted.
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome! Open an issue or submit a pull request on GitHub.
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import time
|
||||
from bs4 import BeautifulSoup
|
||||
from collections import defaultdict
|
||||
from maubot import Plugin
|
||||
from nudenet import NudeDetector
|
||||
|
@ -12,7 +13,6 @@ from mautrix.types import (
|
|||
)
|
||||
from mautrix.errors import MBadJSON, MForbidden
|
||||
from maubot.handlers import command, event
|
||||
#from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
# Initialize NudeDetector
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
|
||||
beautifulsoup4
|
||||
nsfwdetection
|
||||
maubot
|
||||
nudenet
|
||||
|
|
Loading…
Reference in a new issue