Updated index.js
This commit is contained in:
parent
ead508ebc9
commit
665ba73672
1 changed files with 1 additions and 61 deletions
62
index.js
62
index.js
|
@ -2,9 +2,7 @@ const Discord = require('discord.js');
|
|||
const chalk = require('chalk');
|
||||
const fs = require('node:fs');
|
||||
const config = require('./configs/config.json');
|
||||
const simpleGit = require('simple-git');
|
||||
const path = require('node:path');
|
||||
const { exec } = require('child_process');
|
||||
|
||||
// Discord Client Constructor
|
||||
const client = new Discord.Client({
|
||||
|
@ -72,64 +70,6 @@ async function registerSlashCommands() {
|
|||
// Call the async function to register slash commands
|
||||
registerSlashCommands();
|
||||
|
||||
// Function to update the bot from GitHub repository
|
||||
async function updateBotFromGitHub() {
|
||||
|
||||
const git = simpleGit(path.resolve(__dirname));
|
||||
|
||||
try {
|
||||
console.log('Checking for updates from GitHub...');
|
||||
|
||||
if (!await git.checkIsRepo()) {
|
||||
await git.init().addRemote('origin', 'https://git.shadowhosting.xyz/shadowvr/AI_botter.git').fetch();
|
||||
}
|
||||
|
||||
await git.pull('origin', 'main');
|
||||
|
||||
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(updateAndStartBot, interval);
|
||||
|
||||
// Perform initial check for updates on bot startup
|
||||
updateAndStartBot();
|
||||
}
|
||||
|
||||
// Call the function to check for updates
|
||||
checkForUpdates();
|
||||
|
||||
// Anti Crash
|
||||
process.on('unhandledRejection', (reason, p) => {
|
||||
console.log(chalk.bold.redBright('[antiCrash] :: Unhandled Rejection/Catch'));
|
||||
|
@ -147,4 +87,4 @@ process.on('uncaughtExceptionMonitor', (err, origin) => {
|
|||
});
|
||||
|
||||
// Discord Client login
|
||||
client.login(config.Token);
|
||||
client.login(config.Token);
|
||||
|
|
Loading…
Reference in a new issue