2024-06-01 19:35:55 +01:00
|
|
|
const simpleGit = require('simple-git');
|
|
|
|
const path = require('path');
|
|
|
|
const { exec } = require('child_process');
|
|
|
|
|
|
|
|
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();
|
|
|
|
} else {
|
2024-06-01 22:15:16 +01:00
|
|
|
await git.pull('origin', 'main');
|
2024-06-01 19:35:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Bot updated from GitHub.');
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error updating bot from GitHub:', error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function startIndexJs() {
|
|
|
|
console.log('Starting index.js...');
|
|
|
|
const indexProcess = exec('node index.js', {
|
|
|
|
cwd: path.resolve(__dirname),
|
|
|
|
});
|
|
|
|
|
|
|
|
indexProcess.stdout.on('data', (data) => {
|
|
|
|
console.log(data.toString());
|
|
|
|
});
|
|
|
|
|
|
|
|
indexProcess.stderr.on('data', (data) => {
|
|
|
|
console.error(data.toString());
|
|
|
|
});
|
|
|
|
|
|
|
|
indexProcess.on('exit', (code) => {
|
|
|
|
console.log(`index.js process exited with code ${code}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function updateAndStartIndexJs() {
|
|
|
|
await updateBotFromGitHub();
|
|
|
|
startIndexJs();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform initial update and start index.js
|
|
|
|
updateAndStartIndexJs();
|