this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: Add automated installation scripts for Windows and Linux

+728
+78
README.md
··· 106 106 107 107 ## Installation 108 108 109 + ### Automated Installation (Recommended) 110 + 111 + #### Linux (Ubuntu, Fedora, Arch) 112 + Run the automated installation script: 113 + 114 + ```bash 115 + ./install.sh 116 + ``` 117 + 118 + This script will: 119 + - Detect your Linux distribution and install required dependencies 120 + - Set up your `.env` configuration interactively 121 + - Install Node.js dependencies 122 + - Create necessary cache directories 123 + - Optionally set up a systemd service for automatic startup 124 + 125 + #### Windows 126 + Run the automated installation batch file: 127 + 128 + ``` 129 + install.bat 130 + ``` 131 + 132 + This script will: 133 + - Check for required dependencies (Node.js, Git, FFmpeg) 134 + - Install missing dependencies using Chocolatey or winget if available 135 + - Guide you through an interactive configuration process 136 + - Install Node.js dependencies 137 + - Create necessary cache directories 138 + - Optionally set up a Windows service using PM2 139 + 140 + ### Manual Installation 141 + 142 + If you prefer to install manually: 143 + 109 144 1. Clone this repository 110 145 2. Install dependencies: 111 146 ``` ··· 121 156 npm install -g pm2 122 157 ``` 123 158 159 + ### Installation Script Details 160 + 161 + The automated installation scripts provide several advantages: 162 + 163 + 1. **Dependency Management** 164 + - Automatically installs Node.js, Git, FFmpeg, and PM2 if missing 165 + - Uses native package managers (apt, dnf, pacman) on Linux 166 + - Utilizes Chocolatey or winget on Windows if available 167 + 168 + 2. **Interactive Configuration** 169 + - Guides you through setting up all required environment variables 170 + - Provides sensible defaults for optional settings 171 + - Validates that required fields like bot token are entered 172 + 173 + 3. **System Integration** 174 + - Configures systemd service on Linux 175 + - Sets up Windows service with PM2 176 + - Creates proper directory structure for media caching 177 + 124 178 ## Environment Variables 125 179 180 + The bot is configured via environment variables in a `.env` file. The installation scripts will help you create this file interactively, but here's a reference of available settings: 181 + 182 + ### Required Settings 126 183 - `BOT_TOKEN`: Your Telegram bot token from BotFather 127 184 - `CHANNEL_ID`: Your Telegram channel ID or username (e.g., @mychannel) 185 + 186 + ### User Access Control 128 187 - `AUTHORIZED_USERS`: Comma-separated list of Telegram user IDs that are allowed to use the bot 188 + - `OWNER_ID`: (Optional) User ID of the bot owner for admin-level commands 189 + 190 + ### Integration Options 191 + - `WEASYL_API_KEY`: (Optional) API key for Weasyl integration 192 + - `DISCORD_WEBHOOK_URL`: (Optional) For Discord integration 193 + - `DISCORD_ENABLED`: Set to 'true' to enable Discord posting 194 + 195 + ### Queue Configuration 196 + - `DEFAULT_CRON_SCHEDULE`: When to post images (cron format, default: '0 */1 * * *' - every hour) 197 + - `IMAGES_PER_INTERVAL`: Number of images to post each time (default: 1) 198 + 199 + ### Queue Monitoring 200 + - `QUEUE_LOW_THRESHOLD`: Alert when queue has this many items or fewer (default: 10) 201 + - `QUEUE_EMPTY_THRESHOLD`: Alert when queue hits this level (default: 0) 202 + - `QUEUE_ALERTS_ENABLED`: Enable/disable queue monitoring (default: true) 203 + - `QUEUE_ALERT_COOLDOWN_HOURS`: Hours between repeated alerts (default: 24) 204 + 205 + ### Media Cache 206 + - `MAX_CACHE_AGE_DAYS`: Days to keep cached media files (default: 15) 129 207 130 208 ## Running the Bot 131 209
+329
install.bat
··· 1 + @echo off 2 + setlocal enabledelayedexpansion 3 + :: Stagehand Telegram Bot Installation Script for Windows 4 + :: This batch file will install the Stagehand Telegram Bot on a Windows system 5 + 6 + echo [INFO] Starting Stagehand Telegram Bot installation... 7 + 8 + :: Check if script is run from the correct directory 9 + if not exist "package.json" ( 10 + echo [ERROR] Please run this script from the root directory of the Stagehand bot project 11 + exit /b 1 12 + ) 13 + 14 + :: Detect available package managers 15 + set HAVE_WINGET=0 16 + set HAVE_CHOCO=0 17 + 18 + where winget >nul 2>nul 19 + if %ERRORLEVEL% equ 0 ( 20 + set HAVE_WINGET=1 21 + echo [INFO] Detected Windows Package Manager (winget) 22 + ) 23 + 24 + where choco >nul 2>nul 25 + if %ERRORLEVEL% equ 0 ( 26 + set HAVE_CHOCO=1 27 + echo [INFO] Detected Chocolatey Package Manager 28 + ) 29 + 30 + echo [INFO] Installing dependencies... 31 + 32 + :: Check if Node.js is installed and install if missing 33 + where node >nul 2>nul 34 + if %ERRORLEVEL% neq 0 ( 35 + echo [WARNING] Node.js is not installed. 36 + 37 + if %HAVE_WINGET% equ 1 ( 38 + echo [INFO] Installing Node.js using winget... 39 + winget install OpenJS.NodeJS.LTS 40 + if %ERRORLEVEL% equ 0 ( 41 + echo [SUCCESS] Node.js installed successfully using winget. 42 + echo [INFO] You may need to restart this script to use the newly installed Node.js. 43 + pause 44 + exit /b 0 45 + ) else ( 46 + echo [ERROR] Failed to install Node.js using winget. 47 + ) 48 + ) else if %HAVE_CHOCO% equ 1 ( 49 + echo [INFO] Installing Node.js using Chocolatey... 50 + choco install nodejs-lts -y 51 + if %ERRORLEVEL% equ 0 ( 52 + echo [SUCCESS] Node.js installed successfully using Chocolatey. 53 + echo [INFO] You may need to restart this script to use the newly installed Node.js. 54 + pause 55 + exit /b 0 56 + ) else ( 57 + echo [ERROR] Failed to install Node.js using Chocolatey. 58 + ) 59 + ) else ( 60 + echo [ERROR] No package manager available. Please install Node.js manually from https://nodejs.org/ and run this script again. 61 + exit /b 1 62 + ) 63 + ) 64 + 65 + :: Check if Git is installed and install if missing 66 + where git >nul 2>nul 67 + if %ERRORLEVEL% neq 0 ( 68 + echo [WARNING] Git is not installed. It's recommended for updates. 69 + 70 + if %HAVE_WINGET% equ 1 ( 71 + echo [INFO] Would you like to install Git using winget? (y/n): 72 + set /p install_git= 73 + if /i "!install_git!"=="y" ( 74 + echo [INFO] Installing Git using winget... 75 + winget install Git.Git 76 + if %ERRORLEVEL% equ 0 ( 77 + echo [SUCCESS] Git installed successfully. 78 + ) else ( 79 + echo [WARNING] Failed to install Git. Continuing anyway... 80 + ) 81 + ) else ( 82 + echo [INFO] Skipping Git installation. 83 + ) 84 + ) else if %HAVE_CHOCO% equ 1 ( 85 + echo [INFO] Would you like to install Git using Chocolatey? (y/n): 86 + set /p install_git= 87 + if /i "!install_git!"=="y" ( 88 + echo [INFO] Installing Git using Chocolatey... 89 + choco install git -y 90 + if %ERRORLEVEL% equ 0 ( 91 + echo [SUCCESS] Git installed successfully. 92 + ) else ( 93 + echo [WARNING] Failed to install Git. Continuing anyway... 94 + ) 95 + ) else ( 96 + echo [INFO] Skipping Git installation. 97 + ) 98 + ) else ( 99 + echo [INFO] You can install Git from https://git-scm.com/downloads 100 + ) 101 + ) 102 + 103 + :: Check if FFmpeg is installed and install if missing 104 + where ffmpeg >nul 2>nul 105 + if %ERRORLEVEL% neq 0 ( 106 + echo [WARNING] FFmpeg is not found in PATH. 107 + 108 + if %HAVE_WINGET% equ 1 ( 109 + echo [INFO] Would you like to install FFmpeg using winget? (y/n): 110 + set /p install_ffmpeg= 111 + if /i "!install_ffmpeg!"=="y" ( 112 + echo [INFO] Installing FFmpeg using winget... 113 + winget install Gyan.FFmpeg 114 + if %ERRORLEVEL% equ 0 ( 115 + echo [SUCCESS] FFmpeg installed successfully. 116 + ) else ( 117 + echo [WARNING] Failed to install FFmpeg. The bot will use built-in ffmpeg package. 118 + ) 119 + ) else ( 120 + echo [INFO] The bot will use built-in ffmpeg package. If you encounter media issues, 121 + echo [INFO] consider installing FFmpeg from https://ffmpeg.org/download.html 122 + ) 123 + ) else if %HAVE_CHOCO% equ 1 ( 124 + echo [INFO] Would you like to install FFmpeg using Chocolatey? (y/n): 125 + set /p install_ffmpeg= 126 + if /i "!install_ffmpeg!"=="y" ( 127 + echo [INFO] Installing FFmpeg using Chocolatey... 128 + choco install ffmpeg -y 129 + if %ERRORLEVEL% equ 0 ( 130 + echo [SUCCESS] FFmpeg installed successfully. 131 + ) else ( 132 + echo [WARNING] Failed to install FFmpeg. The bot will use built-in ffmpeg package. 133 + ) 134 + ) else ( 135 + echo [INFO] The bot will use built-in ffmpeg package. If you encounter media issues, 136 + echo [INFO] consider installing FFmpeg from https://ffmpeg.org/download.html 137 + ) 138 + ) else ( 139 + echo [INFO] The bot will use built-in ffmpeg package. If you encounter media issues, 140 + echo [INFO] consider installing FFmpeg from https://ffmpeg.org/download.html 141 + ) 142 + ) 143 + 144 + :: Install PM2 globally 145 + echo [INFO] Installing PM2 process manager... 146 + call npm install -g pm2 147 + if %ERRORLEVEL% neq 0 ( 148 + echo [WARNING] Failed to install PM2 using npm. Trying alternative methods... 149 + 150 + if %HAVE_CHOCO% equ 1 ( 151 + echo [INFO] Attempting to install PM2 using Chocolatey... 152 + choco install pm2 -y 153 + if %ERRORLEVEL% equ 0 ( 154 + echo [SUCCESS] PM2 installed successfully using Chocolatey. 155 + ) else ( 156 + echo [ERROR] Failed to install PM2. Please install it manually with 'npm install -g pm2'. 157 + exit /b 1 158 + ) 159 + ) else ( 160 + echo [ERROR] Failed to install PM2. Please install it manually with 'npm install -g pm2'. 161 + exit /b 1 162 + ) 163 + ) 164 + 165 + :: Check if .env file exists and decide whether to configure it 166 + if exist ".env" ( 167 + echo [INFO] .env file already exists. Reconfigure it? (y/n): 168 + set /p RECONFIGURE= 169 + if /i "!RECONFIGURE!"=="y" ( 170 + echo [INFO] Backing up existing .env to .env.backup 171 + copy .env .env.backup 172 + goto :ConfigureEnv 173 + ) else ( 174 + echo [INFO] Using existing .env configuration. 175 + goto :ContinueInstall 176 + ) 177 + ) else ( 178 + goto :ConfigureEnv 179 + ) 180 + 181 + :ConfigureEnv 182 + :: Create .env file interactively 183 + echo [INFO] Setting up .env configuration file... 184 + echo [INFO] Please enter the following information (or press Enter for default values): 185 + echo. 186 + 187 + :: Telegram Bot Configuration 188 + echo [CONFIG] === Telegram Bot Configuration === 189 + set /p BOT_TOKEN="Enter Telegram Bot Token (required): " 190 + 191 + if "!BOT_TOKEN!"=="" ( 192 + echo [ERROR] Bot token is required to run the bot. Continuing but you'll need to edit .env later. 193 + ) 194 + 195 + set /p CHANNEL_ID="Enter Telegram Channel ID (required, e.g. @yourchannel): " 196 + if "!CHANNEL_ID!"=="" ( 197 + echo [ERROR] Channel ID is required to run the bot. Continuing but you'll need to edit .env later. 198 + ) 199 + 200 + set /p AUTHORIZED_USERS="Enter Authorized User IDs (comma-separated, e.g. 123456,789012): " 201 + set /p OWNER_ID="Enter Owner User ID (optional): " 202 + 203 + :: Discord Integration 204 + echo. 205 + echo [CONFIG] === Discord Integration (Optional) === 206 + set /p DISCORD_INTEGRATION="Enable Discord integration? (y/n, default: n): " 207 + 208 + set DISCORD_ENABLED=false 209 + set DISCORD_WEBHOOK_URL= 210 + 211 + if /i "!DISCORD_INTEGRATION!"=="y" ( 212 + set DISCORD_ENABLED=true 213 + set /p DISCORD_WEBHOOK_URL="Enter Discord Webhook URL: " 214 + ) 215 + 216 + :: Weasyl API Key 217 + echo. 218 + echo [CONFIG] === Weasyl API Integration (Optional) === 219 + set /p WEASYL_API_KEY="Enter Weasyl API Key (optional): " 220 + 221 + :: Queue Configuration 222 + echo. 223 + echo [CONFIG] === Queue Configuration === 224 + set DEFAULT_CRON_SCHEDULE=0 */1 * * * 225 + set /p CRON_SCHEDULE="Enter posting schedule in cron format (default: 0 */1 * * * - every hour): " 226 + if not "!CRON_SCHEDULE!"=="" set DEFAULT_CRON_SCHEDULE=!CRON_SCHEDULE! 227 + 228 + set IMAGES_PER_INTERVAL=1 229 + set /p IMG_COUNT="Enter number of images to post per interval (default: 1): " 230 + if not "!IMG_COUNT!"=="" set IMAGES_PER_INTERVAL=!IMG_COUNT! 231 + 232 + :: Queue Alert Configuration 233 + echo. 234 + echo [CONFIG] === Queue Monitoring === 235 + set QUEUE_LOW_THRESHOLD=10 236 + set /p LOW_THRESHOLD="Enter queue low threshold for alerts (default: 10): " 237 + if not "!LOW_THRESHOLD!"=="" set QUEUE_LOW_THRESHOLD=!LOW_THRESHOLD! 238 + 239 + set QUEUE_EMPTY_THRESHOLD=0 240 + set /p EMPTY_THRESHOLD="Enter queue empty threshold (default: 0): " 241 + if not "!EMPTY_THRESHOLD!"=="" set QUEUE_EMPTY_THRESHOLD=!EMPTY_THRESHOLD! 242 + 243 + set /p ALERTS_ENABLED="Enable queue alerts? (y/n, default: y): " 244 + set QUEUE_ALERTS_ENABLED=true 245 + if /i "!ALERTS_ENABLED!"=="n" set QUEUE_ALERTS_ENABLED=false 246 + 247 + set QUEUE_ALERT_COOLDOWN_HOURS=24 248 + set /p ALERT_COOLDOWN="Enter hours between repeated alerts (default: 24): " 249 + if not "!ALERT_COOLDOWN!"=="" set QUEUE_ALERT_COOLDOWN_HOURS=!ALERT_COOLDOWN! 250 + 251 + :: Cache Configuration 252 + echo. 253 + echo [CONFIG] === Cache Configuration === 254 + set MAX_CACHE_AGE_DAYS=15 255 + set /p CACHE_AGE="Enter maximum cache age in days (default: 15): " 256 + if not "!CACHE_AGE!"=="" set MAX_CACHE_AGE_DAYS=!CACHE_AGE! 257 + 258 + :: Write the configuration to .env file 259 + echo [INFO] Creating .env file with your configuration... 260 + ( 261 + echo # Telegram Bot Configuration 262 + echo BOT_TOKEN=!BOT_TOKEN! 263 + echo CHANNEL_ID=!CHANNEL_ID! 264 + echo AUTHORIZED_USERS=!AUTHORIZED_USERS! 265 + echo OWNER_ID=!OWNER_ID! 266 + echo. 267 + echo # Discord Integration ^(Optional^) 268 + echo DISCORD_WEBHOOK_URL=!DISCORD_WEBHOOK_URL! 269 + echo DISCORD_ENABLED=!DISCORD_ENABLED! 270 + echo. 271 + echo # Weasyl API Configuration 272 + echo WEASYL_API_KEY=!WEASYL_API_KEY! 273 + echo. 274 + echo # Queue Configuration 275 + echo DEFAULT_CRON_SCHEDULE=!DEFAULT_CRON_SCHEDULE! 276 + echo IMAGES_PER_INTERVAL=!IMAGES_PER_INTERVAL! 277 + echo. 278 + echo # Queue Alert Configuration 279 + echo QUEUE_LOW_THRESHOLD=!QUEUE_LOW_THRESHOLD! 280 + echo QUEUE_EMPTY_THRESHOLD=!QUEUE_EMPTY_THRESHOLD! 281 + echo QUEUE_ALERTS_ENABLED=!QUEUE_ALERTS_ENABLED! 282 + echo QUEUE_ALERT_COOLDOWN_HOURS=!QUEUE_ALERT_COOLDOWN_HOURS! 283 + echo. 284 + echo # Cache Configuration 285 + echo MAX_CACHE_AGE_DAYS=!MAX_CACHE_AGE_DAYS! 286 + ) > .env 287 + 288 + echo [SUCCESS] Configuration file created successfully. 289 + 290 + :ContinueInstall 291 + 292 + :: Install Node.js dependencies 293 + echo [INFO] Installing Node.js dependencies... 294 + call npm install 295 + if %ERRORLEVEL% neq 0 ( 296 + echo [ERROR] Failed to install Node.js dependencies 297 + exit /b 1 298 + ) 299 + 300 + :: Create cache directories 301 + echo [INFO] Creating cache directories... 302 + if not exist "cache\images" mkdir cache\images 303 + if not exist "cache\videos" mkdir cache\videos 304 + if not exist "cache\transcoded" mkdir cache\transcoded 305 + 306 + :: Create Windows service (using PM2) 307 + echo [INFO] Setting up Windows service... 308 + set /p install_service="Do you want to install Stagehand as a Windows service? (y/n): " 309 + if /i "%install_service%"=="y" ( 310 + echo [INFO] Installing as Windows service using PM2... 311 + call pm2 start ecosystem.config.js 312 + call pm2 save 313 + call pm2 startup 314 + echo [INFO] Please run the above command with administrator privileges if needed. 315 + ) else ( 316 + echo [INFO] Skipping Windows service installation. 317 + ) 318 + 319 + echo. 320 + echo [SUCCESS] =============================================================== 321 + echo [SUCCESS] Stagehand Telegram Bot installation completed successfully! 322 + echo [SUCCESS] =============================================================== 323 + echo [INFO] To start the bot manually: npm start 324 + echo [INFO] To view logs: npm run logs 325 + echo [INFO] To stop the bot: npm run stop 326 + echo [INFO] Don't forget to edit the .env file with your credentials! 327 + echo [INFO] For more information, refer to the README.md file. 328 + 329 + pause
+321
install.sh
··· 1 + #!/bin/bash 2 + # Stagehand Telegram Bot Installation Script for Linux 3 + # Supports: Ubuntu/Debian, Fedora, and Arch Linux 4 + 5 + # Color codes for output 6 + GREEN='\033[0;32m' 7 + YELLOW='\033[1;33m' 8 + RED='\033[0;31m' 9 + BLUE='\033[0;34m' 10 + NC='\033[0m' # No Color 11 + 12 + # Function to display colored messages 13 + print_message() { 14 + echo -e "${BLUE}[STAGEHAND]${NC} $1" 15 + } 16 + 17 + print_success() { 18 + echo -e "${GREEN}[SUCCESS]${NC} $1" 19 + } 20 + 21 + print_warning() { 22 + echo -e "${YELLOW}[WARNING]${NC} $1" 23 + } 24 + 25 + print_error() { 26 + echo -e "${RED}[ERROR]${NC} $1" 27 + } 28 + 29 + # Function to detect the Linux distribution 30 + detect_distro() { 31 + if [ -f /etc/os-release ]; then 32 + . /etc/os-release 33 + DISTRO=$ID 34 + elif [ -f /etc/debian_version ]; then 35 + DISTRO="debian" 36 + elif [ -f /etc/fedora-release ]; then 37 + DISTRO="fedora" 38 + elif [ -f /etc/arch-release ]; then 39 + DISTRO="arch" 40 + else 41 + DISTRO="unknown" 42 + fi 43 + print_message "Detected distribution: ${DISTRO}" 44 + return 0 45 + } 46 + 47 + # Function to install dependencies based on the Linux distribution 48 + install_dependencies() { 49 + print_message "Installing dependencies..." 50 + 51 + case $DISTRO in 52 + "ubuntu"|"debian"|"linuxmint") 53 + print_message "Installing for Ubuntu/Debian..." 54 + sudo apt update 55 + sudo apt install -y git nodejs npm ffmpeg 56 + ;; 57 + "fedora") 58 + print_message "Installing for Fedora..." 59 + sudo dnf update -y 60 + sudo dnf install -y git nodejs npm ffmpeg 61 + ;; 62 + "arch"|"manjaro") 63 + print_message "Installing for Arch Linux..." 64 + sudo pacman -Sy --noconfirm git nodejs npm ffmpeg 65 + ;; 66 + *) 67 + print_error "Unsupported distribution. Please install the following manually: git, nodejs, npm, ffmpeg" 68 + return 1 69 + ;; 70 + esac 71 + 72 + # Install PM2 globally 73 + print_message "Installing PM2 process manager..." 74 + sudo npm install -g pm2 75 + 76 + return 0 77 + } 78 + 79 + # Function to create a .env file interactively 80 + create_env_file() { 81 + print_message "Setting up environment configuration..." 82 + 83 + if [ -f .env ]; then 84 + print_warning ".env file already exists." 85 + read -p "Do you want to reconfigure it? (y/n): " reconfigure 86 + if [[ $reconfigure != "y" && $reconfigure != "Y" ]]; then 87 + print_message "Using existing .env configuration." 88 + return 0 89 + fi 90 + 91 + # Backup existing .env 92 + print_message "Backing up existing .env to .env.backup" 93 + cp .env .env.backup 94 + fi 95 + 96 + print_message "Setting up .env configuration file interactively..." 97 + echo "" 98 + 99 + # Telegram Bot Configuration 100 + echo -e "${BLUE}[CONFIG]${NC} === Telegram Bot Configuration ===" 101 + read -p "Enter Telegram Bot Token (required): " BOT_TOKEN 102 + 103 + if [ -z "$BOT_TOKEN" ]; then 104 + print_error "Bot token is required to run the bot. Continuing but you'll need to edit .env later." 105 + fi 106 + 107 + read -p "Enter Telegram Channel ID (required, e.g. @yourchannel): " CHANNEL_ID 108 + if [ -z "$CHANNEL_ID" ]; then 109 + print_error "Channel ID is required to run the bot. Continuing but you'll need to edit .env later." 110 + fi 111 + 112 + read -p "Enter Authorized User IDs (comma-separated, e.g. 123456,789012): " AUTHORIZED_USERS 113 + read -p "Enter Owner User ID (optional): " OWNER_ID 114 + 115 + # Discord Integration 116 + echo "" 117 + echo -e "${BLUE}[CONFIG]${NC} === Discord Integration (Optional) ===" 118 + read -p "Enable Discord integration? (y/n, default: n): " DISCORD_INTEGRATION 119 + 120 + DISCORD_ENABLED="false" 121 + DISCORD_WEBHOOK_URL="" 122 + 123 + if [[ $DISCORD_INTEGRATION == "y" || $DISCORD_INTEGRATION == "Y" ]]; then 124 + DISCORD_ENABLED="true" 125 + read -p "Enter Discord Webhook URL: " DISCORD_WEBHOOK_URL 126 + fi 127 + 128 + # Weasyl API Key 129 + echo "" 130 + echo -e "${BLUE}[CONFIG]${NC} === Weasyl API Integration (Optional) ===" 131 + read -p "Enter Weasyl API Key (optional): " WEASYL_API_KEY 132 + 133 + # Queue Configuration 134 + echo "" 135 + echo -e "${BLUE}[CONFIG]${NC} === Queue Configuration ===" 136 + DEFAULT_CRON_SCHEDULE="0 */1 * * *" 137 + read -p "Enter posting schedule in cron format (default: 0 */1 * * * - every hour): " CRON_SCHEDULE 138 + if [ ! -z "$CRON_SCHEDULE" ]; then 139 + DEFAULT_CRON_SCHEDULE="$CRON_SCHEDULE" 140 + fi 141 + 142 + IMAGES_PER_INTERVAL="1" 143 + read -p "Enter number of images to post per interval (default: 1): " IMG_COUNT 144 + if [ ! -z "$IMG_COUNT" ]; then 145 + IMAGES_PER_INTERVAL="$IMG_COUNT" 146 + fi 147 + 148 + # Queue Alert Configuration 149 + echo "" 150 + echo -e "${BLUE}[CONFIG]${NC} === Queue Monitoring ===" 151 + QUEUE_LOW_THRESHOLD="10" 152 + read -p "Enter queue low threshold for alerts (default: 10): " LOW_THRESHOLD 153 + if [ ! -z "$LOW_THRESHOLD" ]; then 154 + QUEUE_LOW_THRESHOLD="$LOW_THRESHOLD" 155 + fi 156 + 157 + QUEUE_EMPTY_THRESHOLD="0" 158 + read -p "Enter queue empty threshold (default: 0): " EMPTY_THRESHOLD 159 + if [ ! -z "$EMPTY_THRESHOLD" ]; then 160 + QUEUE_EMPTY_THRESHOLD="$EMPTY_THRESHOLD" 161 + fi 162 + 163 + QUEUE_ALERTS_ENABLED="true" 164 + read -p "Enable queue alerts? (y/n, default: y): " ALERTS_ENABLED 165 + if [[ $ALERTS_ENABLED == "n" || $ALERTS_ENABLED == "N" ]]; then 166 + QUEUE_ALERTS_ENABLED="false" 167 + fi 168 + 169 + QUEUE_ALERT_COOLDOWN_HOURS="24" 170 + read -p "Enter hours between repeated alerts (default: 24): " ALERT_COOLDOWN 171 + if [ ! -z "$ALERT_COOLDOWN" ]; then 172 + QUEUE_ALERT_COOLDOWN_HOURS="$ALERT_COOLDOWN" 173 + fi 174 + 175 + # Cache Configuration 176 + echo "" 177 + echo -e "${BLUE}[CONFIG]${NC} === Cache Configuration ===" 178 + MAX_CACHE_AGE_DAYS="15" 179 + read -p "Enter maximum cache age in days (default: 15): " CACHE_AGE 180 + if [ ! -z "$CACHE_AGE" ]; then 181 + MAX_CACHE_AGE_DAYS="$CACHE_AGE" 182 + fi 183 + 184 + # Write the configuration to .env file 185 + print_message "Creating .env file with your configuration..." 186 + cat > .env << EOF 187 + # Telegram Bot Configuration 188 + BOT_TOKEN=$BOT_TOKEN 189 + CHANNEL_ID=$CHANNEL_ID 190 + AUTHORIZED_USERS=$AUTHORIZED_USERS 191 + OWNER_ID=$OWNER_ID 192 + 193 + # Discord Integration (Optional) 194 + DISCORD_WEBHOOK_URL=$DISCORD_WEBHOOK_URL 195 + DISCORD_ENABLED=$DISCORD_ENABLED 196 + 197 + # Weasyl API Configuration 198 + WEASYL_API_KEY=$WEASYL_API_KEY 199 + 200 + # Queue Configuration 201 + DEFAULT_CRON_SCHEDULE=$DEFAULT_CRON_SCHEDULE 202 + IMAGES_PER_INTERVAL=$IMAGES_PER_INTERVAL 203 + 204 + # Queue Alert Configuration 205 + QUEUE_LOW_THRESHOLD=$QUEUE_LOW_THRESHOLD 206 + QUEUE_EMPTY_THRESHOLD=$QUEUE_EMPTY_THRESHOLD 207 + QUEUE_ALERTS_ENABLED=$QUEUE_ALERTS_ENABLED 208 + QUEUE_ALERT_COOLDOWN_HOURS=$QUEUE_ALERT_COOLDOWN_HOURS 209 + 210 + # Cache Configuration 211 + MAX_CACHE_AGE_DAYS=$MAX_CACHE_AGE_DAYS 212 + EOF 213 + 214 + print_success "Configuration file created successfully." 215 + return 0 216 + } 217 + 218 + # Function to install the application 219 + install_app() { 220 + print_message "Installing Stagehand bot..." 221 + 222 + # Install Node.js dependencies 223 + print_message "Installing Node.js dependencies..." 224 + npm install 225 + 226 + if [ $? -ne 0 ]; then 227 + print_error "Failed to install Node.js dependencies" 228 + return 1 229 + fi 230 + 231 + print_success "Stagehand bot installed successfully!" 232 + return 0 233 + } 234 + 235 + # Function to set up systemd service 236 + setup_systemd_service() { 237 + print_message "Setting up systemd service for automatic startup..." 238 + 239 + # Check if user wants to install the service 240 + read -p "Do you want to install Stagehand as a systemd service? (y/n): " install_service 241 + 242 + if [[ $install_service != "y" && $install_service != "Y" ]]; then 243 + print_message "Skipping systemd service installation." 244 + return 0 245 + fi 246 + 247 + # Get current username for service configuration 248 + CURRENT_USER=$(whoami) 249 + CURRENT_DIR=$(pwd) 250 + 251 + # Update the username in the service file 252 + print_message "Updating service file with current user: $CURRENT_USER" 253 + sed -i "s/User=henrick/User=$CURRENT_USER/g" stagehand.service 254 + 255 + # Update working directory in service file 256 + print_message "Updating service file with current directory: $CURRENT_DIR" 257 + sed -i "s|WorkingDirectory=.*|WorkingDirectory=$CURRENT_DIR|g" stagehand.service 258 + 259 + # Run the service installation script 260 + print_message "Installing systemd service..." 261 + sudo ./install-service.sh 262 + 263 + if [ $? -ne 0 ]; then 264 + print_error "Failed to install systemd service" 265 + return 1 266 + fi 267 + 268 + print_success "Systemd service installed successfully!" 269 + return 0 270 + } 271 + 272 + # Main installation function 273 + main() { 274 + print_message "Starting Stagehand Telegram Bot installation..." 275 + 276 + # Check if script is run from the correct directory 277 + if [ ! -f "package.json" ] || [ ! -f "index.js" ]; then 278 + print_error "Please run this script from the root directory of the Stagehand bot project" 279 + exit 1 280 + fi 281 + 282 + # Detect the Linux distribution 283 + detect_distro 284 + 285 + # Install dependencies 286 + install_dependencies 287 + if [ $? -ne 0 ]; then 288 + print_error "Failed to install dependencies" 289 + exit 1 290 + fi 291 + 292 + # Create .env file 293 + create_env_file 294 + 295 + # Install the application 296 + install_app 297 + if [ $? -ne 0 ]; then 298 + print_error "Failed to install application" 299 + exit 1 300 + fi 301 + 302 + # Set up systemd service 303 + setup_systemd_service 304 + 305 + print_message "Creating cache directories..." 306 + mkdir -p cache/images 307 + mkdir -p cache/videos 308 + mkdir -p cache/transcoded 309 + 310 + print_success "===============================================================" 311 + print_success "Stagehand Telegram Bot installation completed successfully!" 312 + print_success "===============================================================" 313 + print_message "To start the bot manually: npm start" 314 + print_message "To view logs: npm run logs" 315 + print_message "To stop the bot: npm run stop" 316 + print_message "Don't forget to edit the .env file with your credentials!" 317 + print_message "For more information, refer to the README.md file." 318 + } 319 + 320 + # Execute main function 321 + main