From 41a09040ed1a4ae170733bb0dd1e7a47fc111245 Mon Sep 17 00:00:00 2001 From: ShadowVR Date: Fri, 31 May 2024 16:40:10 -0400 Subject: [PATCH] Updated index.js --- index.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 12a2042..cacac55 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ - const Discord = require('discord.js'); const chalk = require('chalk'); const fs = require('node:fs'); @@ -88,24 +87,45 @@ async function updateBotFromGitHub() { // Force update by resetting to the latest commit on the remote main branch await git.reset(['--hard', 'origin/main']); - console.log('Bot updated from GitHub. Restarting...'); - - // Restart the bot to apply changes - process.exit(); + console.log('Bot updated from GitHub.'); } catch (error) { console.error('Error updating bot from GitHub:', error); } } +function startBot() { + console.log('Starting the bot...'); + const botProcess = exec('node bot.js', { + cwd: path.resolve(__dirname), + }); + + botProcess.stdout.on('data', (data) => { + console.log(data.toString()); + }); + + botProcess.stderr.on('data', (data) => { + console.error(data.toString()); + }); + + botProcess.on('exit', (code) => { + console.log(`Bot process exited with code ${code}`); + }); +} + +async function updateAndStartBot() { + await updateBotFromGitHub(); + startBot(); +} + // Function to check for updates at regular intervals function checkForUpdates() { // Set an interval to check for updates (e.g., every 24 hours) const interval = 24 * 60 * 60 * 1000; // 24 hours in milliseconds - setInterval(updateBotFromGitHub, interval); + setInterval(updateAndStartBot, interval); // Perform initial check for updates on bot startup - updateBotFromGitHub(); + updateAndStartBot(); } // Call the function to check for updates