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:
parent
c4d07a1ff9
commit
b0241e707c
13 changed files with 77 additions and 73 deletions
|
@ -70,11 +70,11 @@ const os2 = function (o2, l) {
|
|||
if (fs.readdirSync('/etc').includes('os-release')) {
|
||||
const osrelease = fs.readFileSync('/etc/os-release').toString('UTF-8').split('\n')
|
||||
const osrelease2 = {}
|
||||
for (const i in osrelease) {
|
||||
if (!osrelease[i].includes('=')) continue
|
||||
let osrvalue = osrelease[i].split('=')[1]
|
||||
for (const item of osrelease) {
|
||||
if (!item.includes('=')) continue
|
||||
let osrvalue = item.split('=')[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) {
|
||||
|
@ -186,8 +186,8 @@ const aboutServer = function (c) {
|
|||
}
|
||||
|
||||
const displayServerList = function (c) {
|
||||
for (const i in index.bot) {
|
||||
if (index.bot[i].host.options && index.bot[i].host.options.hidden) continue
|
||||
index.bot.forEach((item, i)=>{
|
||||
if (item.host.options && item.host.options.hidden) return
|
||||
c.reply({
|
||||
translate: getMessage(c.lang, 'command.about.serverListItem'),
|
||||
color: c.colors.secondary,
|
||||
|
@ -197,12 +197,12 @@ const displayServerList = function (c) {
|
|||
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
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
|
@ -44,26 +44,26 @@ module.exports = {
|
|||
break
|
||||
}
|
||||
case 'list':
|
||||
for (const i in c.bot.cloops) {
|
||||
c.bot.cloops.forEach((item, i)=>{
|
||||
c.reply({
|
||||
translate: getMessage(c.lang, 'command.cloop.list'),
|
||||
color: c.colors.secondary,
|
||||
with: [
|
||||
{
|
||||
text: i,
|
||||
text: i.toString(),
|
||||
color: c.colors.primary
|
||||
},
|
||||
{
|
||||
text: c.bot.cloops[i].command,
|
||||
text: item.command,
|
||||
color: c.colors.primary
|
||||
},
|
||||
{
|
||||
text: c.bot.cloops[i].rate + '',
|
||||
text: item.rate + '',
|
||||
color: c.colors.primary
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
})
|
||||
break
|
||||
case 'clear':
|
||||
c.bot.clearCloops()
|
||||
|
|
|
@ -9,14 +9,14 @@ const sortHelp = function sortHelp (c1, c2) {
|
|||
}
|
||||
|
||||
const bpl = fs.readdirSync('./commands')
|
||||
for (const i in bpl) {
|
||||
if (!bpl[i].endsWith('.js')) {
|
||||
for (const plugin of bpl) {
|
||||
if (!plugin.endsWith('.js')) {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
const commandName = bpl[i].split('.js')[0]
|
||||
const commandName = plugin.split('.js')[0]
|
||||
if (commandName !== 'help') {
|
||||
cmds[commandName] = require(`./${bpl[i]}`)
|
||||
cmds[commandName] = require(`./${plugin}`)
|
||||
if (cmds[commandName].level === undefined) {
|
||||
cmds[commandName].level = 0
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ const printCmdHelp = (c) => {
|
|||
desc = cmds[cmds[cmd].alias].desc
|
||||
}
|
||||
}
|
||||
for (const i in usage) {
|
||||
for (const item of usage) {
|
||||
c.reply({
|
||||
translate: getMessage(c.lang, 'command.help.commandUsage'),
|
||||
color: c.colors.secondary,
|
||||
|
@ -99,7 +99,7 @@ const printCmdHelp = (c) => {
|
|||
color: c.colors.primary
|
||||
},
|
||||
{
|
||||
text: usage[i],
|
||||
text: item,
|
||||
color: c.colors.primary
|
||||
}
|
||||
]
|
||||
|
@ -152,8 +152,8 @@ if (cmds.help.level === undefined) {
|
|||
|
||||
for (const i in cmds) {
|
||||
if (cmds[i].aliases) {
|
||||
for (const j in cmds[i].aliases) {
|
||||
cmds[cmds[i].aliases[j]] = {
|
||||
for (const alias of cmds[commandName].aliases) {
|
||||
cmds[alias] = {
|
||||
alias: i,
|
||||
usage: cmds[i].usage,
|
||||
level: cmds[i].level,
|
||||
|
|
|
@ -36,9 +36,9 @@ module.exports = {
|
|||
],
|
||||
color: 'white'
|
||||
}
|
||||
for (const i in bot) {
|
||||
if (bot[i].host.options.hidden) continue
|
||||
bot[i].tellraw('@a', json)
|
||||
}
|
||||
bot.forEach(item => {
|
||||
if (item.host.options.hidden) return
|
||||
item.tellraw('@a', json)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,27 +17,27 @@ module.exports = {
|
|||
const value = c.args.join(' ')
|
||||
if (value === '' && key === 'lang') {
|
||||
// Show all valid languages to user
|
||||
for (const i in languages) {
|
||||
for (const item of languages) {
|
||||
c.reply({
|
||||
translate: '%s (%s)',
|
||||
color: c.colors.secondary,
|
||||
with: [
|
||||
{
|
||||
text: getMessage(languages[i], 'language.name'),
|
||||
text: getMessage(item, 'language.name'),
|
||||
color: c.colors.primary
|
||||
},
|
||||
{
|
||||
text: getMessage(languages[i], 'language.region'),
|
||||
text: getMessage(item, 'language.region'),
|
||||
color: c.colors.primary
|
||||
}
|
||||
],
|
||||
hoverEvent: {
|
||||
action: 'show_text',
|
||||
value: {
|
||||
translate: getMessage(languages[i], 'command.settings.setLanguage'),
|
||||
translate: getMessage(item, 'command.settings.setLanguage'),
|
||||
with: [
|
||||
{
|
||||
text: `${c.prefix}settings set lang ${languages[i]}`,
|
||||
text: `${c.prefix}settings set lang ${item}`,
|
||||
color: c.colors.secondary
|
||||
}
|
||||
]
|
||||
|
|
10
index.js
10
index.js
|
@ -8,12 +8,12 @@ module.exports.bot = []
|
|||
|
||||
const botplug = []
|
||||
const bpl = fs.readdirSync('plugins')
|
||||
for (const i in bpl) {
|
||||
if (!bpl[i].endsWith('.js')) {
|
||||
for (const plugin of bpl) {
|
||||
if (!plugin.endsWith('.js')) {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
botplug.push(require(`./plugins/${bpl[i]}`))
|
||||
botplug.push(require(`./plugins/${plugin}`))
|
||||
} catch (e) { console.log(e) }
|
||||
}
|
||||
|
||||
|
@ -67,8 +67,8 @@ const createBot = function createBot (host, oldId) {
|
|||
})
|
||||
}
|
||||
|
||||
for (const i in settings.servers) {
|
||||
createBot(settings.servers[i])
|
||||
for (const server of settings.servers) {
|
||||
createBot(server)
|
||||
}
|
||||
|
||||
module.exports.createBot = createBot
|
||||
|
|
|
@ -181,10 +181,10 @@ module.exports = {
|
|||
b.displayChat(data.type, `${msgConsole}\x1b[0m`)
|
||||
|
||||
const fullCommand = data.message
|
||||
for (const i in b.prefix) {
|
||||
if (fullCommand.startsWith(b.prefix[i])) {
|
||||
const command = fullCommand.slice(b.prefix[i].length)
|
||||
b.runCommand(data.username, data.nickname, data.uuid, command, data.type, b.prefix[i])
|
||||
for (const prefix of b.prefix) {
|
||||
if (fullCommand.startsWith(prefix)) {
|
||||
const command = fullCommand.slice(prefix.length)
|
||||
b.runCommand(data.username, data.nickname, data.uuid, command, data.type, prefix)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -14,8 +14,8 @@ module.exports = {
|
|||
b.cloops.splice(index, 1)
|
||||
}
|
||||
b.clearCloops = function () {
|
||||
for (const i in b.cloops) {
|
||||
clearInterval(b.cloops[i].interval)
|
||||
for (const cloop of b.cloops) {
|
||||
clearInterval(cloop.interval)
|
||||
}
|
||||
b.cloops = []
|
||||
}
|
||||
|
|
|
@ -5,24 +5,24 @@ module.exports = {
|
|||
b.players = {}
|
||||
b._client.on('player_info', (data) => {
|
||||
const buffer2 = {}
|
||||
for (const i in data.data) {
|
||||
for (const player of data.data) {
|
||||
let uuid
|
||||
if (data.data[i].uuid) {
|
||||
uuid = data.data[i].uuid
|
||||
} else if (data.data[i].UUID) {
|
||||
uuid = data.data[i].UUID
|
||||
if (player.uuid) {
|
||||
uuid = player.uuid
|
||||
} else if (player.UUID) {
|
||||
uuid = player.UUID
|
||||
}
|
||||
let displayName
|
||||
if (data.data[i].displayName !== undefined) {
|
||||
displayName = data.data[i].displayName
|
||||
if (player.displayName !== undefined) {
|
||||
displayName = player.displayName
|
||||
} else {
|
||||
displayName = '{"text":"[[[[ No display name ]]]]"}'
|
||||
}
|
||||
if (data.data[i].player && data.data[i].player.name !== undefined) {
|
||||
buffer2[uuid] = { realName: data.data[i].player.name, displayName: parse(parseNBT(displayName)) }
|
||||
} else if (data.data[i].name !== undefined) {
|
||||
buffer2[uuid] = { realName: data.data[i].name, displayName: parse(parseNBT(displayName)) }
|
||||
} else if (data.data[i].displayName !== undefined) {
|
||||
if (player.player && player.player.name !== undefined) {
|
||||
buffer2[uuid] = { realName: player.player.name, displayName: parse(parseNBT(displayName)) }
|
||||
} else if (player.name !== undefined) {
|
||||
buffer2[uuid] = { realName: player.name, displayName: parse(parseNBT(displayName)) }
|
||||
} else if (player.displayName !== undefined) {
|
||||
buffer2[uuid] = { displayName: parse(parseNBT(displayName)) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,16 +77,18 @@ const parse = function (_data, l = 0, resetColor = consoleColors.reset) {
|
|||
if (lang[trans] !== undefined) {
|
||||
trans = lang[trans].replace(/%%/g, '\ue123')
|
||||
}
|
||||
for (const i in data.with) {
|
||||
const j2 = parse(data.with[i], l + 1, data.color ? processColor(data.color, resetColor) : resetColor)
|
||||
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'))
|
||||
if(data.with){
|
||||
data.with.forEach((item, i) => {
|
||||
const j2 = parse(item, l + 1, data.color ? processColor(data.color, resetColor) : resetColor)
|
||||
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')
|
||||
}
|
||||
if (data.extra) {
|
||||
for (const i in data.extra) {
|
||||
const parsed = parse(data.extra[i], l, data.color ? processColor(data.color, resetColor) : resetColor)
|
||||
for (const item of data.extra) {
|
||||
const parsed = parse(item, l, data.color ? processColor(data.color, resetColor) : resetColor)
|
||||
out += parsed
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ const parse = function (_data, l = 0) {
|
|||
out += trans.replaceAll('\ud900\ud801', '%').replaceAll('\ud900\ud804', '%s').replaceAll('\ud900\ud805', '$s')
|
||||
}
|
||||
if (data.extra) {
|
||||
for (const i in data.extra) {
|
||||
const parsed = parse(data.extra[i], l)
|
||||
for (const item of data.extra) {
|
||||
const parsed = parse(item, l)
|
||||
out += parsed
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
const fs = require('fs')
|
||||
const cmds = Object.create(null)
|
||||
const bpl = fs.readdirSync('./commands')
|
||||
for (const i in bpl) {
|
||||
if (!bpl[i].endsWith('.js')) {
|
||||
for (const plugin of bpl) {
|
||||
if (!plugin.endsWith('.js')) {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
const commandName = bpl[i].split('.js')[0]
|
||||
cmds[commandName] = require(`../commands/${bpl[i]}`)
|
||||
const commandName = plugin.split('.js')[0]
|
||||
cmds[commandName] = require(`../commands/${plugin}`)
|
||||
if (cmds[commandName].level === undefined) {
|
||||
cmds[commandName].level = 0
|
||||
}
|
||||
if (cmds[commandName].aliases) {
|
||||
for (const j in cmds[commandName].aliases) {
|
||||
cmds[cmds[commandName].aliases[j]] = {
|
||||
for (const alias of cmds[commandName].aliases) {
|
||||
cmds[alias] = {
|
||||
execute: cmds[commandName].execute,
|
||||
alias: commandName,
|
||||
usage: cmds[commandName].usage,
|
||||
|
|
14
util/lang.js
14
util/lang.js
|
@ -3,12 +3,12 @@ const languages = {}
|
|||
|
||||
const loadplug = (botno) => {
|
||||
const bpl = fs.readdirSync('lang')
|
||||
for (const i in bpl) {
|
||||
if (!bpl[i].endsWith('.json')) {
|
||||
for (const plugin of bpl) {
|
||||
if (!plugin.endsWith('.json')) {
|
||||
continue
|
||||
}
|
||||
try {
|
||||
languages[bpl[i].split('.')[0]] = require(`../lang/${bpl[i]}`)
|
||||
languages[plugin.split('.')[0]] = require(`../lang/${plugin}`)
|
||||
} 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) {
|
||||
message = languages['en-US'][message].replace(/%%/g, '\ue123')
|
||||
}
|
||||
for (const i in with2) {
|
||||
message = message.replace(/%s/, with2[i].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
message = message.replaceAll(`%${+i + 1}$s`, with2[i].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
||||
if (with2){
|
||||
for (const withItem of with2) {
|
||||
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')
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue