First part of the run logs
This commit is contained in:
50
index.js
50
index.js
@@ -210,15 +210,39 @@ async function startBot(accountName) {
|
||||
startBot(accountName).then(resolve).catch(reject);
|
||||
}
|
||||
else {
|
||||
const logEntry = {
|
||||
accountName,
|
||||
date: new Date().toISOString(),
|
||||
};
|
||||
fs.appendFile('batch_logs.json', JSON.stringify(logEntry) + '\n', (err) => {
|
||||
const currentDate = new Date();
|
||||
const formattedDate = `${currentDate.getDate()}-${currentDate.getMonth() + 1}-${currentDate.getFullYear()}`;
|
||||
const logEntry = { accountName: accountName, date: formattedDate };
|
||||
|
||||
fs.readFile('batch_logs.json', 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error(`Failed to write to batch_logs.json: ${err}`);
|
||||
logManager(`Failed to read batch_logs.json: ${err}`, 'error');
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
|
||||
let logEntries = [];
|
||||
try {
|
||||
logEntries = JSON.parse(data);
|
||||
}
|
||||
catch (parseError) {
|
||||
logManager(`Failed to parse batch_logs.json: ${parseError}`, 'error');
|
||||
}
|
||||
|
||||
const existingEntryIndex = logEntries.findIndex(entry => entry.accountName === accountName);
|
||||
if (existingEntryIndex !== -1) {
|
||||
logEntries[existingEntryIndex] = logEntry;
|
||||
}
|
||||
else {
|
||||
logEntries.push(logEntry);
|
||||
}
|
||||
|
||||
fs.writeFile('batch_logs.json', JSON.stringify(logEntries, null, 2), err => {
|
||||
if (err) {
|
||||
logManager(`Failed to write to batch_logs.json: ${err}`, 'error');
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -260,7 +284,7 @@ async function main() {
|
||||
|
||||
if (fs.existsSync('.env')) {
|
||||
require('dotenv').config({ path: '.env' });
|
||||
logManager(`[${host}] Config file: .env.`, 'info');
|
||||
logManager(`[${host}] Config file: .env`, 'info');
|
||||
}
|
||||
else {
|
||||
logManager(`[${host}] Config file: not found.`, 'error');
|
||||
@@ -270,6 +294,16 @@ async function main() {
|
||||
logManager(`[${host}] Bot Console Webhook: ${botConsoleWebhook ? 'True' : 'False'}\n[${host}] Bot Report Webhook: ${reportWebhook ? 'True' : 'False'}\n[${host}] Bot Manager Webhook: ${managerWebhook ? 'True' : 'False'}`);
|
||||
logManager(`[${host}] Starting mcr-bot on host: ${host}`, 'info');
|
||||
|
||||
if (!fs.existsSync('batch_logs.json')) {
|
||||
fs.writeFile('batch_logs.json', JSON.stringify([], null, 2), err => {
|
||||
if (err) {
|
||||
logManager(`Failed to create batch_logs.json: ${err}`, 'error');
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
logManager(`[${host}] Log file: batch_logs.json`, 'info');
|
||||
|
||||
for (const vpn of vpns) {
|
||||
logManager(`[${host}] Switching to VPN: [${vpn}]`, 'info');
|
||||
const con = await vpnConnect(vpn);
|
||||
|
||||
Reference in New Issue
Block a user