matrix-nsfwbot/README.md
2024-09-27 08:53:26 +02:00

3.2 KiB

nsfwbot for Matrix

nsfwbot is a Matrix bot plugin that detects NSFW (Not Safe For Work) images posted in Matrix chat rooms. It uses nudenet, which includes a deep learning model that efficiently runs without requiring a GPU, with low resource demands.

Features

  • 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.
  • Custom Actions: Configurable actions for detected content, including reporting and redacting messages.

Requirements

  • Maubot: Runs within the Maubot framework.

  • Python Dependencies: nudenet, beautifulsoup4, and maubot.

    To install the dependencies, you can find them listed in the requirements.txt:

    beautifulsoup4
    nsfwdetection
    maubot
    

Installation

  1. Use the Custom Maubot Docker Image: Replace the official Maubot image with a custom Debian-based image:

    docker pull ghcr.io/tcpipuk/maubot:debian
    
  2. a. Install pre-prepared plugin from repository releases

    b. Clone the Repository:

    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.

  3. Configure the Plugin: 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: 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).

    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 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:

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:

- 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%

If a user sends too many images:

User @example:matrix.org has exceeded the image limit. Previous images redacted.