Add a default copy.txt, better documentation

This commit is contained in:
Nexus 2024-08-28 17:37:53 +01:00
parent d8916d907f
commit 93a0deb3db
7 changed files with 49 additions and 13 deletions

4
.gitignore vendored
View file

@ -283,6 +283,6 @@ pyrightconfig.json
# End of https://www.toptal.com/developers/gitignore/api/pycharm+all,visualstudiocode,python
config.ini
.env
notes.json
.lastfetch
data/
data/
!data.example/*

View file

@ -14,7 +14,33 @@ fetching new notifications and processing every minute (configurable).
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.
### config.ini
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:
@ -53,3 +79,12 @@ By default, the log level is set to `INFO`. If you want to change this, you can
* `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.

5
bot.py
View file

@ -32,13 +32,12 @@ limit = int(config[server_domain].get("limit", 100))
bot = Misskey(server_domain, api_key)
with open(BASE / "copy.txt") as _fd:
copy = _fd.read()
def main():
print("Bot running.")
while True:
with open(BASE / "copy.txt") as _fd:
copy = _fd.read()
try:
with open(BASE / ".lastfetch", "r") as fd:
lastfetch = fd.read()

View file

@ -1,8 +1,3 @@
Hello {0[user][name]}!
Unfortunately, this account is automated and not checked by a human.
If you would like to get in contact with an administrator, please contact @nex@fedi.transgender.ing.
Default response from [fediverse-admin-bot](https://codeberg.org/nexy7574/fediverse-admin-bot) - bot admin needs to change copy.txt!
To make a report, please use your client's report feature.
If you are experiencing issues with fedi.transgender.ing, please contact an administrator.
You can join our Matrix room here: https://matrix.to/#/#fedi:transgender.ing?via=nexy7574.co.uk&via=matrix.org&via=envs.net
If you're my admin, see: [README](https://codeberg.org/nexy7574/fediverse-admin-bot/src/branch/dev/README.md#files)

2
data.example/.env Normal file
View file

@ -0,0 +1,2 @@
# Not automatically read by the program.
LOGLEVEL=DEBUG # case sensitive by the way.

4
data.example/config.ini Normal file
View file

@ -0,0 +1,4 @@
[domain.example]
api_key = my_api_key
sleep_time = 30 # 30 second loop
limit = 10 # only fetch 10 notifications per loop

1
data.example/copy.txt Symbolic link
View file

@ -0,0 +1 @@
../copy.txt