From d6c851b1f22a1685a9882a19fe035bf0b5008dea Mon Sep 17 00:00:00 2001 From: Anon Date: Sun, 9 Oct 2022 13:05:40 -0700 Subject: [PATCH] Updated to reflect scheduling posts with cron --- README.md | 44 +++++++++++++++++++------------------------ docs/configuration.md | 24 ++++++++++++----------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index f440301..0520c11 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,6 @@ cd CreatePleromaApp/ # Follow the interactive prompts. ``` - If you did everything correctly you should see `Success! :)` at the end of the terminal, as well as your credentials in the format below: ```text settings_server = OrderedDict([ @@ -66,12 +65,12 @@ settings_server = OrderedDict([ settings_reminder = "09/20/2020 02:58PM" settings_encrypt = { - "encrypt": False, - "salt": "", + "encrypt": False, + "salt": "", + "keyfile": None } ``` -If you used encryption, everything in the `settings_server` dictionary will be encrypted and you will have to enter your password every time you start the bot. Copy and paste these values from the terminal into your `src/cfg.py` file. **Make sure you paste over or delete the placeholder values with the same names.** - +If you used encryption, everything in the `settings_server` dictionary will be encrypted. If you used encryption and did not specify a keyfile, you will have to enter your password every time you start the bot. Copy and paste these values from the terminal into your `src/cfg.py` file. **Make sure you paste over or delete the placeholder values with the same names.** ## Posting To begin posting: @@ -80,7 +79,6 @@ To begin posting: - Enter your password if you encrypted your OAuth tokens. - If you symlinked the file in the [Installing](#installing) section you can simply run `miraiNikkiBot` instead of changing directories and starting the bot with `./run.sh` - If everything worked correctly, you should see your first image posted to your account. -- Hit Ctrl+C to stop the bot. - Keep in mind that the bot's default visibility setting is set to unlisted for testing. You may want to update it to public. # Donate @@ -89,29 +87,25 @@ XMR: 493HynLQA4z71b3j9ZDXRNQudpdFW8GxeBGD8ahRctKn97RRurMVd35DqVqdAdjv68TcXTJWUwm BAT: [Basic Attention Token](https://basicattentiontoken.org/) # Useful Tips -## Installing Screen -Most likely, you will want this bot to run over a long period of time. It is probably best to install the `screen` package for your distro so you don't have to have a terminal window constantly open (especially if you are running it from a remote machine such as a Raspberry Pi or server). +## Scheduling posts with cron +Most likely you will want this bot to run over a long period of time. There are a several ways to automate calling a script at regular intervals on Linux. For brevity I will be covering the cron way. + +First off, install cron if it's not already installed: ``` sudo pacman -Syu -sudo pacman -S --needed screen - -# Screen cheatsheet -# To create a new screen session named 'miraiNikkiBot' -screen -S miraiNikkiBot -# To detach from the screen session -Ctrl+a d -# To reconnect to the screen session -screen -r miraiNikkiBot -# List screen sessions -screen -ls -# Kill the screen session -Ctrl+a k y -# Scroll back -Ctrl+a ESC Page Up -# Cancel scroll back -ESC +sudo pacman -S --needed cronie +sudo systemctl enable cronie +sudo systemctl start cronie ``` +Next, run the following commands: +- `crontab -e` +- `25,55 * * * * /absolute/path/to/run.sh >> "/absolute/path/to/log.txt" 2>&1` + - Modify the paths above to suit your preferences +- Save and exit + +If you followed the steps above the cron job should run every 30 minutes at 25 and 55 minutes past the hour. Tail the log file to ensure it's working correctly. + ## Quickly Create Configuration Files Configuration files for Mirai Nikki Bot are just python files. Because of this we can easily create multiple configurations by importing the main configuration file, and overriding the values we need. This is useful for creating holiday and debug configurations without needing to create a new configuration file from scratch. ``` diff --git a/docs/configuration.md b/docs/configuration.md index 7ac4186..bd2fc95 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -39,6 +39,8 @@ Paste the generated credentials from `create_app.py` in the fields below. **`salt:`** The salt value generated by `create_app.py` +**`keyfile:`** The keyfile used for decryption. + ## settings_behavior This is the main configuration setting for the bot. @@ -46,11 +48,11 @@ This is the main configuration setting for the bot. **`feature_set:`** The feature set of the instance you are connecting to ('mainline', 'fedibird', or 'pleroma'). **This bot has only been tested with 'pleroma'.** -**`sleep_seconds:`** The time between posts (in seconds) - **`uploads_per_post:`** The number of times the bot should post after `sleep_seconds` -**`retry_seconds:`** The time the bot should wait before attempting to re-upload a post that failed (in seconds). This value is ignored if the bot experiences a FileNotFoundError (the file was deleted after the bot was started) or encounters a 413 error (file upload size is too large). In either of the two cases the bot will continue posting the next image in the list. +**`max_errors:`** The max consecutive posting errors that should occur before the bot gives up and exits. This usually indicates a temporary problem with the remote server, however if the bot repeatedly fails, and the server is up, it probably means the image is too large to upload. Try reducing the `max_size` variable if this happens. Your image may also be in a format that the remote server rejects, in which case the post should be added to the master blacklist. + +**`retry_seconds:`** The time to wait between post attempts (in seconds). **`content_type:`** The content type of the post ('text/plain' (default), 'text/markdown', 'text/html', 'text/bbcode'). **This bot has only been tested with `'text/plain'` and `'text/markdown'`**. @@ -61,19 +63,19 @@ This is the main configuration setting for the bot. **`debug:`** Set this to true for testing. This will prevent Mirai Nikki Bot from logging into the mastodon instance and asking for your encryption password (meaning that nothing will actually get posted to your account, but it will still do everything else). ## settings_time -Time localization settings. +Time localization settings. Mostly unimplemented. -**`time_format:`** This is used to schedule posts using the `-t` switch. Referenced in `set_pretimer_hour()` +**`time_format:`** Time format. -**`time_format_seconds:`** Unused. Should be the same as `time_format` but with a resolution in seconds. +**`time_format_seconds:`** Should be the same as `time_format` but with a resolution in seconds. -**`date_format:`** This is used to schedule posts using the `-d` switch. Referenced in `set_pretimer_day()` +**`date_format:`** Date format. -**`long_date_format:`** Time and date format. `settings_encrypt["reminder"]` Should be in this format. Referenced in `print_header_stats()` and `_sanity_warnings()` +**`long_date_format:`** Time and date format. `settings_encrypt["reminder"]` Should be in this format. CreatePleromaApp will use this value if available. -**`long_date_seconds_format:`** Unused. Should be the same as `long_date_format` but with a resolution in seconds. +**`long_date_seconds_format:`** Should be the same as `long_date_format` but with a resolution in seconds. -**`long_date_week:`** The same as `long_date_format` but with the day of the week specified. Referenced in `print_header_stats()` +**`long_date_week:`** The same as `long_date_format` but with the day of the week specified. **`datetime:`** A custom time to be printed by the bot if ${datetime} substitution is used in the profile output path. @@ -93,7 +95,7 @@ Below is an explanation of each keyword: * **`skip:`** A tuple of tuples of time ranges to skip. -* **`nsfw:`** A tuple of tuples of time ranges to mark as sensative (nsfw) +* **`nsfw:`** A tuple of tuples of time ranges to mark as sensitive (nsfw) * **`output_name:`** The output path of the string. This string can include the following shell-like variables that the bot will automatically substitute: