Compare commits
3 commits
a473083b4d
...
b9bb068252
Author | SHA1 | Date | |
---|---|---|---|
b9bb068252 | |||
eb1d352915 | |||
471d74b9ea |
5 changed files with 63 additions and 12 deletions
20
package-lock.json
generated
20
package-lock.json
generated
|
@ -13,21 +13,21 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@azure/msal-common": {
|
||||
"version": "14.15.0",
|
||||
"resolved": "https://registry.npmjs.org/@azure/msal-common/-/msal-common-14.15.0.tgz",
|
||||
"integrity": "sha512-ImAQHxmpMneJ/4S8BRFhjt1MZ3bppmpRPYYNyzeQPeFN288YKbb8TmmISQEbtfkQ1BPASvYZU5doIZOPBAqENQ==",
|
||||
"version": "14.16.0",
|
||||
"resolved": "https://registry.npmjs.org/@azure/msal-common/-/msal-common-14.16.0.tgz",
|
||||
"integrity": "sha512-1KOZj9IpcDSwpNiQNjt0jDYZpQvNZay7QAEi/5DLubay40iGYtLzya/jbjRPLyOTZhEKyL1MzPuw2HqBCjceYA==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@azure/msal-node": {
|
||||
"version": "2.15.0",
|
||||
"resolved": "https://registry.npmjs.org/@azure/msal-node/-/msal-node-2.15.0.tgz",
|
||||
"integrity": "sha512-gVPW8YLz92ZeCibQH2QUw96odJoiM3k/ZPH3f2HxptozmH6+OnyyvKXo/Egg39HAM230akarQKHf0W74UHlh0Q==",
|
||||
"version": "2.16.0",
|
||||
"resolved": "https://registry.npmjs.org/@azure/msal-node/-/msal-node-2.16.0.tgz",
|
||||
"integrity": "sha512-oww0oJTOOvPKTVXqVyxfcFVjExQKYEkKR5KM0cTG3jnzt6u/MRMx8XaK49L/bxV35r9sCHQFjNlEShad9qGSYA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@azure/msal-common": "14.15.0",
|
||||
"@azure/msal-common": "14.16.0",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"uuid": "^8.3.0"
|
||||
},
|
||||
|
@ -36,9 +36,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "22.8.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.7.tgz",
|
||||
"integrity": "sha512-LidcG+2UeYIWcMuMUpBKOnryBWG/rnmOHQR5apjn8myTQcx3rinFRn7DcIFhMnS0PPFSC6OafdIKEad0lj6U0Q==",
|
||||
"version": "22.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.0.tgz",
|
||||
"integrity": "sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.19.8"
|
||||
|
|
31
plugins/chatlog.js
Executable file
31
plugins/chatlog.js
Executable file
|
@ -0,0 +1,31 @@
|
|||
import chatlog from '../util/chatlog.js'
|
||||
import { readdirSync, mkdirSync } from "node:fs"
|
||||
import { default as settings } from '../settings.json' with {type: "json"}
|
||||
|
||||
const checkLog = () => {
|
||||
if (settings.disableLogging) return
|
||||
try {
|
||||
if (!readdirSync('.').includes('logs')) mkdirSync('logs')
|
||||
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()}`
|
||||
if (!readdirSync('./logs').includes(filenameToday)) mkdirSync(`logs/${filenameToday}`)
|
||||
if (!readdirSync('./logs').includes(filenameTomorrow)) mkdirSync(`logs/${filenameTomorrow}`) // Create tomorrow's log directory early
|
||||
} catch (e) {
|
||||
console.log(e) // Prevents some crashes when there is no space remaining on the storage medium the bot is on or when the permissions are incorrect
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(checkLog, 3600000) // Runs once every hour,
|
||||
checkLog() // and at bot startup.
|
||||
|
||||
|
||||
export default function load (b) {
|
||||
b.on('plainchat', (msg, type) => {
|
||||
if (!settings.disableLogging && !settings.disableChatLogging) chatlog(`chat_${b.host.host}_${b.host.port}`, `[${type}] ${msg}`)
|
||||
})
|
||||
b.on('command', c => {
|
||||
if (!settings.disableLogging && !settings.disableCommandLogging) chatlog(`cmd_${b.host.host}_${b.host.port}`, `[${c.msgType}] ${c.username} (${c.uuid}): ${c.command}`)
|
||||
})
|
||||
}
|
|
@ -12,7 +12,10 @@ export default function load (b) {
|
|||
}
|
||||
})
|
||||
b.runCommand = function (user, nick, uuid, command, type, subtype, prefix){
|
||||
const context = new Command(uuid, user, nick, command, "minecraft", type, subtype, prefix, b, 0, {})
|
||||
const context = new Command(uuid, user, nick, command, "minecraft", type, subtype, prefix, b, 0)
|
||||
|
||||
b.emit('command', context)
|
||||
|
||||
if(cmds[context.cmdName.toLowerCase()]){
|
||||
try {
|
||||
cmds[context.cmdName.toLowerCase()].execute(context)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { default as settings } from '../settings.json' with {type: "json"}
|
||||
export default class Command {
|
||||
constructor (uuid, user, nick, cmd, senderType, msgType, msgSubtype, prefix, bot, verify, prefs) {
|
||||
constructor (uuid, user, nick, cmd, senderType, msgType, msgSubtype, prefix, bot, verify) {
|
||||
this.uuid=uuid;
|
||||
this.reply = text => bot.tellraw(uuid, text)
|
||||
this.username = user;
|
||||
|
|
17
util/chatlog.js
Executable file
17
util/chatlog.js
Executable file
|
@ -0,0 +1,17 @@
|
|||
import { appendFileSync } from 'node:fs'
|
||||
import { default as settings } from '../settings.json' with {type: "json"}
|
||||
|
||||
export default function chatlog (fileName, item) {
|
||||
if (settings.disableLogging) return
|
||||
const dateToday = new Date(Date.now())
|
||||
const UTCYears = dateToday.getUTCFullYear()
|
||||
const UTCMonths = dateToday.getUTCMonth() + 1
|
||||
const UTCDays = dateToday.getUTCDate()
|
||||
const UTCHours = dateToday.getUTCHours()
|
||||
const UTCMinutes = dateToday.getUTCMinutes().toString().padStart(2, '0')
|
||||
const UTCSeconds = dateToday.getUTCSeconds().toString().padStart(2, '0')
|
||||
const UTCMilliSeconds = dateToday.getUTCMilliseconds().toString().padStart(3, '0')
|
||||
const filenameToday = `${UTCMonths}-${UTCDays}-${UTCYears}`
|
||||
const logDate = `${UTCMonths}/${UTCDays}/${UTCYears} ${UTCHours}:${UTCMinutes}:${UTCSeconds}.${UTCMilliSeconds}`
|
||||
appendFileSync(`logs/${filenameToday}/${fileName}.txt`, `[${logDate}] ${item}\n`)
|
||||
}
|
Loading…
Reference in a new issue