Updated index.js
This commit is contained in:
parent
fcaefaeff9
commit
41a09040ed
1 changed files with 27 additions and 7 deletions
34
index.js
34
index.js
|
@ -1,5 +1,4 @@
|
||||||
|
|
||||||
|
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
const fs = require('node:fs');
|
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
|
// Force update by resetting to the latest commit on the remote main branch
|
||||||
await git.reset(['--hard', 'origin/main']);
|
await git.reset(['--hard', 'origin/main']);
|
||||||
|
|
||||||
console.log('Bot updated from GitHub. Restarting...');
|
console.log('Bot updated from GitHub.');
|
||||||
|
|
||||||
// Restart the bot to apply changes
|
|
||||||
process.exit();
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error updating bot from GitHub:', 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 to check for updates at regular intervals
|
||||||
function checkForUpdates() {
|
function checkForUpdates() {
|
||||||
// Set an interval to check for updates (e.g., every 24 hours)
|
// Set an interval to check for updates (e.g., every 24 hours)
|
||||||
const interval = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
|
const interval = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
|
||||||
setInterval(updateBotFromGitHub, interval);
|
setInterval(updateAndStartBot, interval);
|
||||||
|
|
||||||
// Perform initial check for updates on bot startup
|
// Perform initial check for updates on bot startup
|
||||||
updateBotFromGitHub();
|
updateAndStartBot();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call the function to check for updates
|
// Call the function to check for updates
|
||||||
|
|
Loading…
Reference in a new issue