From 240fef627334252ee8cd9f074e74cb9aba14d5ce Mon Sep 17 00:00:00 2001 From: 7cc5c4f330d47060 Date: Sun, 4 Aug 2024 01:41:32 -0400 Subject: [PATCH] Lint --- commands/about.js | 8 ++++---- commands/cloop.js | 2 +- commands/help.js | 10 +++++----- commands/serverinfo.js | 2 +- commands/tpr.js | 2 +- index.js | 4 ++-- plugins/!chat.js | 19 +++++++++---------- plugins/command.js | 4 ++-- plugins/commandblock.js | 8 ++++---- plugins/console.js | 2 +- plugins/player.js | 8 ++++---- plugins/selfcare.js | 4 ++-- util/ConsoleCommand.js | 3 --- util/chatparse_console.js | 28 ++++++++++++++-------------- util/chatparse_plain.js | 6 ++---- util/commands.js | 2 +- util/lang.js | 20 ++++++++++---------- util/mc_lang.js | 4 ++-- util/version.js | 2 +- 19 files changed, 66 insertions(+), 72 deletions(-) diff --git a/commands/about.js b/commands/about.js index e34891c..acaaf22 100644 --- a/commands/about.js +++ b/commands/about.js @@ -1,5 +1,5 @@ const version = require('../version.json') -const {getMessage} = require('../util/lang.js') +const { getMessage } = require('../util/lang.js') const botVersion = require('../util/version.js') module.exports = { execute: function (c) { @@ -28,10 +28,10 @@ module.exports = { } ] }) - if(version.isPreRelease){ + if (version.isPreRelease) { c.reply({ text: getMessage(c.lang, 'command.about.preRelease'), - color: c.colors.secondary, + color: c.colors.secondary }) } c.reply({ text: '' }) @@ -55,7 +55,7 @@ module.exports = { text: getMessage(c.lang, 'command.about.sourceCode.openInBrowser') } } - }, + } ] }) c.reply({ text: '' }) diff --git a/commands/cloop.js b/commands/cloop.js index dac4f98..4e349b0 100644 --- a/commands/cloop.js +++ b/commands/cloop.js @@ -1,4 +1,4 @@ -const {getMessage} = require('../util/lang.js') +const { getMessage } = require('../util/lang.js') module.exports = { execute: (c) => { const subcmd = c.args.splice(0, 1)[0] diff --git a/commands/help.js b/commands/help.js index 92792e1..0c52dbf 100644 --- a/commands/help.js +++ b/commands/help.js @@ -1,7 +1,7 @@ const fs = require('fs') const cmds = Object.create(null) const bpl = fs.readdirSync('./commands') -const {getMessage} = require('../util/lang.js') +const { getMessage } = require('../util/lang.js') const sortHelp = function sortHelp (c1, c2) { const level1 = cmds[c1.with[0]].level ? cmds[c1.with[0]].level : 0 @@ -15,7 +15,7 @@ for (const i in bpl) { // Built-in loadCMD to the help command, to prevent circu } try { const commandName = bpl[i].split('.js')[0] - if(commandName != "help"){ + if (commandName !== 'help') { cmds[commandName] = require(`./${bpl[i]}`) if (cmds[commandName].level === undefined) { cmds[commandName].level = 0 @@ -65,7 +65,7 @@ const printHelp = (c) => { } const printCmdHelp = (c) => { - const cmd=c.args[0]; + const cmd = c.args[0] if (!cmds[cmd]) { c.reply({ text: getMessage(c.lang, 'command.help.noCommand') }) return @@ -134,12 +134,12 @@ module.exports = { ] } -cmds.help = module.exports; // Placed after to ensure that the correct values are added to cmds +cmds.help = module.exports // Placed after to ensure that the correct values are added to cmds if (cmds.help.level === undefined) { cmds.help.level = 0 } -for (const i in cmds){ +for (const i in cmds) { if (cmds[i].aliases) { for (const j in cmds[i].aliases) { cmds[cmds[i].aliases[j]] = { diff --git a/commands/serverinfo.js b/commands/serverinfo.js index efbbcb1..44d8b44 100755 --- a/commands/serverinfo.js +++ b/commands/serverinfo.js @@ -1,6 +1,6 @@ const os = require('os') const cp = require('child_process') -const {getMessage,formatTime} = require('../util/lang.js') +const { getMessage, formatTime } = require('../util/lang.js') const fs = require('fs') const botVersion = require('../util/version.js') const gr = function (l, text, value, color) { diff --git a/commands/tpr.js b/commands/tpr.js index 4c3dcb2..5e7c418 100755 --- a/commands/tpr.js +++ b/commands/tpr.js @@ -1,4 +1,4 @@ -const {getMessage} = require('../util/lang.js') +const { getMessage } = require('../util/lang.js') module.exports = { execute: function (c) { let uuid diff --git a/index.js b/index.js index ee1037c..a0a4300 100755 --- a/index.js +++ b/index.js @@ -36,7 +36,7 @@ const createBot = function createBot (host, oldId) { host: host.host, port: host.port ? host.port : 25565, username: generateUser(host.options.legalName), - version: host.version?host.version:settings.version_mc + version: host.version ? host.version : settings.version_mc }) if (typeof oldId !== 'undefined') { for (const i in module.exports.bot[oldId].interval) { @@ -58,7 +58,7 @@ const createBot = function createBot (host, oldId) { bot.info = (msg) => { console.log(`[${bot.id}] [info] ${msg}`) } - + bot.displayChat = (type, msg) => { console.log(`[${bot.id}] [${type}] ${msg}`) } diff --git a/plugins/!chat.js b/plugins/!chat.js index 90786be..d8a2657 100755 --- a/plugins/!chat.js +++ b/plugins/!chat.js @@ -1,5 +1,4 @@ const settings = require('../settings.json') -const console2 = require('./console.js') const parsePlain = require('../util/chatparse_plain.js') const parseConsole = require('../util/chatparse_console.js') const parse1204 = require('../util/chatparse_1204.js') @@ -76,14 +75,14 @@ module.exports = { const parsed = parsePlain(json) let chatName let username - let message; - let uuid; - if(b.host.options.isVanilla && json.translate === "chat.type.text"){ // Servers without Extras chat - if(json.with && json.with.length>=2){ - message = parsePlain(json.with[1]); - username = parsePlain(json.with[0]); + let message + let uuid + if (b.host.options.isVanilla && json.translate === 'chat.type.text') { // Servers without Extras chat + if (json.with && json.with.length >= 2) { + message = parsePlain(json.with[1]) + username = parsePlain(json.with[0]) } - uuid = b.findUUID(username); + uuid = b.findUUID(username) } else { // Servers with Extras chat, such as Kaboom const split = parsed.split(': ') message = split.join(': ') @@ -96,11 +95,11 @@ module.exports = { b.on('chat', (data) => { const msgConsole = parseConsole(data.json) const msgPlain = parsePlain(data.json) - if(settings.logJSONmessages) console.log(data.json) + if (settings.logJSONmessages) console.log(data.json) if (msgPlain.endsWith('\n\n\n\n\nThe chat has been cleared')) return if (msgPlain.startsWith('Command set: ')) return b.emit('plainchat', msgPlain) - b.displayChat(data.type,`${msgConsole}\x1b[0m`) + b.displayChat(data.type, `${msgConsole}\x1b[0m`) const fullCommand = data.message for (const i in b.prefix) { diff --git a/plugins/command.js b/plugins/command.js index 9bebe53..257b80e 100755 --- a/plugins/command.js +++ b/plugins/command.js @@ -1,8 +1,8 @@ const Command = require('../util/Command.js') const hashcheck = require('../util/hashcheck.js') const settings = require('../settings.json') -const {getMessage} = require('../util/lang.js') -const cmds = require("../util/commands.js") +const { getMessage } = require('../util/lang.js') +const cmds = require('../util/commands.js') module.exports = { load: (b) => { diff --git a/plugins/commandblock.js b/plugins/commandblock.js index 16b9f55..435c3e3 100755 --- a/plugins/commandblock.js +++ b/plugins/commandblock.js @@ -97,11 +97,11 @@ module.exports = { } else { finalname = uuid } - let tellrawCommand; - if(b.host.options.isVanilla){ - tellrawCommand = "tellraw"; + let tellrawCommand + if (b.host.options.isVanilla) { + tellrawCommand = 'tellraw' } else { - tellrawCommand = "minecraft:tellraw"; + tellrawCommand = 'minecraft:tellraw' } b.ccq.push(`/${tellrawCommand} ${finalname} ${JSON.stringify(message)}`) } diff --git a/plugins/console.js b/plugins/console.js index 0f8ab7a..c5804e8 100644 --- a/plugins/console.js +++ b/plugins/console.js @@ -1,7 +1,7 @@ const readln = require('readline') const index = require('../index.js') const ConsoleCommand = require('../util/ConsoleCommand.js') -const cmds = require("../util/commands.js") +const cmds = require('../util/commands.js') const rl = readln.createInterface({ input: process.stdin, output: process.stdout, diff --git a/plugins/player.js b/plugins/player.js index ae130ec..4080984 100644 --- a/plugins/player.js +++ b/plugins/player.js @@ -10,11 +10,11 @@ module.exports = { } else if (data.data[i].UUID) { uuid = data.data[i].UUID } - let displayName; - if(data.data[i].displayName !== undefined){ - displayName = data.data[i].displayName; + let displayName + if (data.data[i].displayName !== undefined) { + displayName = data.data[i].displayName } else { - displayName = "Undefined!" + displayName = 'Undefined!' } if (data.data[i].player && data.data[i].player.name !== undefined) { buffer2[uuid] = { realName: data.data[i].player.name, displayName: displayName.plain } diff --git a/plugins/selfcare.js b/plugins/selfcare.js index 699ede0..f1f31bc 100755 --- a/plugins/selfcare.js +++ b/plugins/selfcare.js @@ -44,7 +44,7 @@ module.exports = { }) // Commandspy - if(!b.host.options.isVanilla){ + if (!b.host.options.isVanilla) { b.add_sc_task('cspy', '/cspy on', true, true) b.on('plainchat', (msg) => { if (msg === 'Successfully disabled CommandSpy') { @@ -54,7 +54,7 @@ module.exports = { } }) } - + // Gamemode b.add_sc_task('gamemode', '/minecraft:gamemode creative', true) b._client.on('game_state_change', (p) => { diff --git a/util/ConsoleCommand.js b/util/ConsoleCommand.js index addf695..7c29e3b 100644 --- a/util/ConsoleCommand.js +++ b/util/ConsoleCommand.js @@ -1,10 +1,7 @@ // HOW TO WRITE CLASS JS const index = require('../index.js') -const cmds = require('./commands.js') const parse = require('../util/chatparse_console.js') const settings = require('../settings.json') -const {getMessage} = require('../util/lang.js') -const lang = settings.defaultLang class ConsoleCommand { constructor (cmd, index2) { this.send = () => {} // not needed for console diff --git a/util/chatparse_console.js b/util/chatparse_console.js index b7a7257..2b07167 100644 --- a/util/chatparse_console.js +++ b/util/chatparse_console.js @@ -1,20 +1,20 @@ -const settings = require('../settings.json'); -const lang = require('./mc_lang.js'); +const settings = require('../settings.json') +const lang = require('./mc_lang.js') -const _consoleColors = require("./consolecolors.json"); -let consoleColors; -let consoleColors24; -if(_consoleColors[settings.terminalMode]){ - consoleColors=_consoleColors[settings.terminalMode].fourBit - consoleColors24=_consoleColors[settings.terminalMode].twentyFourBit +const _consoleColors = require('./consolecolors.json') +let consoleColors +let consoleColors24 +if (_consoleColors[settings.terminalMode]) { + consoleColors = _consoleColors[settings.terminalMode].fourBit + consoleColors24 = _consoleColors[settings.terminalMode].twentyFourBit } else { - consoleColors=_consoleColors.none.fourBit - consoleColors24=_consoleColors.none.twentyFourBit + consoleColors = _consoleColors.none.fourBit + consoleColors24 = _consoleColors.none.twentyFourBit } const hexColorParser = (color) => { - if(!consoleColors24.enabled || consoleColors24.bit!==24){ // Hex color parsing to the 8 bit and 4 bit modes has not been implemented yet - return ""; + if (!consoleColors24.enabled || consoleColors24.bit !== 24) { // Hex color parsing to the 8 bit and 4 bit modes has not been implemented yet + return '' } let out = '\x1B[0;' const redChannel = Number('0x' + color.slice(1, 3)) @@ -29,7 +29,7 @@ const hexColorParser = (color) => { } const processColor = (col, rcol) => { - let out; + let out if (col === 'reset') { out = rcol } else if (col.startsWith('#')) { @@ -55,7 +55,7 @@ const parse = function (_data, l = 0, resetColor = consoleColors.reset) { data = _data } let nkt = false - let out = "" + let out = '' if (data['']) { data.text = data[''] nkt = true diff --git a/util/chatparse_plain.js b/util/chatparse_plain.js index f35f19b..c6b2856 100644 --- a/util/chatparse_plain.js +++ b/util/chatparse_plain.js @@ -1,4 +1,4 @@ -const lang = require('./mc_lang.js'); +const lang = require('./mc_lang.js') const parse = function (_data, l = 0) { if (l >= 12) { @@ -14,11 +14,9 @@ const parse = function (_data, l = 0) { } else { data = _data } - let nkt = false - let out = "" + let out = '' if (data['']) { data.text = data[''] - nkt = true } if (data.text) { let _text = data.text diff --git a/util/commands.js b/util/commands.js index 7d25194..e1b9015 100644 --- a/util/commands.js +++ b/util/commands.js @@ -26,4 +26,4 @@ for (const i in bpl) { // Built-in loadCMD } } catch (e) { console.log(e) } } -module.exports=cmds; \ No newline at end of file +module.exports = cmds diff --git a/util/lang.js b/util/lang.js index 6b0d2fe..54dcee8 100644 --- a/util/lang.js +++ b/util/lang.js @@ -35,24 +35,24 @@ module.exports = { const days = Math.floor(time / 86400000) % 7 const weeks = Math.floor(time / 604800000) if (weeks !== 0) { - finalString += weeks; - finalString += `${weeks === 1 ? getMessage(language, "time.week") : getMessage(language, "time.weekPlural")}` + finalString += weeks + finalString += `${weeks === 1 ? getMessage(language, 'time.week') : getMessage(language, 'time.weekPlural')}` } if (days !== 0) { - finalString += days; - finalString += `${days === 1 ? getMessage(language, "time.day") : getMessage(language, "time.dayPlural")}` + finalString += days + finalString += `${days === 1 ? getMessage(language, 'time.day') : getMessage(language, 'time.dayPlural')}` } if (hours !== 0) { - finalString += hours; - finalString += `${hours === 1 ? getMessage(language, "time.hour") : getMessage(language, "time.hourPlural")}` + finalString += hours + finalString += `${hours === 1 ? getMessage(language, 'time.hour') : getMessage(language, 'time.hourPlural')}` } if (minutes !== 0) { - finalString += minutes; - finalString += `${minutes === 1 ? getMessage(language, "time.minute") : getMessage(language, "time.minutePlural")}` + finalString += minutes + finalString += `${minutes === 1 ? getMessage(language, 'time.minute') : getMessage(language, 'time.minutePlural')}` } if (seconds !== 0) { - finalString += seconds; - finalString += `${seconds === 1 ? getMessage(language, "time.second") : getMessage(language, "time.secondPlural")}` + finalString += seconds + finalString += `${seconds === 1 ? getMessage(language, 'time.second') : getMessage(language, 'time.secondPlural')}` } return finalString } diff --git a/util/mc_lang.js b/util/mc_lang.js index 67f656d..971486e 100644 --- a/util/mc_lang.js +++ b/util/mc_lang.js @@ -1,6 +1,6 @@ -const _lang = require('minecraft-data')('1.20.2').language; +const _lang = require('minecraft-data')('1.20.2').language const lang = Object.create(null) // Without constructor function for (const i in _lang) { lang[i] = _lang[i] } -module.exports=lang \ No newline at end of file +module.exports = lang diff --git a/util/version.js b/util/version.js index 83d9aef..5ecf7e5 100644 --- a/util/version.js +++ b/util/version.js @@ -17,4 +17,4 @@ if (gitCommit) { botVersion += ` (${gitCommit} - ${gitBranch})` } -module.exports=botVersion; \ No newline at end of file +module.exports = botVersion