Convert arrays to use for...of or forEach instead of for...in

for...in is for objects, not arrays apparently
This commit is contained in:
7cc5c4f330d47060 2024-08-21 16:52:04 -04:00
parent c4d07a1ff9
commit b0241e707c
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
13 changed files with 77 additions and 73 deletions

View file

@ -70,11 +70,11 @@ const os2 = function (o2, l) {
if (fs.readdirSync('/etc').includes('os-release')) { if (fs.readdirSync('/etc').includes('os-release')) {
const osrelease = fs.readFileSync('/etc/os-release').toString('UTF-8').split('\n') const osrelease = fs.readFileSync('/etc/os-release').toString('UTF-8').split('\n')
const osrelease2 = {} const osrelease2 = {}
for (const i in osrelease) { for (const item of osrelease) {
if (!osrelease[i].includes('=')) continue if (!item.includes('=')) continue
let osrvalue = osrelease[i].split('=')[1] let osrvalue = item.split('=')[1]
if (osrvalue.startsWith('"') && osrvalue.endsWith('"')) { osrvalue = osrvalue.slice(1, osrvalue.length - 1) }; if (osrvalue.startsWith('"') && osrvalue.endsWith('"')) { osrvalue = osrvalue.slice(1, osrvalue.length - 1) };
osrelease2[osrelease[i].split('=')[0]] = osrvalue osrelease2[item.split('=')[0]] = osrvalue
} }
if (osrelease2.PRETTY_NAME) { if (osrelease2.PRETTY_NAME) {
@ -186,8 +186,8 @@ const aboutServer = function (c) {
} }
const displayServerList = function (c) { const displayServerList = function (c) {
for (const i in index.bot) { index.bot.forEach((item, i)=>{
if (index.bot[i].host.options && index.bot[i].host.options.hidden) continue if (item.host.options && item.host.options.hidden) return
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,
@ -197,12 +197,12 @@ const displayServerList = function (c) {
color: c.colors.primary color: c.colors.primary
}, },
{ {
text: `${index.bot[i].host.host}:${index.bot[i].host.port}`, text: `${item.host.host}:${item.host.port}`,
color: c.colors.primary color: c.colors.primary
} }
] ]
}) })
} })
} }
module.exports = { module.exports = {

View file

@ -44,26 +44,26 @@ module.exports = {
break break
} }
case 'list': case 'list':
for (const i in c.bot.cloops) { c.bot.cloops.forEach((item, i)=>{
c.reply({ c.reply({
translate: getMessage(c.lang, 'command.cloop.list'), translate: getMessage(c.lang, 'command.cloop.list'),
color: c.colors.secondary, color: c.colors.secondary,
with: [ with: [
{ {
text: i, text: i.toString(),
color: c.colors.primary color: c.colors.primary
}, },
{ {
text: c.bot.cloops[i].command, text: item.command,
color: c.colors.primary color: c.colors.primary
}, },
{ {
text: c.bot.cloops[i].rate + '', text: item.rate + '',
color: c.colors.primary color: c.colors.primary
} }
] ]
}) })
} })
break break
case 'clear': case 'clear':
c.bot.clearCloops() c.bot.clearCloops()

View file

@ -9,14 +9,14 @@ const sortHelp = function sortHelp (c1, c2) {
} }
const bpl = fs.readdirSync('./commands') const bpl = fs.readdirSync('./commands')
for (const i in bpl) { for (const plugin of bpl) {
if (!bpl[i].endsWith('.js')) { if (!plugin.endsWith('.js')) {
continue continue
} }
try { try {
const commandName = bpl[i].split('.js')[0] const commandName = plugin.split('.js')[0]
if (commandName !== 'help') { if (commandName !== 'help') {
cmds[commandName] = require(`./${bpl[i]}`) cmds[commandName] = require(`./${plugin}`)
if (cmds[commandName].level === undefined) { if (cmds[commandName].level === undefined) {
cmds[commandName].level = 0 cmds[commandName].level = 0
} }
@ -89,7 +89,7 @@ const printCmdHelp = (c) => {
desc = cmds[cmds[cmd].alias].desc desc = cmds[cmds[cmd].alias].desc
} }
} }
for (const i in usage) { for (const item of usage) {
c.reply({ c.reply({
translate: getMessage(c.lang, 'command.help.commandUsage'), translate: getMessage(c.lang, 'command.help.commandUsage'),
color: c.colors.secondary, color: c.colors.secondary,
@ -99,7 +99,7 @@ const printCmdHelp = (c) => {
color: c.colors.primary color: c.colors.primary
}, },
{ {
text: usage[i], text: item,
color: c.colors.primary color: c.colors.primary
} }
] ]
@ -152,8 +152,8 @@ if (cmds.help.level === undefined) {
for (const i in cmds) { for (const i in cmds) {
if (cmds[i].aliases) { if (cmds[i].aliases) {
for (const j in cmds[i].aliases) { for (const alias of cmds[commandName].aliases) {
cmds[cmds[i].aliases[j]] = { cmds[alias] = {
alias: i, alias: i,
usage: cmds[i].usage, usage: cmds[i].usage,
level: cmds[i].level, level: cmds[i].level,

View file

@ -36,9 +36,9 @@ module.exports = {
], ],
color: 'white' color: 'white'
} }
for (const i in bot) { bot.forEach(item => {
if (bot[i].host.options.hidden) continue if (item.host.options.hidden) return
bot[i].tellraw('@a', json) item.tellraw('@a', json)
} })
} }
} }

View file

@ -17,27 +17,27 @@ module.exports = {
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 item of 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(item, 'language.name'),
color: c.colors.primary color: c.colors.primary
}, },
{ {
text: getMessage(languages[i], 'language.region'), text: getMessage(item, '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(item, 'command.settings.setLanguage'),
with: [ with: [
{ {
text: `${c.prefix}settings set lang ${languages[i]}`, text: `${c.prefix}settings set lang ${item}`,
color: c.colors.secondary color: c.colors.secondary
} }
] ]

View file

@ -8,12 +8,12 @@ module.exports.bot = []
const botplug = [] const botplug = []
const bpl = fs.readdirSync('plugins') const bpl = fs.readdirSync('plugins')
for (const i in bpl) { for (const plugin of bpl) {
if (!bpl[i].endsWith('.js')) { if (!plugin.endsWith('.js')) {
continue continue
} }
try { try {
botplug.push(require(`./plugins/${bpl[i]}`)) botplug.push(require(`./plugins/${plugin}`))
} catch (e) { console.log(e) } } catch (e) { console.log(e) }
} }
@ -67,8 +67,8 @@ const createBot = function createBot (host, oldId) {
}) })
} }
for (const i in settings.servers) { for (const server of settings.servers) {
createBot(settings.servers[i]) createBot(server)
} }
module.exports.createBot = createBot module.exports.createBot = createBot

View file

@ -181,10 +181,10 @@ module.exports = {
b.displayChat(data.type, `${msgConsole}\x1b[0m`) b.displayChat(data.type, `${msgConsole}\x1b[0m`)
const fullCommand = data.message const fullCommand = data.message
for (const i in b.prefix) { for (const prefix of b.prefix) {
if (fullCommand.startsWith(b.prefix[i])) { if (fullCommand.startsWith(prefix)) {
const command = fullCommand.slice(b.prefix[i].length) const command = fullCommand.slice(prefix.length)
b.runCommand(data.username, data.nickname, data.uuid, command, data.type, b.prefix[i]) b.runCommand(data.username, data.nickname, data.uuid, command, data.type, prefix)
} }
} }
}) })

View file

@ -14,8 +14,8 @@ module.exports = {
b.cloops.splice(index, 1) b.cloops.splice(index, 1)
} }
b.clearCloops = function () { b.clearCloops = function () {
for (const i in b.cloops) { for (const cloop of b.cloops) {
clearInterval(b.cloops[i].interval) clearInterval(cloop.interval)
} }
b.cloops = [] b.cloops = []
} }

View file

@ -5,24 +5,24 @@ module.exports = {
b.players = {} b.players = {}
b._client.on('player_info', (data) => { b._client.on('player_info', (data) => {
const buffer2 = {} const buffer2 = {}
for (const i in data.data) { for (const player of data.data) {
let uuid let uuid
if (data.data[i].uuid) { if (player.uuid) {
uuid = data.data[i].uuid uuid = player.uuid
} else if (data.data[i].UUID) { } else if (player.UUID) {
uuid = data.data[i].UUID uuid = player.UUID
} }
let displayName let displayName
if (data.data[i].displayName !== undefined) { if (player.displayName !== undefined) {
displayName = data.data[i].displayName displayName = player.displayName
} else { } else {
displayName = '{"text":"[[[[ No display name ]]]]"}' displayName = '{"text":"[[[[ No display name ]]]]"}'
} }
if (data.data[i].player && data.data[i].player.name !== undefined) { if (player.player && player.player.name !== undefined) {
buffer2[uuid] = { realName: data.data[i].player.name, displayName: parse(parseNBT(displayName)) } buffer2[uuid] = { realName: player.player.name, displayName: parse(parseNBT(displayName)) }
} else if (data.data[i].name !== undefined) { } else if (player.name !== undefined) {
buffer2[uuid] = { realName: data.data[i].name, displayName: parse(parseNBT(displayName)) } buffer2[uuid] = { realName: player.name, displayName: parse(parseNBT(displayName)) }
} else if (data.data[i].displayName !== undefined) { } else if (player.displayName !== undefined) {
buffer2[uuid] = { displayName: parse(parseNBT(displayName)) } buffer2[uuid] = { displayName: parse(parseNBT(displayName)) }
} }
} }

View file

@ -77,16 +77,18 @@ const parse = function (_data, l = 0, resetColor = consoleColors.reset) {
if (lang[trans] !== undefined) { if (lang[trans] !== undefined) {
trans = lang[trans].replace(/%%/g, '\ue123') trans = lang[trans].replace(/%%/g, '\ue123')
} }
for (const i in data.with) { if(data.with){
const j2 = parse(data.with[i], l + 1, data.color ? processColor(data.color, resetColor) : resetColor) data.with.forEach((item, i) => {
trans = trans.replace(/%s/, j2.replaceAll('%s', '\ud900\ud804').replaceAll('$s', '\ud900\ud805')) const j2 = parse(item, l + 1, data.color ? processColor(data.color, resetColor) : resetColor)
trans = trans.replaceAll(`%${+i + 1}$s`, j2.replaceAll('%s', '\ud900\ud804').replaceAll('$s', '\ud900\ud805')) trans = trans.replace(/%s/, j2.replaceAll('%s', '\ud900\ud804').replaceAll('$s', '\ud900\ud805'))
trans = trans.replaceAll(`%${+i + 1}$s`, j2.replaceAll('%s', '\ud900\ud804').replaceAll('$s', '\ud900\ud805'))
})
} }
out += trans.replaceAll('\ud900\ud801', '%').replaceAll('\ud900\ud804', '%s').replaceAll('\ud900\ud805', '$s') out += trans.replaceAll('\ud900\ud801', '%').replaceAll('\ud900\ud804', '%s').replaceAll('\ud900\ud805', '$s')
} }
if (data.extra) { if (data.extra) {
for (const i in data.extra) { for (const item of data.extra) {
const parsed = parse(data.extra[i], l, data.color ? processColor(data.color, resetColor) : resetColor) const parsed = parse(item, l, data.color ? processColor(data.color, resetColor) : resetColor)
out += parsed out += parsed
} }
} }

View file

@ -37,8 +37,8 @@ const parse = function (_data, l = 0) {
out += trans.replaceAll('\ud900\ud801', '%').replaceAll('\ud900\ud804', '%s').replaceAll('\ud900\ud805', '$s') out += trans.replaceAll('\ud900\ud801', '%').replaceAll('\ud900\ud804', '%s').replaceAll('\ud900\ud805', '$s')
} }
if (data.extra) { if (data.extra) {
for (const i in data.extra) { for (const item of data.extra) {
const parsed = parse(data.extra[i], l) const parsed = parse(item, l)
out += parsed out += parsed
} }
} }

View file

@ -1,19 +1,19 @@
const fs = require('fs') const fs = require('fs')
const cmds = Object.create(null) const cmds = Object.create(null)
const bpl = fs.readdirSync('./commands') const bpl = fs.readdirSync('./commands')
for (const i in bpl) { for (const plugin of bpl) {
if (!bpl[i].endsWith('.js')) { if (!plugin.endsWith('.js')) {
continue continue
} }
try { try {
const commandName = bpl[i].split('.js')[0] const commandName = plugin.split('.js')[0]
cmds[commandName] = require(`../commands/${bpl[i]}`) cmds[commandName] = require(`../commands/${plugin}`)
if (cmds[commandName].level === undefined) { if (cmds[commandName].level === undefined) {
cmds[commandName].level = 0 cmds[commandName].level = 0
} }
if (cmds[commandName].aliases) { if (cmds[commandName].aliases) {
for (const j in cmds[commandName].aliases) { for (const alias of cmds[commandName].aliases) {
cmds[cmds[commandName].aliases[j]] = { cmds[alias] = {
execute: cmds[commandName].execute, execute: cmds[commandName].execute,
alias: commandName, alias: commandName,
usage: cmds[commandName].usage, usage: cmds[commandName].usage,

View file

@ -3,12 +3,12 @@ const languages = {}
const loadplug = (botno) => { const loadplug = (botno) => {
const bpl = fs.readdirSync('lang') const bpl = fs.readdirSync('lang')
for (const i in bpl) { for (const plugin of bpl) {
if (!bpl[i].endsWith('.json')) { if (!plugin.endsWith('.json')) {
continue continue
} }
try { try {
languages[bpl[i].split('.')[0]] = require(`../lang/${bpl[i]}`) languages[plugin.split('.')[0]] = require(`../lang/${plugin}`)
} catch (e) { console.log(e) } } catch (e) { console.log(e) }
} }
} }
@ -21,9 +21,11 @@ const getMessage = function (l, msg, with2) {
} else if (languages['en-US'] && languages['en-US'][message] !== undefined) { } else if (languages['en-US'] && languages['en-US'][message] !== undefined) {
message = languages['en-US'][message].replace(/%%/g, '\ue123') message = languages['en-US'][message].replace(/%%/g, '\ue123')
} }
for (const i in with2) { if (with2){
message = message.replace(/%s/, with2[i].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125')) for (const withItem of with2) {
message = message.replaceAll(`%${+i + 1}$s`, with2[i].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125')) message = message.replace(/%s/, withItem.replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
message = message.replaceAll(`%${+i + 1}$s`, withItem.replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
}
} }
return message.replace(/\ue123/g, '%').replace(/\ue124/g, '%s').replace(/\ue125/g, '$s') return message.replace(/\ue123/g, '%').replace(/\ue124/g, '%s').replace(/\ue125/g, '$s')
} }