From a2c02e699f754856831d5c835905946040a4c87f Mon Sep 17 00:00:00 2001 From: agessaman Date: Mon, 16 Feb 2026 14:59:31 -0800 Subject: [PATCH] Implement automatic creation of config.ini from example file - Added logic to the `install-service.sh` script to automatically create a `config.ini` file from `config.ini.example` if it does not exist in the installation directory. - Included warnings for users if the example file is not found, ensuring proper configuration setup before starting the bot. - Refactored joke command configuration in `core.py` to maintain consistency and clarity in the configuration structure. --- install-service.sh | 13 +++++++++++++ modules/core.py | 47 +++++++++++++++++++++++----------------------- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/install-service.sh b/install-service.sh index 1da1360..85c7fd8 100755 --- a/install-service.sh +++ b/install-service.sh @@ -405,6 +405,19 @@ copy_files_smart "$SCRIPT_DIR" "$INSTALL_DIR" || { exit 1 } +# If no config.ini in install dir, create it from config.ini.example +if [ ! -f "$INSTALL_DIR/config.ini" ]; then + if [ -f "$INSTALL_DIR/config.ini.example" ]; then + cp "$INSTALL_DIR/config.ini.example" "$INSTALL_DIR/config.ini" + print_success "Created $INSTALL_DIR/config.ini from config.ini.example (no config was present)" + elif [ -f "$SCRIPT_DIR/config.ini.example" ]; then + cp "$SCRIPT_DIR/config.ini.example" "$INSTALL_DIR/config.ini" + print_success "Created $INSTALL_DIR/config.ini from config.ini.example (no config was present)" + else + print_warning "config.ini.example not found. Create $INSTALL_DIR/config.ini manually before starting the bot." + fi +fi + # Create venv and install dependencies before chown so the service user ends up # owning a complete, working venv (avoids partial root-owned venv and import errors). print_section "Step 4: Setting Up Python Virtual Environment" diff --git a/modules/core.py b/modules/core.py index a1c3b1d..7dcc080 100644 --- a/modules/core.py +++ b/modules/core.py @@ -518,29 +518,6 @@ startup_advert = false # false: Manual mode - no automatic actions, use !repeater commands to manage contacts (default) auto_manage_contacts = false -[Joke_Command] -# Enable or disable the joke command (true/false) -enabled = true - -# Enable seasonal joke defaults (October: spooky, December: Christmas) -# true: Seasonal defaults are applied (default) -# false: No seasonal defaults (always random) -seasonal_jokes = true - -# Handle long jokes (over 130 characters) -# false: Fetch new jokes until we get a short one (default) -# true: Split long jokes into multiple messages -long_jokes = false - -[DadJoke_Command] -# Enable or disable the dad joke command (true/false) -enabled = true - -# Handle long jokes (over 130 characters) -# false: Fetch new jokes until we get a short one (default) -# true: Split long jokes into multiple messages -long_jokes = false - [Admin_ACL] # Admin Access Control List (ACL) for restricted commands # Only users with public keys listed here can execute admin commands @@ -760,6 +737,30 @@ url_timeout = 10 # true: Use 24-hour UTC format # false: Use 12-hour local format use_zulu_time = false + +[Joke_Command] +# Enable or disable the joke command (true/false) +enabled = true + +# Enable seasonal joke defaults (October: spooky, December: Christmas) +# true: Seasonal defaults are applied (default) +# false: No seasonal defaults (always random) +seasonal_jokes = true + +# Handle long jokes (over 130 characters) +# false: Fetch new jokes until we get a short one (default) +# true: Split long jokes into multiple messages +long_jokes = false + +[DadJoke_Command] +# Enable or disable the dad joke command (true/false) +enabled = true + +# Handle long jokes (over 130 characters) +# false: Fetch new jokes until we get a short one (default) +# true: Split long jokes into multiple messages +long_jokes = false + """ with open(self.config_file, 'w') as f: f.write(default_config)