This commit is contained in:
7cc5c4f330d47060 2024-08-15 05:43:42 -04:00
parent 59d04b3879
commit 9af9d8d974
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
8 changed files with 72 additions and 72 deletions

View file

@ -181,12 +181,12 @@ const aboutServer = function (c) {
} }
const displayServerList = function (c) { const displayServerList = function (c) {
for(const i in index.bot){ for (const i in index.bot) {
if(index.bot[i].host.options && index.bot[i].host.options.hidden) continue if (index.bot[i].host.options && index.bot[i].host.options.hidden) continue
c.reply({ c.reply({
translate: getMessage(c.lang, 'command.about.serverListItem'), translate: getMessage(c.lang, 'command.about.serverListItem'),
color: c.colors.secondary, color: c.colors.secondary,
with:[ with: [
{ {
text: i.toString(), text: i.toString(),
color: c.colors.primary color: c.colors.primary

View file

@ -2,9 +2,9 @@ const { bot } = require('../index.js')
const { getMessage } = require('../util/lang.js') const { getMessage } = require('../util/lang.js')
module.exports = { module.exports = {
execute: (c) => { execute: (c) => {
if(c.bot.host && c.bot.host.options.hidden){ if (c.bot.host && c.bot.host.options.hidden) {
c.reply({ c.reply({
text: getMessage(c.lang, "command.netmsg.disabled"), text: getMessage(c.lang, 'command.netmsg.disabled'),
color: c.colors.secondary color: c.colors.secondary
}) })
return return
@ -37,7 +37,7 @@ module.exports = {
color: 'white' color: 'white'
} }
for (const i in bot) { for (const i in bot) {
if(bot[i].host.options.hidden) continue if (bot[i].host.options.hidden) continue
bot[i].tellraw('@a', json) bot[i].tellraw('@a', json)
} }
} }

View file

@ -4,38 +4,38 @@ module.exports = {
execute: (c) => { execute: (c) => {
const subcmd = c.args.splice(0, 1)[0] const subcmd = c.args.splice(0, 1)[0]
switch (subcmd) { switch (subcmd) {
case 'set': case 'set':{
const allowedKeys = ["colorPrimary", "colorSecondary", "lang"] const allowedKeys = ['colorPrimary', 'colorSecondary', 'lang']
const key = c.args.splice(0, 1)[0] const key = c.args.splice(0, 1)[0]
if(!allowedKeys.includes(key)){ if (!allowedKeys.includes(key)) {
c.reply({ c.reply({
text: getMessage(c.lang, 'command.settings.error.invalidKey'), text: getMessage(c.lang, 'command.settings.error.invalidKey'),
color: c.colors.secondary color: c.colors.secondary
}); })
return; return
} }
const value = c.args.join(" ") const value = c.args.join(' ')
if(value === "" && key==="lang"){ if (value === '' && key === 'lang') {
// Show all valid languages to user // Show all valid languages to user
for(const i in languages){ for (const i in languages) {
c.reply({ c.reply({
translate: "%s (%s)", translate: '%s (%s)',
color: c.colors.secondary, color: c.colors.secondary,
with:[ with: [
{ {
text: getMessage(languages[i], 'language.name'), text: getMessage(languages[i], 'language.name'),
color: c.colors.primary color: c.colors.primary
}, },
{ {
text: getMessage(languages[i], 'language.region'), text: getMessage(languages[i], 'language.region'),
color: c.colors.primary color: c.colors.primary
} }
], ],
hoverEvent:{ hoverEvent: {
action: "show_text", action: 'show_text',
value: { value: {
translate: getMessage(languages[i], 'command.settings.setLanguage'), translate: getMessage(languages[i], 'command.settings.setLanguage'),
with:[ with: [
{ {
text: `${c.prefix}settings set lang ${languages[i]}`, text: `${c.prefix}settings set lang ${languages[i]}`,
color: c.colors.secondary color: c.colors.secondary
@ -47,19 +47,19 @@ module.exports = {
} }
return return
} }
if(value === ""){ if (value === '') {
c.reply({ c.reply({
text: getMessage(c.lang, 'command.settings.error.mustProvideValue'), text: getMessage(c.lang, 'command.settings.error.mustProvideValue'),
color: c.colors.secondary color: c.colors.secondary
}); })
return; return
} }
if(key==="lang" && !languages.includes(value)){ if (key === 'lang' && !languages.includes(value)) {
c.reply({ c.reply({
text: getMessage(c.lang, 'command.settings.error.invalidLanguage'), text: getMessage(c.lang, 'command.settings.error.invalidLanguage'),
color: c.colors.secondary color: c.colors.secondary
}); })
return; return
} }
c.prefs[key] = value c.prefs[key] = value
@ -67,19 +67,20 @@ module.exports = {
fs.writeFileSync(`userPref/${c.uuid}.json`, JSON.stringify(c.prefs)) fs.writeFileSync(`userPref/${c.uuid}.json`, JSON.stringify(c.prefs))
// Delete require cache // Delete require cache
for(const i in require.cache){ for (const i in require.cache) {
if(i.endsWith(`${c.uuid}.json`)) delete require.cache[i] if (i.endsWith(`${c.uuid}.json`)) delete require.cache[i]
} }
c.reply({ c.reply({
text: getMessage(c.lang, 'command.settings.saved'), text: getMessage(c.lang, 'command.settings.saved'),
color: c.colors.secondary color: c.colors.secondary
}); })
break; break
case 'get':{ }
case 'get':
c.reply({ c.reply({
translate: "%s: %s", translate: '%s: %s',
color: c.colors.primary, color: c.colors.primary,
with:[ with: [
{ {
text: getMessage(c.lang, 'command.settings.get.colorPrimary'), text: getMessage(c.lang, 'command.settings.get.colorPrimary'),
color: c.colors.secondary color: c.colors.secondary
@ -91,9 +92,9 @@ module.exports = {
] ]
}) })
c.reply({ c.reply({
translate: "%s: %s", translate: '%s: %s',
color: c.colors.primary, color: c.colors.primary,
with:[ with: [
{ {
text: getMessage(c.lang, 'command.settings.get.colorSecondary'), text: getMessage(c.lang, 'command.settings.get.colorSecondary'),
color: c.colors.secondary color: c.colors.secondary
@ -105,9 +106,9 @@ module.exports = {
] ]
}) })
c.reply({ c.reply({
translate: "%s: %s (%s)", translate: '%s: %s (%s)',
color: c.colors.primary, color: c.colors.primary,
with:[ with: [
{ {
text: getMessage(c.lang, 'command.settings.get.language'), text: getMessage(c.lang, 'command.settings.get.language'),
color: c.colors.secondary color: c.colors.secondary
@ -123,7 +124,6 @@ module.exports = {
] ]
}) })
break break
}
default: default:
c.reply({ c.reply({
translate: getMessage(c.lang, 'command.cloop.error.subcommand'), translate: getMessage(c.lang, 'command.cloop.error.subcommand'),

View file

@ -1,18 +1,18 @@
const chatlog = require("../util/chatlog.js") const chatlog = require('../util/chatlog.js')
const fs = require('fs') const fs = require('fs')
const settings = require('../settings.json') const settings = require('../settings.json')
const checkLog = () => { const checkLog = () => {
if(settings.disableLogging) return; if (settings.disableLogging) return
try { try {
if (!fs.readdirSync('.').includes('botvXLogs')) fs.mkdirSync('botvXLogs'); if (!fs.readdirSync('.').includes('botvXLogs')) fs.mkdirSync('botvXLogs')
const dateToday = new Date(Date.now()); const dateToday = new Date(Date.now())
const dateTomorrow = new Date(Date.now()+86400000); const dateTomorrow = new Date(Date.now() + 86400000)
const filenameToday = `${dateToday.getUTCMonth()+1}-${dateToday.getUTCDate()}-${dateToday.getUTCFullYear()}`; const filenameToday = `${dateToday.getUTCMonth() + 1}-${dateToday.getUTCDate()}-${dateToday.getUTCFullYear()}`
const filenameTomorrow = `${dateTomorrow.getUTCMonth()+1}-${dateTomorrow.getUTCDate()}-${dateTomorrow.getUTCFullYear()}`; const filenameTomorrow = `${dateTomorrow.getUTCMonth() + 1}-${dateTomorrow.getUTCDate()}-${dateTomorrow.getUTCFullYear()}`
if (!fs.readdirSync('./botvXLogs').includes(filenameToday)) fs.mkdirSync(`botvXLogs/${filenameToday}`); if (!fs.readdirSync('./botvXLogs').includes(filenameToday)) fs.mkdirSync(`botvXLogs/${filenameToday}`)
if (!fs.readdirSync('./botvXLogs').includes(filenameTomorrow)) fs.mkdirSync(`botvXLogs/${filenameTomorrow}`); // Create tomorrow's log directory early if (!fs.readdirSync('./botvXLogs').includes(filenameTomorrow)) fs.mkdirSync(`botvXLogs/${filenameTomorrow}`) // Create tomorrow's log directory early
} catch(e){ } catch (e) {
console.log(e) // Prevents some crashes when disk space is full or when the permissions are incorrect console.log(e) // Prevents some crashes when disk space is full or when the permissions are incorrect
} }
} }
@ -23,10 +23,10 @@ checkLog() // and at bot startup.
module.exports = { module.exports = {
load: (b) => { load: (b) => {
b.on('plainchat', (msg, type) => { b.on('plainchat', (msg, type) => {
if(!settings.disableLogging && !settings.disableChatLogging) chatlog(`chat_${b.host.host}_${b.host.port}`, `[${type}] ${msg}`) if (!settings.disableLogging && !settings.disableChatLogging) chatlog(`chat_${b.host.host}_${b.host.port}`, `[${type}] ${msg}`)
}) })
b.on('command', (name, uuid, text) => { b.on('command', (name, uuid, text) => {
if(!settings.disableLogging && !settings.disableCommandLogging) chatlog(`cmd_${b.host.host}_${b.host.port}`, `${name} (${uuid}): ${text}`) if (!settings.disableLogging && !settings.disableCommandLogging) chatlog(`cmd_${b.host.host}_${b.host.port}`, `${name} (${uuid}): ${text}`)
}) })
} }
} }

View file

@ -3,11 +3,11 @@ const hashcheck = require('../util/hashcheck.js')
const settings = require('../settings.json') const settings = require('../settings.json')
const { getMessage } = require('../util/lang.js') const { getMessage } = require('../util/lang.js')
const cmds = require('../util/commands.js') const cmds = require('../util/commands.js')
const fs = require("fs") const fs = require('fs')
if(!fs.readdirSync('.').includes('userPref')) fs.mkdirSync("userPref"); if (!fs.readdirSync('.').includes('userPref')) fs.mkdirSync('userPref')
const loadSettings = function(uuid){ const loadSettings = function (uuid) {
try { try {
return require(`../userPref/${uuid}.json`) return require(`../userPref/${uuid}.json`)
} catch (e) { } catch (e) {
@ -21,7 +21,7 @@ module.exports = {
b.runCommand = (name, uuid, text, prefix) => { b.runCommand = (name, uuid, text, prefix) => {
if (uuid === '00000000-0000-0000-0000-000000000000') return if (uuid === '00000000-0000-0000-0000-000000000000') return
if (Date.now() - b.lastCmd <= 1000) return if (Date.now() - b.lastCmd <= 1000) return
const userSettings = loadSettings(uuid); const userSettings = loadSettings(uuid)
b.lastCmd = Date.now() b.lastCmd = Date.now()
const cmd = text.split(' ') const cmd = text.split(' ')
const lang = settings.defaultLang const lang = settings.defaultLang
@ -29,7 +29,7 @@ module.exports = {
if (verify > 0) { if (verify > 0) {
text = cmd.slice(0, cmd.length - 1).join(' ') text = cmd.slice(0, cmd.length - 1).join(' ')
} }
b.emit("command", name, uuid, text, prefix) b.emit('command', name, uuid, text, prefix)
if (cmds[cmd[0].toLowerCase()]) { if (cmds[cmd[0].toLowerCase()]) {
const command = cmds[cmd[0].toLowerCase()] const command = cmds[cmd[0].toLowerCase()]
if (command.level !== undefined && command.level > verify) { if (command.level !== undefined && command.level > verify) {

View file

@ -13,7 +13,7 @@ module.exports = {
b.sc_tasks = {} b.sc_tasks = {}
b.selfcareRun = 0 b.selfcareRun = 0
b.interval.sc = setInterval(() => { b.interval.sc = setInterval(() => {
if(Date.now() - b.selfcareRun <= 600){ if (Date.now() - b.selfcareRun <= 600) {
return return
} }
for (const i in b.sc_tasks) { for (const i in b.sc_tasks) {

View file

@ -18,19 +18,19 @@ class Command {
this.port = bot.host.port this.port = bot.host.port
// this.lang = lang // this.lang = lang
this.prefs = prefs this.prefs = prefs
if(prefs.lang){ if (prefs.lang) {
this.lang = prefs.lang this.lang = prefs.lang
} else { } else {
this.lang = settings.defaultLang this.lang = settings.defaultLang
} }
let _colors = {} const _colors = {}
if(prefs.colorPrimary){ if (prefs.colorPrimary) {
_colors.primary = prefs.colorPrimary _colors.primary = prefs.colorPrimary
} else { } else {
_colors.primary = settings.colors.primary _colors.primary = settings.colors.primary
} }
if(prefs.colorSecondary){ if (prefs.colorSecondary) {
_colors.secondary = prefs.colorSecondary _colors.secondary = prefs.colorSecondary
} else { } else {
_colors.secondary = settings.colors.secondary _colors.secondary = settings.colors.secondary

View file

@ -1,14 +1,14 @@
const fs = require('fs') const fs = require('fs')
const settings = require('../settings.json') const settings = require('../settings.json')
module.exports = function(fileName, item){ module.exports = function (fileName, item) {
if(settings.disableLogging) return; if (settings.disableLogging) return
const dateToday = new Date(Date.now()); const dateToday = new Date(Date.now())
const UTCHours = dateToday.getUTCHours(); const UTCHours = dateToday.getUTCHours()
const UTCMinutes = dateToday.getUTCMinutes().toString().padStart(2,"0"); const UTCMinutes = dateToday.getUTCMinutes().toString().padStart(2, '0')
const UTCSeconds = dateToday.getUTCSeconds().toString().padStart(2,"0"); const UTCSeconds = dateToday.getUTCSeconds().toString().padStart(2, '0')
const UTCMilliSeconds = dateToday.getUTCMilliseconds().toString().padStart(3,"0"); const UTCMilliSeconds = dateToday.getUTCMilliseconds().toString().padStart(3, '0')
const filenameToday = `${dateToday.getUTCMonth()+1}-${dateToday.getUTCDate()}-${dateToday.getUTCFullYear()}`; const filenameToday = `${dateToday.getUTCMonth() + 1}-${dateToday.getUTCDate()}-${dateToday.getUTCFullYear()}`
const logDate = `${dateToday.getUTCMonth()+1}/${dateToday.getUTCDate()}/${dateToday.getUTCFullYear()} ${UTCHours}:${UTCMinutes}:${UTCSeconds}.${UTCMilliSeconds}`; const logDate = `${dateToday.getUTCMonth() + 1}/${dateToday.getUTCDate()}/${dateToday.getUTCFullYear()} ${UTCHours}:${UTCMinutes}:${UTCSeconds}.${UTCMilliSeconds}`
fs.appendFileSync(`botvXLogs/${filenameToday}/${fileName}.txt`, `[${logDate}] ${item}\n`) fs.appendFileSync(`botvXLogs/${filenameToday}/${fileName}.txt`, `[${logDate}] ${item}\n`)
} }