From ac5d2a60bd858299002d2c22d59276131871e16b Mon Sep 17 00:00:00 2001 From: david-hummingbot <85695272+david-hummingbot@users.noreply.github.com> Date: Wed, 21 Jan 2026 22:00:14 +0800 Subject: [PATCH 1/2] fix config and pickle file issues --- setup-environment.sh | 105 ++++++++++++++++++++++++++++++++----------- 1 file changed, 79 insertions(+), 26 deletions(-) diff --git a/setup-environment.sh b/setup-environment.sh index 5d2a885..41190e0 100755 --- a/setup-environment.sh +++ b/setup-environment.sh @@ -2,8 +2,19 @@ # Configuration ENV_FILE=".env" +CONFIG_FILE="config.yml" DATA_DIR="data" +# Escape special characters for .env file +escape_env_value() { + local value="$1" + # Escape backslashes, double quotes, and dollar signs + value="${value//\\/\\\\}" + value="${value//\"/\\\"}" + value="${value//\$/\\\$}" + echo "$value" +} + echo "===================================" echo " Condor Bot Setup" echo "===================================" @@ -15,33 +26,66 @@ if [ -f "$ENV_FILE" ]; then echo ">> Credentials already exist. Skipping setup params." echo "" else - # 2. Prompt for Telegram Bot Token + # 2. Prompt for Telegram Bot Token with validation echo "" - read -p "Enter your Telegram Bot Token: " telegram_token + while true; do + echo -n "Enter your Telegram Bot Token: " + read -r telegram_token < /dev/tty || telegram_token="" + telegram_token=$(echo "$telegram_token" | tr -d '[:space:]') + + if [ -z "$telegram_token" ]; then + echo "⚠️ Telegram Bot Token cannot be empty. Please try again." + continue + fi + + # Validate token format: digits:alphanumeric + if ! [[ "$telegram_token" =~ ^[0-9]+:[A-Za-z0-9_-]+$ ]]; then + echo "⚠️ Invalid Telegram Bot Token format." + echo " Expected format: 123456789:ABCdefGHIjklMNOpqrsTUVwxyz" + echo " Please enter a valid token." + continue + fi + + break + done - # 3. Prompt for Admin User ID + # 3. Prompt for Admin User ID with validation echo "" echo "Enter your Telegram User ID (you will be the admin)." echo "(Tip: Message @userinfobot on Telegram to get your ID)" - read -p "Admin User ID: " admin_id + while true; do + echo -n "Admin User ID: " + read -r admin_id < /dev/tty || admin_id="" + admin_id=$(echo "$admin_id" | tr -d '[:space:]') + + if [ -z "$admin_id" ]; then + echo "⚠️ Admin User ID cannot be empty. Please try again." + continue + fi + + # Validate user ID is numeric + if ! [[ "$admin_id" =~ ^[0-9]+$ ]]; then + echo "⚠️ Invalid User ID. User ID should be numeric (e.g., 123456789)." + continue + fi + + break + done # 4. Prompt for OpenAI API Key (optional) echo "" echo "Enter your OpenAI API Key (optional, for AI features)." echo "Press Enter to skip if not using AI features." - read -p "OpenAI API Key: " openai_key - - # Clean whitespaces from inputs - telegram_token=$(echo "$telegram_token" | tr -d '[:space:]') - admin_id=$(echo "$admin_id" | tr -d '[:space:]') + echo -n "OpenAI API Key: " + read -r openai_key < /dev/tty || openai_key="" openai_key=$(echo "$openai_key" | tr -d '[:space:]') - # 5. Create .env file + # 5. Create .env file with escaped values { - echo "TELEGRAM_TOKEN=$telegram_token" - echo "ADMIN_USER_ID=$admin_id" + echo "TELEGRAM_TOKEN=$(escape_env_value "$telegram_token")" + echo "ADMIN_USER_ID=$(escape_env_value "$admin_id")" if [ -n "$openai_key" ]; then - echo "OPENAI_API_KEY=$openai_key" + echo "OPENAI_API_KEY=$(escape_env_value "$openai_key")" fi } > "$ENV_FILE" @@ -55,17 +99,26 @@ if [ ! -d "$DATA_DIR" ]; then mkdir -p "$DATA_DIR" fi -# 7. Display Run Instructions -echo "===================================" -echo " How to Run Condor" -echo "===================================" -echo "" -echo "Option 1: Docker (Recommended)" -echo " make deploy" -echo "" -echo "Option 2: Local Python" -echo " make run" +# 7. Create blank config.yml if it doesn't exist +if [ -f "$CONFIG_FILE" ]; then + echo "" + echo ">> Found existing $CONFIG_FILE file." + echo ">> Configuration already exists." +else + echo "" + echo "Creating blank $CONFIG_FILE file..." + touch "$CONFIG_FILE" + echo "✅ $CONFIG_FILE created successfully!" + echo "" + echo "Note: You can add Hummingbot API servers and manage access" + echo " using the /config command in your Telegram bot." +fi + +# 8. Display Run Instructions echo "" -echo "On first run, config.yml will be auto-created." -echo "Use /config in the bot to add servers and manage access." -echo "===================================" +echo "✅ Setup Complete! Environment and config files are ready." +echo "==========================================================" +echo "🚀 RUN: 'make deploy' (Docker) or 'make run' (Local)" +echo "🛠️ CMDS: make stop, restart, logs, ps, install" +echo "🤖 NEXT: Open Telegram, use /servers to add API servers" +echo "==========================================================" From 40e57b6a2086ac63fd481091e6f66fd83dd8417b Mon Sep 17 00:00:00 2001 From: david-hummingbot <85695272+david-hummingbot@users.noreply.github.com> Date: Wed, 21 Jan 2026 22:01:02 +0800 Subject: [PATCH 2/2] Change bot data persistence file location in Docker Updated volume mapping for bot persistence file location. --- docker-compose.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9c9e2bd..745b202 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,11 +6,13 @@ services: environment: TELEGRAM_TOKEN: ${TELEGRAM_TOKEN} ADMIN_USER_ID: ${ADMIN_USER_ID} + # Where to store the bot persistence file inside the container + CONDOR_PERSISTENCE_FILE: /app/data/condor_bot_data.pickle env_file: - .env volumes: - # Persist bot data (user preferences, trading context, etc.) - - ./condor_bot_data.pickle:/app/condor_bot_data.pickle + # The pickle file will be created as /app/data/condor_bot_data.pickle. + - ./data:/app/data # Mount config (servers, users, permissions) - ./config.yml:/app/config.yml # Mount routines for auto-discovery