2024-08-15 05:43:42 -04:00
|
|
|
const chatlog = require('../util/chatlog.js')
|
2024-08-15 05:38:09 -04:00
|
|
|
const fs = require('fs')
|
|
|
|
const settings = require('../settings.json')
|
|
|
|
|
|
|
|
const checkLog = () => {
|
2024-08-15 05:43:42 -04:00
|
|
|
if (settings.disableLogging) return
|
2024-08-15 05:38:09 -04:00
|
|
|
try {
|
2024-08-15 12:50:12 -04:00
|
|
|
if (!fs.readdirSync('.').includes('logs')) fs.mkdirSync('logs')
|
2024-08-15 05:43:42 -04:00
|
|
|
const dateToday = new Date(Date.now())
|
|
|
|
const dateTomorrow = new Date(Date.now() + 86400000)
|
|
|
|
const filenameToday = `${dateToday.getUTCMonth() + 1}-${dateToday.getUTCDate()}-${dateToday.getUTCFullYear()}`
|
|
|
|
const filenameTomorrow = `${dateTomorrow.getUTCMonth() + 1}-${dateTomorrow.getUTCDate()}-${dateTomorrow.getUTCFullYear()}`
|
2024-08-15 12:50:12 -04:00
|
|
|
if (!fs.readdirSync('./logs').includes(filenameToday)) fs.mkdirSync(`logs/${filenameToday}`)
|
|
|
|
if (!fs.readdirSync('./logs').includes(filenameTomorrow)) fs.mkdirSync(`logs/${filenameTomorrow}`) // Create tomorrow's log directory early
|
2024-08-15 05:43:42 -04:00
|
|
|
} catch (e) {
|
2024-08-15 05:38:09 -04:00
|
|
|
console.log(e) // Prevents some crashes when disk space is full or when the permissions are incorrect
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setInterval(checkLog, 3600000) // Runs once every hour,
|
|
|
|
checkLog() // and at bot startup.
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
load: (b) => {
|
|
|
|
b.on('plainchat', (msg, type) => {
|
2024-08-15 05:43:42 -04:00
|
|
|
if (!settings.disableLogging && !settings.disableChatLogging) chatlog(`chat_${b.host.host}_${b.host.port}`, `[${type}] ${msg}`)
|
2024-08-15 05:38:09 -04:00
|
|
|
})
|
|
|
|
b.on('command', (name, uuid, text) => {
|
2024-08-15 05:43:42 -04:00
|
|
|
if (!settings.disableLogging && !settings.disableCommandLogging) chatlog(`cmd_${b.host.host}_${b.host.port}`, `${name} (${uuid}): ${text}`)
|
2024-08-15 05:38:09 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|