From 93a0deb3db9a94a060a55167487e5017dbdb6300 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 28 Aug 2024 17:37:53 +0100 Subject: [PATCH] Add a default copy.txt, better documentation --- .gitignore | 4 ++-- README.md | 37 ++++++++++++++++++++++++++++++++++++- bot.py | 5 ++--- copy.txt | 9 ++------- data.example/.env | 2 ++ data.example/config.ini | 4 ++++ data.example/copy.txt | 1 + 7 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 data.example/.env create mode 100644 data.example/config.ini create mode 120000 data.example/copy.txt diff --git a/.gitignore b/.gitignore index f0c9c2b..eba06df 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ \ No newline at end of file +data/ +!data.example/* \ No newline at end of file diff --git a/README.md b/README.md index 34975cd..411ac74 100644 --- a/README.md +++ b/README.md @@ -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. + +
+Docker information + +`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 +``` +
+ +## 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. diff --git a/bot.py b/bot.py index 0031a42..1695db5 100644 --- a/bot.py +++ b/bot.py @@ -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() diff --git a/copy.txt b/copy.txt index a9410d2..d285484 100644 --- a/copy.txt +++ b/copy.txt @@ -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) diff --git a/data.example/.env b/data.example/.env new file mode 100644 index 0000000..8b56518 --- /dev/null +++ b/data.example/.env @@ -0,0 +1,2 @@ +# Not automatically read by the program. +LOGLEVEL=DEBUG # case sensitive by the way. \ No newline at end of file diff --git a/data.example/config.ini b/data.example/config.ini new file mode 100644 index 0000000..03e3463 --- /dev/null +++ b/data.example/config.ini @@ -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 diff --git a/data.example/copy.txt b/data.example/copy.txt new file mode 120000 index 0000000..0c70dff --- /dev/null +++ b/data.example/copy.txt @@ -0,0 +1 @@ +../copy.txt \ No newline at end of file