fediverse-admin-bot/README.md

90 lines
3.9 KiB
Markdown

# 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](./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.
<details>
<summary>Docker information</summary>
`docker run`:
```sh
docker run -it --name fedi-admin-bot -v ./data:/app/data codeberg.org/nexy7574/fediverse-admin-bot:dev
```
Make sure your [files](#files) are in the `./data` directory.
`docker-compose`:
```yaml
services:
bot:
image: codeberg.org/nexy7574/fediverse-admin-bot:dev
volumes:
- ./data:/app/data
restart: unless-stopped
```
</details>
## Files
### `config.ini`
Before you start, you'll need a `config.ini` in your working directory. This file should look like this:
```ini
[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.