Global Error Handler: Log File.

master
masterhc 4 weeks ago
parent f41432d943
commit a15fcc6f06

@ -7,6 +7,7 @@ const xmlparser = require('xml-js')
const GuildM = require('./models/guilds');
const Spawner = require('child_process');
const mongoose = require('mongoose');
const fs = require('fs');
module.exports.GatewayIntentBits = GatewayIntentBits;
module.exports.Partials = Partials;
@ -126,6 +127,38 @@ class _Client extends Client
this.YTFeed()
this.music();
}, 60*60*1000);
const logDir = "logs"; // Directory for logs
const logFile = path.join(logDir, "error.log");
const maxAgeDays = 7; // Delete if older than 7 days
setInterval(()=>
{
// Ensure the log directory exists
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir, { recursive: true });
}
// Check if the log file is older than maxAgeDays
if (fs.existsSync(logFile)) {
const stats = fs.statSync(logFile);
const fileAgeMs = Date.now() - stats.mtimeMs; // File age in milliseconds
const maxAgeMs = maxAgeDays * 24 * 60 * 60 * 1000; // Convert days to milliseconds
if (fileAgeMs > maxAgeMs) {
console.log(`Deleting old log file: ${logFile}`);
fs.unlinkSync(logFile); // Delete the file
}
}
});
process.on("uncaughtException", (err) =>
{
const timestamp = new Date().toISOString();
console.log(timeStamp)
const errorMessage = `[${timestamp}] Caught before crash: ${err.message}\n`;
console.error(err);
fs.appendFileSync(logFile, errorMessage);
process.exit(1); // Ensure the process exits after logging
});
}
setGuilds()
{
@ -1050,6 +1083,7 @@ class rustCommits
*/
function send(commit, channel, client)
{
client.channels.cache.get(channel).send({embeds:[
new EmbedBuilder()
.setColor(0xc23811)
@ -1263,6 +1297,7 @@ class FreeGameModel
}
const strikesM = require('./models/strikes');
const guildsM = require('./models/guilds');
const { timeStamp } = require('console');
class Strikes
{
constructor(client)

@ -1,32 +1,45 @@
const crypto = require('crypto');
// Key and IV generation for AES
const algorithm = 'aes-256-cbc';
const key = crypto.randomBytes(32); // 256-bit key
console.log(key)
const iv = crypto.randomBytes(16); // Initialization vector
console.log(iv)
// Encrypt function
function encrypt(text) {
const cipher = crypto.createCipheriv(algorithm, key, iv);
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
return encrypted;
}
// Decrypt function
function decrypt(encryptedText) {
const decipher = crypto.createDecipheriv(algorithm, key, iv);
let decrypted = decipher.update(encryptedText, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
// Example usage
const textToEncrypt = 'Hello, World!';
const encryptedText = encrypt(textToEncrypt);
const decryptedText = decrypt(encryptedText);
console.log('Text to Encrypt:', textToEncrypt);
console.log('Encrypted Text:', encryptedText);
console.log('Decrypted Text:', decryptedText);
// const crypto = require('crypto');
// // Key and IV generation for AES
// const algorithm = 'aes-256-cbc';
// const key = crypto.randomBytes(32); // 256-bit key
// console.log(key)
// const iv = crypto.randomBytes(16); // Initialization vector
// console.log(iv)
// // Encrypt function
// function encrypt(text) {
// const cipher = crypto.createCipheriv(algorithm, key, iv);
// let encrypted = cipher.update(text, 'utf8', 'hex');
// encrypted += cipher.final('hex');
// return encrypted;
// }
// // Decrypt function
// function decrypt(encryptedText) {
// const decipher = crypto.createDecipheriv(algorithm, key, iv);
// let decrypted = decipher.update(encryptedText, 'hex', 'utf8');
// decrypted += decipher.final('utf8');
// return decrypted;
// }
// // Example usage
// const textToEncrypt = 'Hello, World!';
// const encryptedText = encrypt(textToEncrypt);
// const decryptedText = decrypt(encryptedText);
// console.log('Text to Encrypt:', textToEncrypt);
// console.log('Encrypted Text:', encryptedText);
// console.log('Decrypted Text:', decryptedText);
console.log("Starting script...");
setTimeout(() => {
console.log("About to throw an error...");
1*p
}, 3000);
process.on("uncaughtException", (err) => {
console.error("Caught before exit:", err);
process.exit(1); // Ensure the process exits after logging
});

Loading…
Cancel
Save