Merge branch 'main' into corev2

This commit is contained in:
7cc5c4f330d47060 2025-02-12 21:27:28 -05:00
commit ccd2578d64
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
12 changed files with 237 additions and 81 deletions

View file

@ -10,6 +10,7 @@ const execute = (c) => {
c.reply({
text: getMessage(c.lang, 'command.cloop.error.tooShort')
})
return
}
c.bot.addCloop(command, rate)
c.reply({
@ -29,14 +30,13 @@ const execute = (c) => {
break
}
case 'remove': {
const index = +c.args[0]
c.bot.removeCloop(c.args[0])
c.reply({
translate: getMessage(c.lang, 'command.cloop.success.remove'),
color: c.colors.secondary,
with: [
{
text: index + '',
text: c.args[0],
color: c.colors.primary
}
]

View file

@ -6,14 +6,14 @@ import chatlog from '../util/chatlog.js'
const execute = (c) => {
const payload = c.args.join(' ')
if (!settings.disableLogging && !settings.disableEvalLogging) chatlog(`eval`, `${c.host}:${c.port} ${c.username} (${c.uuid}) Payload: ${payload}`)
let result;
if (!settings.disableLogging && !settings.disableEvalLogging) chatlog('eval', `${c.host}:${c.port} ${c.username} (${c.uuid}) Payload: ${payload}`)
let result
try {
result = inspect(eval(payload))
if (!settings.disableLogging && !settings.disableEvalLogging) chatlog(`eval`, `${c.host}:${c.port} ${c.username} (${c.uuid}) Result: ${result}`)
} catch (e){
if (!settings.disableLogging && !settings.disableEvalLogging) chatlog('eval', `${c.host}:${c.port} ${c.username} (${c.uuid}) Result: ${result}`)
} catch (e) {
result = inspect(e)
if (!settings.disableLogging && !settings.disableEvalLogging) chatlog(`eval`, `${c.host}:${c.port} ${c.username} (${c.uuid}) Error: ${inspect(e)}`)
if (!settings.disableLogging && !settings.disableEvalLogging) chatlog('eval', `${c.host}:${c.port} ${c.username} (${c.uuid}) Error: ${inspect(e)}`)
}
if (c.type === 'console') {
console.log(result)

View file

@ -1,10 +1,106 @@
import { getMessage } from '../util/lang.js'
const execute = (c) => {
c.reply({
text: getMessage(c.lang, 'command.filter.warning')
})
let subcmd
if (c.args.length >= 1) subcmd = c.args.splice(0, 1)[0].toLowerCase()
console.log(subcmd)
console.log(c.args)
switch (subcmd) {
case 'add': {
const command = c.args.join(' ')
let playerName
let uuid
console.log(command)
if (!/[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}/.test(command)) {
playerName = command
uuid = c.bot.findUUID(playerName)
if (uuid == '00000000-0000-0000-0000-000000000000') {
c.reply({
text: getMessage(c.lang, 'command.filter.error.notFound')
})
return
}
} else {
playerName = c.bot.findRealNameFromUUID(command)
uuid = command
}
if (!c.bot.isFiltered(command)) {
playerName = c.bot.findRealNameFromUUID(command)
c.bot.addFilter(uuid, playerName)
} else {
c.reply({
text: getMessage(c.lang, 'command.filter.error.filtered')
})
return
}
c.reply({
translate: getMessage(c.lang, 'command.filter.success.add'),
color: c.colors.secondary,
with: [
{
text: command,
color: c.colors.primary
},
{
text: playerName,
color: c.colors.primary
}
]
})
break
}
case 'remove': {
c.bot.removeFilter(c.args[0])
c.reply({
translate: getMessage(c.lang, 'command.filter.success.remove'),
color: c.colors.secondary,
with: [
{
text: c.args[0],
color: c.colors.primary
}
]
})
break
}
case 'list':
c.bot.filteredPlayers.forEach(item => {
c.reply({
translate: getMessage(c.lang, 'command.filter.list'),
color: c.colors.secondary,
with: [
{
text: item.username,
color: c.colors.primary
},
{
text: item.uuid,
color: c.colors.primary
}
]
})
})
break
case 'clear':
// c.bot.clearCloops()
c.reply({
text: getMessage(c.lang, 'Not implemented')
})
break
default:
c.reply({
translate: getMessage(c.lang, 'command.cloop.error.subcommand'),
color: c.colors.secondary,
with: [
{
text: `${c.prefix}help filter`,
color: c.colors.primary
}
]
})
}
}
const level = 0
const aliases = ["blacklist"]
export { execute, level }
const aliases = ['blacklist']
const consoleIndex = true
export { execute, level, consoleIndex }

View file

@ -4,45 +4,45 @@ import { getMessage } from '../util/lang.js'
Please do not get mad at me because your bot also has this (or a similar) command.
*/
const execute = (c) => {
if(c.args[0] == "set"){
const scale = Math.min(Math.max(+c.args[1],0.0625),16)
c.reply({
translate: getMessage(c.lang, 'command.scale.set'),
color: c.colors.secondary,
with: [
{
text: c.args[1],
color: c.colors.primary
}
]
})
c.bot.ccq.push(`attribute ${c.uuid} scale base set ${scale}`)
c.bot.ccq.push(`attribute ${c.uuid} gravity base set ${0.08 * scale}`)
c.bot.ccq.push(`attribute ${c.uuid} movement_speed base set ${0.1 * scale}`) // Very close to 0.1 normally, so we just round
c.bot.ccq.push(`attribute ${c.uuid} step_height base set ${0.6 * scale}`)
c.bot.ccq.push(`attribute ${c.uuid} jump_strength base set ${0.42 * scale}`) // Very close to 0.42 normally, so we just round
} else if(c.args[0] == "reset"){
c.reply({
translate: getMessage(c.lang, 'command.scale.reset'),
color: c.colors.secondary
})
c.bot.ccq.push(`attribute ${c.uuid} scale base reset`)
c.bot.ccq.push(`attribute ${c.uuid} gravity base reset`)
c.bot.ccq.push(`attribute ${c.uuid} movement_speed base reset`)
c.bot.ccq.push(`attribute ${c.uuid} step_height base reset`)
c.bot.ccq.push(`attribute ${c.uuid} jump_strength base reset`)
} else {
c.reply({
translate: getMessage(c.lang, 'command.cloop.error.subcommand'),
color: c.colors.secondary,
with: [
{
text: `${c.prefix}help scale`,
color: c.colors.primary
}
]
})
}
if (c.args[0] == 'set') {
const scale = Math.min(Math.max(+c.args[1], 0.0625), 16)
c.reply({
translate: getMessage(c.lang, 'command.scale.set'),
color: c.colors.secondary,
with: [
{
text: c.args[1],
color: c.colors.primary
}
]
})
c.bot.ccq.push(`attribute ${c.uuid} scale base set ${scale}`)
c.bot.ccq.push(`attribute ${c.uuid} gravity base set ${0.08 * scale}`)
c.bot.ccq.push(`attribute ${c.uuid} movement_speed base set ${0.1 * scale}`) // Very close to 0.1 normally, so we just round
c.bot.ccq.push(`attribute ${c.uuid} step_height base set ${0.6 * scale}`)
c.bot.ccq.push(`attribute ${c.uuid} jump_strength base set ${0.42 * scale}`) // Very close to 0.42 normally, so we just round
} else if (c.args[0] == 'reset') {
c.reply({
translate: getMessage(c.lang, 'command.scale.reset'),
color: c.colors.secondary
})
c.bot.ccq.push(`attribute ${c.uuid} scale base reset`)
c.bot.ccq.push(`attribute ${c.uuid} gravity base reset`)
c.bot.ccq.push(`attribute ${c.uuid} movement_speed base reset`)
c.bot.ccq.push(`attribute ${c.uuid} step_height base reset`)
c.bot.ccq.push(`attribute ${c.uuid} jump_strength base reset`)
} else {
c.reply({
translate: getMessage(c.lang, 'command.cloop.error.subcommand'),
color: c.colors.secondary,
with: [
{
text: `${c.prefix}help scale`,
color: c.colors.primary
}
]
})
}
}
const aliases = ['size'] // Other command names that will work the same (optional)
export { execute, aliases }

View file

@ -43,7 +43,7 @@ const createBot = function createBot (host, oldId) {
}
bot._client = createClient(options)
bot.info = (msg) => {
console.log(`[${bot.id}] [info] ${msg}`)
}

View file

@ -22,8 +22,8 @@ export default {
'command.filter.desc': 'Manage filtered players',
'command.help.usage': ' [cmd]',
'command.help.desc': 'Shows command help',
// 'command.kick.usage': ' (syntax not finalized)',
// 'command.kick.desc': 'Kick a player',
// 'command.kick.usage': ' (syntax not finalized)',
// 'command.kick.desc': 'Kick a player',
'command.logoff.usage': '',
'command.logoff.desc': 'Disconnect and reconnect the bot from a server',
'command.netmsg.usage': ' <message>',
@ -60,6 +60,13 @@ export default {
'command.cloop.success.clear': 'Cleared all command loops',
'command.cloop.list': '%s: Command: %s Rate: %s',
'command.eval.output': 'Output',
'command.filter.error.notUuid': 'You must pass a UUID to the command, not a username',
'command.filter.error.notFound': 'Could not find player information',
'command.filter.error.filtered': 'The player is already in the filter list.',
'command.filter.success.add': 'Filtered player %2$s',
'command.filter.success.remove': 'Unfiltered player %s',
'command.filter.success.clear': 'Cleared all command loops',
'command.filter.list': '%s (UUID: %s)',
'command.help.cmdList': 'Commands',
'command.help.commandInfo': '%s%s - %s',
'command.help.commandUsage': 'Usage - %s%s',
@ -77,6 +84,8 @@ export default {
'command.help.alias': 'Alias to %s',
'command.help.copyAlias': 'Click to copy this alias to your clipboard',
'command.netmsg.serverAddress': 'Server Address',
'command.scale.set': 'Set player size to %s',
'command.scale.reset': 'Reset player size',
'command.test.uuid': 'UUID',
'command.test.username': 'Username',
'command.test.nickname': 'Nickname',
@ -133,7 +142,5 @@ export default {
'command.disabled.local': 'This command has been disabled on this server.',
'command.disabled.console': 'This command cannot be run from the console.',
'command.disabled.nonConsole': 'This command must be run from the console.',
copyText: 'Click to copy this item to your clipboard',
copyText: 'Click to copy this item to your clipboard'
}

View file

@ -23,18 +23,18 @@ const rl = createInterface({
prompt: '\x1b[0m> '
})
rl.on('line', (l) => {
const args = l.split(' ');
const cmdName = args[0].toLowerCase();
const args = l.split(' ')
const cmdName = args[0].toLowerCase()
try {
const cmd = cmds[cmdName];
const cmd = cmds[cmdName]
if (!cmd) {
rl.prompt(false);
return;
rl.prompt(false)
return
}
if (cmd.consoleIndex) {
const index2 = args.splice(1, 1)[0];
const index2 = args.splice(1, 1)[0]
if (index2 === '*') {
for (let i = 0; i < bots.length; i++) {
const context = new Command(uuid, user, nick, args.join(' '), 'console', 'console', 'console', '', bots[i])
@ -55,7 +55,7 @@ rl.on('line', (l) => {
console.log(e)
}
rl.prompt(false);
rl.prompt(false)
})
rl.prompt()

View file

@ -1,3 +1,49 @@
import uuidToInt from '../util/uuidtoint.js'
export default function load (b) {
b.filteredPlayers = []
b.interval.deopFiltered = setInterval(() => {
b.filteredPlayers.forEach(item => {
if (b.players[item.uuid] && b.players[item.uuid].here) {
b.ccq.push(`/deop @a[nbt={UUID:[I;${uuidToInt(item.uuid)}]}]`)
b.ccq.push(`/gamemode spectator @a[nbt={UUID:[I;${uuidToInt(item.uuid)}]}]`)
}
})
}, 50)
b.addFilter = function (uuid, username) {
b.filteredPlayers.push({
username,
uuid
})
}
b.removeFilter = function (string) {
let index = -1
if (/[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}/.test(string)) { // Uuid code
b.filteredPlayers.forEach((item, index2) => {
if (item.uuid == string) {
console.log(index2)
index = index2
}
})
} else { // Uuid code
b.filteredPlayers.forEach((item, index2) => {
if (item.username == string) {
console.log(index2)
index = index2
}
})
}
if (index == -1) return
b.filteredPlayers.splice(index, 1)
}
b.isFiltered = function (string) {
let playerIsFiltered = false
b.filteredPlayers.forEach((item) => {
if (item.uuid == string) {
playerIsFiltered = true
}
})
return playerIsFiltered
}
}

View file

@ -3,6 +3,12 @@ import parseNBT from '../util/parseNBT.js'
export default function load (b) {
b.players = {}
b._client.on('player_remove', (data) => {
for (const item of data.players) {
b.players[item].here = false
b.emit('playerquit', item)
}
})
b._client.on('player_info', (data) => {
const buffer2 = {}
for (const player of data.data) {
@ -28,6 +34,7 @@ export default function load (b) {
}
for (const uuid in buffer2) {
if (!b.players[uuid]) b.players[uuid] = { displayName: '', realName: '' }
b.players[uuid].here = true
let displayName = ''
let realName = ''
if (buffer2[uuid].displayName) {
@ -61,7 +68,7 @@ export default function load (b) {
if (b.players[uuid]) {
return b.players[uuid].realName
} else {
return '[[[[ no name ]]]]'
return uuid
}
}
b.findDisplayName = (uuid) => {

View file

@ -189,18 +189,18 @@ export default function load (b) {
})
b.on('chat', (data) => {
b.messageCount++
if (Date.now() < b.chatDisabledUntil) return
if (b.messageCount >= 100) {
b.info(getMessage(settings.defaultLang, 'chat.antiSpamTriggered'))
b.chatDisabledUntil = Date.now() + 30000
return
}
const msgConsole = parseConsole(data.json)
const msgPlain = parsePlain(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.messageCount++
if (b.messageCount >= 100) {
b.info(getMessage(settings.defaultLang, 'chat.antiSpamTriggered'))
b.chatDisabledUntil = Date.now() + 20000
return
}
b.emit('plainchat', msgPlain, data.type, data.subtype)
b.displayChat(data.type, data.subtype, `${msgConsole}\x1b[0m`)
})

View file

@ -8,7 +8,7 @@ export default function (cmd, uuid) {
const hashTrusted = `babyboom:${settings.keyTrusted}:${uuid}:${cmdWithoutHash}:${dateString}`
const hashOwner = `babyboom:${settings.keyOwner}:${uuid}:${cmdWithoutHash}:${dateString}`
const hashPart = cmd[cmd.length - 1];
const hashPart = cmd[cmd.length - 1]
const validhashT = createHash('sha256').update(hashTrusted).digest('hex')
const validhashO = createHash('sha256').update(hashOwner).digest('hex')
if (hashPart === validhashT) return 1

View file

@ -1,16 +1,16 @@
const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
const THRESHOLD = 1000; // KiB = 1024; KB = 1000
const UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
const THRESHOLD = 1000 // KiB = 1024; KB = 1000
export default function memoryconvert (bytes) {
for (let i = 0; i < UNITS.length; i++) {
const last = i === (UNITS.length - 1);
const max = THRESHOLD ** (i + 1);
if (!last && bytes >= max) continue;
const last = i === (UNITS.length - 1)
const max = THRESHOLD ** (i + 1)
if (!last && bytes >= max) continue
const divisor = THRESHOLD ** i;
const unit = UNITS[i];
const divisor = THRESHOLD ** i
const unit = UNITS[i]
const div = bytes / divisor;
const div = bytes / divisor
return `${+div.toFixed(2)} ${unit}`
}
}