diff --git a/index.js b/index.js index 1ac9d75..a0c6b09 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -const { execSync } = require('child_process'); +const { execSync, spawn } = require('child_process'); const fs = require('node:fs'); const os = require('os'); @@ -140,7 +140,24 @@ async function startBot(accountName) { } try { - execSync(`timeout 150m bash -c "${commandPrefix} ${commandSuffix}; exit"`, { stdio: 'inherit', shell: '/bin/bash' }); + // execSync(`timeout 150m bash -c "${commandPrefix} ${commandSuffix}; exit"`, { stdio: 'inherit', shell: '/bin/bash' }); + const childProcess = spawn('bash', ['-c', `${commandPrefix} ${commandSuffix}`], { stdio: 'inherit' }); + + childProcess.stdout.on('data', (data) => { + console.log(`[${accountName}] ${data.toString()}`); + if (data.includes('Press enter') || data.includes('Press any key')) { + setTimeout(() => { + childProcess.stdin.write('\n'); + }, 1000); + } + }); + + childProcess.on('close', (code) => { + if (code !== 0) { + consoleLog(`[${host}] Bot process for ${accountName} exited with code ${code}. Restarting...`, 'error'); + startBot(accountName); + } + }); } catch (error) { consoleLog(`[${host}] Failed to start bot for ${accountName}.`, 'error');