Merge pull request 'refactor: small cleanups' (#1) from amy/botv12:main into main
Reviewed-on: #1
This commit is contained in:
commit
7fe346075e
10 changed files with 108 additions and 80 deletions
4
index.js
4
index.js
|
@ -30,9 +30,9 @@ const createBot = function createBot (host, oldId) {
|
||||||
|
|
||||||
bot._client = createClient({
|
bot._client = createClient({
|
||||||
host: host.host,
|
host: host.host,
|
||||||
port: host.port ? host.port : 25565,
|
port: host.port ?? 25565,
|
||||||
username: generateUser(host.options.legalName),
|
username: generateUser(host.options.legalName),
|
||||||
version: host.version ? host.version : settings.version_mc
|
version: host.version ?? settings.version_mc
|
||||||
})
|
})
|
||||||
|
|
||||||
bot.info = (msg) => {
|
bot.info = (msg) => {
|
||||||
|
|
19
launch.cmd
19
launch.cmd
|
@ -1,8 +1,15 @@
|
||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
:botlaunch
|
:botlaunch
|
||||||
node index.js
|
node index.js
|
||||||
if %errorlevel%==1 (
|
call :err_unwrap
|
||||||
exit
|
|
||||||
)
|
timeout /nobreak /t 5 >NUL
|
||||||
timeout /nobreak /t 5 > nul
|
goto botlaunch
|
||||||
goto botlaunch
|
|
||||||
|
:err_unwrap
|
||||||
|
set _err=%ERRORLEVEL%
|
||||||
|
if %_err% neq 0 (
|
||||||
|
exit %_err%
|
||||||
|
)
|
||||||
|
goto :eof
|
||||||
|
|
11
launch.sh
11
launch.sh
|
@ -1,6 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
while [ true ];
|
set -xe
|
||||||
do node index.js;
|
|
||||||
if [ $? -eq 1 ]; then exit; fi
|
while :; do
|
||||||
sleep 6;
|
node index.js
|
||||||
|
sleep 5
|
||||||
done
|
done
|
65
package-lock.json
generated
65
package-lock.json
generated
|
@ -9,7 +9,8 @@
|
||||||
"version": "12.0.0-alpha.2",
|
"version": "12.0.0-alpha.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minecraft-protocol": "^1.49.0"
|
"minecraft-protocol": "^1.51.0",
|
||||||
|
"prismarine-chat": "^1.10.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@azure/msal-common": {
|
"node_modules/@azure/msal-common": {
|
||||||
|
@ -36,12 +37,21 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "22.9.1",
|
"version": "22.10.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.2.tgz",
|
||||||
"integrity": "sha512-p8Yy/8sw1caA8CdRIQBG5tiLHmxtQKObCijiAa9Ez+d4+PRffM4054xbju0msf+cvhJpnFEeNjxmVT/0ipktrg==",
|
"integrity": "sha512-Xxr6BBRCAOQixvonOye19wnzyDiUtTeqldOOmj3CkeblonbccA12PFwlufvRdrpjXxqnmUaeiU5EOA+7s5diUQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~6.19.8"
|
"undici-types": "~6.20.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/node-rsa": {
|
||||||
|
"version": "1.1.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/node-rsa/-/node-rsa-1.1.4.tgz",
|
||||||
|
"integrity": "sha512-dB0ECel6JpMnq5ULvpUTunx3yNm8e/dIkv8Zu9p2c8me70xIRUUG3q+qXRwcSf9rN3oqamv4116iHy90dJGRpA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/readable-stream": {
|
"node_modules/@types/readable-stream": {
|
||||||
|
@ -188,9 +198,9 @@
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.3.7",
|
"version": "4.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz",
|
||||||
"integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
|
"integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ms": "^2.1.3"
|
"ms": "^2.1.3"
|
||||||
|
@ -420,9 +430,9 @@
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/minecraft-data": {
|
"node_modules/minecraft-data": {
|
||||||
"version": "3.78.0",
|
"version": "3.80.0",
|
||||||
"resolved": "https://registry.npmjs.org/minecraft-data/-/minecraft-data-3.78.0.tgz",
|
"resolved": "https://registry.npmjs.org/minecraft-data/-/minecraft-data-3.80.0.tgz",
|
||||||
"integrity": "sha512-Ssks8QD31lsoxqa7LySTqeP9romsfAbfsSGiUHiGMeqfxRi/PtOxGLyKD1BXB8V/tXLztFcbQYqzIhprDkPguw==",
|
"integrity": "sha512-UYq+ADpS9K1+cqiJiz6tqkht4y4cRYF3qOYanG9eIiHY+VC+qIAC7/UcW6G3adayvj5YBOCurlqaw3E0TMAtHg==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/minecraft-folder-path": {
|
"node_modules/minecraft-folder-path": {
|
||||||
|
@ -432,11 +442,12 @@
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/minecraft-protocol": {
|
"node_modules/minecraft-protocol": {
|
||||||
"version": "1.50.0",
|
"version": "1.51.0",
|
||||||
"resolved": "https://registry.npmjs.org/minecraft-protocol/-/minecraft-protocol-1.50.0.tgz",
|
"resolved": "https://registry.npmjs.org/minecraft-protocol/-/minecraft-protocol-1.51.0.tgz",
|
||||||
"integrity": "sha512-GiZy8g4YG0iZEKifX6ulCyhVnTDGZ1gH0ouUdxjo6xkKwp4KOf+ptbBgZ8G5+WHCumrI91+v/JYU07uCvKdi0w==",
|
"integrity": "sha512-ACvquP6fI8TdPXfPNNGTTi9v12WW6LS4k2KmmUBSmNncM0KnUwywqTT6YQIfCff6dUMd9DZB1oaNZfEDto+QQw==",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/node-rsa": "^1.1.4",
|
||||||
"@types/readable-stream": "^4.0.0",
|
"@types/readable-stream": "^4.0.0",
|
||||||
"aes-js": "^3.1.2",
|
"aes-js": "^3.1.2",
|
||||||
"buffer-equal": "^1.0.0",
|
"buffer-equal": "^1.0.0",
|
||||||
|
@ -560,12 +571,12 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/prismarine-nbt": {
|
"node_modules/prismarine-nbt": {
|
||||||
"version": "2.6.0",
|
"version": "2.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/prismarine-nbt/-/prismarine-nbt-2.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/prismarine-nbt/-/prismarine-nbt-2.7.0.tgz",
|
||||||
"integrity": "sha512-z65ijm6hVlYOmhg8IEzdYfUz1u3AOiQtzyTSAwD8NLBCr96ZUPtUH5o/6sGAoDaN+rkDe0DNBCiO7bvXXO1fkQ==",
|
"integrity": "sha512-Du9OLQAcCj3y29YtewOJbbV4ARaSUEJiTguw0PPQbPBy83f+eCyDRkyBpnXTi/KPyEpgYCzsjGzElevLpFoYGQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"protodef": "^1.9.0"
|
"protodef": "^1.18.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/prismarine-realms": {
|
"node_modules/prismarine-realms": {
|
||||||
|
@ -598,9 +609,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/protodef": {
|
"node_modules/protodef": {
|
||||||
"version": "1.17.0",
|
"version": "1.18.0",
|
||||||
"resolved": "https://registry.npmjs.org/protodef/-/protodef-1.17.0.tgz",
|
"resolved": "https://registry.npmjs.org/protodef/-/protodef-1.18.0.tgz",
|
||||||
"integrity": "sha512-mnpNPV3xwu63u3NwZuXM1RCp979vjHxUGHzVrb6dxbvof5Fx+b8Rs0G0c3xtEuFDreGAMWS7VrlNkDUDBMsFWQ==",
|
"integrity": "sha512-jO64lkzkh0dYc0AVWCU/GzCKwqhFFIz1kfEz0NBf0RUuRNcmvgKbopabJdfZ6W8NvALdySUXgEhvKDZPhdBwrg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash.get": "^4.4.2",
|
"lodash.get": "^4.4.2",
|
||||||
|
@ -613,9 +624,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/protodef-validator": {
|
"node_modules/protodef-validator": {
|
||||||
"version": "1.3.1",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/protodef-validator/-/protodef-validator-1.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/protodef-validator/-/protodef-validator-1.4.0.tgz",
|
||||||
"integrity": "sha512-lZ5FWKZYR9xOjpMw1+EfZRfCjzNRQWPq+Dk+jki47Sikl2EeWEPnTfnJERwnU/EwFq6us+0zqHHzSsmLeYX+Lg==",
|
"integrity": "sha512-2y2coBolqCEuk5Kc3QwO7ThR+/7TZiOit4FrpAgl+vFMvq8w76nDhh09z08e2NQOdrgPLsN2yzXsvRvtADgUZQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ajv": "^6.5.4"
|
"ajv": "^6.5.4"
|
||||||
|
@ -741,9 +752,9 @@
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/undici-types": {
|
"node_modules/undici-types": {
|
||||||
"version": "6.19.8",
|
"version": "6.20.0",
|
||||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
|
||||||
"integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
|
"integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/uri-js": {
|
"node_modules/uri-js": {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
"author": "7cc5c4f330d47060",
|
"author": "7cc5c4f330d47060",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minecraft-protocol": "^1.49.0"
|
"minecraft-protocol": "^1.51.0",
|
||||||
|
"prismarine-chat": "^1.10.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,32 +23,39 @@ const rl = createInterface({
|
||||||
prompt: '\x1b[0m> '
|
prompt: '\x1b[0m> '
|
||||||
})
|
})
|
||||||
rl.on('line', (l) => {
|
rl.on('line', (l) => {
|
||||||
|
const args = l.split(' ');
|
||||||
|
const cmdName = args[0].toLowerCase();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (cmds[l.split(' ')[0].toLowerCase()]) {
|
const cmd = cmds[cmdName];
|
||||||
if (cmds[l.split(' ')[0].toLowerCase()].consoleIndex) {
|
if (!cmd) {
|
||||||
const tmpcmd = l.split(' ')
|
rl.prompt(false);
|
||||||
const index2 = tmpcmd.splice(1, 1)[0]
|
return;
|
||||||
if (index2 === '*') {
|
}
|
||||||
for (let i = 0; i < bots.length; i++) {
|
|
||||||
const cmd = new Command(uuid, user, nick, tmpcmd.join(' '), 'console', 'console', 'console', '', bots[i])
|
if (cmd.consoleIndex) {
|
||||||
cmd.verify = 2
|
const index2 = args.splice(1, 1)[0];
|
||||||
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
|
if (index2 === '*') {
|
||||||
}
|
for (let i = 0; i < bots.length; i++) {
|
||||||
} else {
|
const context = new Command(uuid, user, nick, args.join(' '), 'console', 'console', 'console', '', bots[i])
|
||||||
const cmd = new Command(uuid, user, nick, tmpcmd.join(' '), 'console', 'console', 'console', '', bots[+index2])
|
context.verify = 2
|
||||||
cmd.verify = 2
|
cmd.execute(context)
|
||||||
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const cmd = new Command(uuid, user, nick, l, 'console', 'console', 'console', '', consoleBotStub)
|
const context = new Command(uuid, user, nick, args.join(' '), 'console', 'console', 'console', '', bots[+index2])
|
||||||
cmd.verify = 2
|
context.verify = 2
|
||||||
cmds[l.split(' ')[0].toLowerCase()].execute(cmd)
|
cmd.execute(context)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const context = new Command(uuid, user, nick, l, 'console', 'console', 'console', '', consoleBotStub)
|
||||||
|
context.verify = 2
|
||||||
|
cmd.execute(context)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
}
|
}
|
||||||
rl.prompt(false)
|
|
||||||
|
rl.prompt(false);
|
||||||
})
|
})
|
||||||
rl.prompt()
|
rl.prompt()
|
||||||
|
|
||||||
|
@ -58,6 +65,7 @@ function consoleWrite (text) {
|
||||||
process.stdout.write(text + '\n')
|
process.stdout.write(text + '\n')
|
||||||
rl.prompt(true)
|
rl.prompt(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function load (b) {
|
export default function load (b) {
|
||||||
b.info = (msg) => {
|
b.info = (msg) => {
|
||||||
consoleWrite(`[${b.id}] [info] ${msg}`)
|
consoleWrite(`[${b.id}] [info] ${msg}`)
|
||||||
|
|
|
@ -15,8 +15,8 @@ export default class Command {
|
||||||
this.colors = settings.colors
|
this.colors = settings.colors
|
||||||
this.lang = settings.defaultLang
|
this.lang = settings.defaultLang
|
||||||
this.verify = 0
|
this.verify = 0
|
||||||
this.host = bot.host.host
|
this.host = bot?.host.host
|
||||||
this.port = bot.host.port
|
this.port = bot?.host.port
|
||||||
this.bot = bot
|
this.bot = bot
|
||||||
|
|
||||||
this.rewriteCommand = newCmd => {
|
this.rewriteCommand = newCmd => {
|
||||||
|
|
|
@ -7,13 +7,12 @@ export default function (cmd, uuid) {
|
||||||
const dateString = _dateString.slice(0, _dateString.length - 4)
|
const dateString = _dateString.slice(0, _dateString.length - 4)
|
||||||
const hashTrusted = `babyboom:${settings.keyTrusted}:${uuid}:${cmdWithoutHash}:${dateString}`
|
const hashTrusted = `babyboom:${settings.keyTrusted}:${uuid}:${cmdWithoutHash}:${dateString}`
|
||||||
const hashOwner = `babyboom:${settings.keyOwner}:${uuid}:${cmdWithoutHash}:${dateString}`
|
const hashOwner = `babyboom:${settings.keyOwner}:${uuid}:${cmdWithoutHash}:${dateString}`
|
||||||
|
|
||||||
|
const hashPart = cmd[cmd.length - 1];
|
||||||
const validhashT = createHash('sha256').update(hashTrusted).digest('hex')
|
const validhashT = createHash('sha256').update(hashTrusted).digest('hex')
|
||||||
const validhashO = createHash('sha256').update(hashOwner).digest('hex')
|
const validhashO = createHash('sha256').update(hashOwner).digest('hex')
|
||||||
if (cmd[cmd.length - 1] === validhashT) {
|
if (hashPart === validhashT) return 1
|
||||||
return 1
|
if (hashPart === validhashO) return 2
|
||||||
}
|
|
||||||
if (cmd[cmd.length - 1] === validhashO) {
|
|
||||||
return 2
|
|
||||||
}
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import MinecraftData from 'minecraft-data'
|
import MinecraftData from 'minecraft-data'
|
||||||
const _lang = MinecraftData('1.20.6').language
|
const _lang = MinecraftData('1.21.1').language
|
||||||
const lang = Object.create(null) // Without constructor function
|
const lang = Object.create(null) // Without constructor function
|
||||||
for (const i in _lang) {
|
for (const i in _lang) {
|
||||||
lang[i] = _lang[i]
|
lang[i] = _lang[i]
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
|
const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
||||||
|
const THRESHOLD = 1000; // KiB = 1024; KB = 1000
|
||||||
|
|
||||||
export default function memoryconvert (bytes) {
|
export default function memoryconvert (bytes) {
|
||||||
if (bytes >= 1125899906842624) { // Petabytes
|
for (let i = 0; i < UNITS.length; i++) {
|
||||||
return `${Math.round(bytes / 1125899906842624 * 100) / 100} PB`
|
const last = i === (UNITS.length - 1);
|
||||||
} else if (bytes >= 1099511627776) { // Terabytes
|
const max = THRESHOLD ** (i + 1);
|
||||||
return `${Math.round(bytes / 1099511627776 * 100) / 100} TB`
|
if (!last && bytes >= max) continue;
|
||||||
} else if (bytes >= 1073741824) { // Gigabytes
|
|
||||||
return `${Math.round(bytes / 1073741824 * 100) / 100} GB`
|
const divisor = THRESHOLD ** i;
|
||||||
} else if (bytes >= 1048576) { // Megabytes
|
const unit = UNITS[i];
|
||||||
return `${Math.round(bytes / 1048576 * 100) / 100} MB`
|
|
||||||
} else if (bytes >= 1024) { // Kilobytes
|
const div = bytes / divisor;
|
||||||
return `${Math.round(bytes / 1024 * 100) / 100} KB`
|
return `${+div.toFixed(2)} ${unit}`
|
||||||
} else { // Bytes
|
|
||||||
return `${bytes} B`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue