A bot that redirects a given profile to another one, for administration purposes
Find a file
2024-08-28 17:37:53 +01:00
data.example Add a default copy.txt, better documentation 2024-08-28 17:37:53 +01:00
.gitignore Add a default copy.txt, better documentation 2024-08-28 17:37:53 +01:00
bot.py Add a default copy.txt, better documentation 2024-08-28 17:37:53 +01:00
copy.txt Add a default copy.txt, better documentation 2024-08-28 17:37:53 +01:00
Dockerfile Add dockerfile, allow changing base data path to ./data/ 2024-08-28 17:24:04 +01:00
LICENSE Initial commit 2024-08-28 17:16:11 +01:00
README.md Add a default copy.txt, better documentation 2024-08-28 17:37:53 +01:00
requirements.txt Initial commit 2024-08-28 17:16:11 +01:00
tox.ini Initial commit 2024-08-28 17:16:11 +01:00

Fediverse Admin Bot

This is a simple bot designed for misskey (and its forks) to redirect mentions and messages to an unmonitored @admin account to a monitored account.

For example, this bot is running under @admin@fedi.transgender.ing and redirects all mentions and messages to @nex@fedi.transgender.ing, and includes a link to the relevant matrix room. You can see the exact reply in copy.txt.

This bot requires an API key, and the ability to see notifications, create notes, and add reactions to notes. When bot.py is run, it will loop indefinitely, fetching new notifications and processing every minute (configurable).

Installation

Simply clone the repository, or grab the latest release. Then, create a virtualenv, and install the requirements from requirements.txt. This bot was created with Python 3.12, however should be compatible with any version of Python 3.8 or above. It doesn't use any fancy syntax, at least.

There is also a docker image, although you do not need to use docker to run this. It is literally just a blocking python script.

Docker information

docker run:

docker run -it --name fedi-admin-bot -v ./data:/app/data codeberg.org/nexy7574/fediverse-admin-bot:dev

Make sure your files are in the ./data directory.

docker-compose:

services:
    bot:
        image: codeberg.org/nexy7574/fediverse-admin-bot:dev
        volumes:
            - ./data:/app/data
        restart: unless-stopped

Files

config.ini

Before you start, you'll need a config.ini in your working directory. This file should look like this:

[domain.example]  # the domain of the instance you're running on
api_key = your_api_key
sleep_time = 60  # how long to wait between loops, in seconds. Default is 1 minute, if omitted.
limit = 100  # how many notifications to fetch at once.
# If your admin account is getting an absurd amount of traffic, you may need to raise this to ensure that all notifications are processed.

.lastfetch

You need to make sure that the bot can read+write to the ./.lastfetch - this file contains a string, which is the ID of the last fetched notification. Deleting this will cause the bot to reprocess the last :limit: notifications, which may result in double-posting. This file does not have to exist on startup, it will be created. Do not edit this file, unless you want to manually replace what the last fetched notification was.

If you have an ID you would like to use as the epoch, you can either manually write it to that file, or set it as the $EPOCH_ID environment variable.

bot.log

The bot will automatically log all decisions it makes, timestamped, with a reason, to a file called bot.log. This file will be created if it does not exist.

The log file does not automatically rotate. If you want to keep logs for a long time, you will need to manually rotate them. The log file is also not overwritten on startup, it is automatically appended to. It is more of a black-box thing than a debugging tool.

Setting the log level

By default, the log level is set to INFO. If you want to change this, you can set the LOGLEVEL environment variable to one of the following:

  • DEBUG
  • INFO
  • WARNING
  • ERROR
  • CRITICAL

Debug is the most verbose, critical is only for the most severe errors.

copy.txt

This is a plain text file that the bot will read from on each loop, which will be used to reply to mentions and replies. You can use markdown (MFM) in this file, however it will not be previewed in your editors as this is a plain text file.

You can use placeholders in this file. {0} is the JSON of the notification, and {1} is the bot instance. So, {0[note]} will be the note JSON, and {0[note][user][name]} will be the name of the user who sent the note. See more in the misskey API docs, or by looking at the raw note data in the UI.