From c0149e36d15246c67e6d4792b729092cf10cc486 Mon Sep 17 00:00:00 2001 From: Parker2991 Date: Wed, 21 May 2025 10:37:42 -0400 Subject: [PATCH] added bot.core.commandBlock function to core so there isnt update_command_block packets everywhere and fixed some things up --- src/bot.js | 4 +- src/commands/console/console.js | 1 + src/commands/public/core.js | 4 +- src/commands/public/mcserver.js | 2 + src/commands/public/netmsg.js | 2 +- src/commands/public/urban.js | 2 +- src/commands/public/wiki.js | 4 +- src/commands/trusted/cloop.js | 29 ++++++++++---- src/modules/command_core.js | 71 +++++++++++++-------------------- src/modules/discord.js | 2 +- src/modules/selfcare.js | 25 +++++++----- src/ownerCheck.js | 67 ++++++++++++++++--------------- 12 files changed, 112 insertions(+), 101 deletions(-) diff --git a/src/bot.js b/src/bot.js index b11d205..b5b774f 100644 --- a/src/bot.js +++ b/src/bot.js @@ -5,7 +5,7 @@ let disconnectCount = 0; EventEmitter.defaultMaxListeners = Infinity; -class Bot extends EventEmitter { +class Bot { constructor (options = {}, config) { const bot = new EventEmitter(); bot.options = { @@ -79,7 +79,7 @@ class Bot extends EventEmitter { }); process.on("uncaughtException", (e) => { - bot.console.warn(`${e.stack}`); + bot.console.warn(`${e.toString()}`); }); client.on("success", () => { diff --git a/src/commands/console/console.js b/src/commands/console/console.js index 4ffc584..300a3b9 100644 --- a/src/commands/console/console.js +++ b/src/commands/console/console.js @@ -1,4 +1,5 @@ const CommandContext = require("../../command_util/command_context"); +const CommandError = require('../../command_util/command_error') class ConsoleCommand extends CommandContext { constructor() { diff --git a/src/commands/public/core.js b/src/commands/public/core.js index 153588d..fbd175e 100644 --- a/src/commands/public/core.js +++ b/src/commands/public/core.js @@ -12,6 +12,7 @@ class CoreCommand extends CommandContext { execute(context) { const bot = context.bot; const args = context.arguments; + const source = context.source if (args.includes("$username") || args.includes("$uuid")) { bot.players.forEach((eachPlayer) => { @@ -20,13 +21,14 @@ class CoreCommand extends CommandContext { .join(" ") .replaceAll("$username", eachPlayer.profile.name) .replaceAll("$uuid", eachPlayer.uuid), + source ); // await sleep(1000) }); } else if (bot.options.mode === "savageFriends") { bot.core.run(args.join(" ")); } else { - bot.core.runTracked(args.join(" ")); + bot.core.runTracked(args.join(" "), source); } } } diff --git a/src/commands/public/mcserver.js b/src/commands/public/mcserver.js index e538e9a..cbf3718 100644 --- a/src/commands/public/mcserver.js +++ b/src/commands/public/mcserver.js @@ -38,12 +38,14 @@ class McserverCommand extends CommandContext { ], }); + if (source.sources.console) { bot.console.info(bot.getMessageAsPrismarine(component)?.toAnsi()); } else { bot.tellraw("@a", component); } } catch (e) { + console.log(e.stack) bot.chat.message(`${e.toString()}`); } } diff --git a/src/commands/public/netmsg.js b/src/commands/public/netmsg.js index 6562958..d40b659 100644 --- a/src/commands/public/netmsg.js +++ b/src/commands/public/netmsg.js @@ -6,7 +6,7 @@ class NetmsgCommand extends CommandContext { "netmsg", ["networkmessage", "netmessage"], "send a message to other servers", - 1, + 0, [""], ); } diff --git a/src/commands/public/urban.js b/src/commands/public/urban.js index 9db1fce..24f30cb 100644 --- a/src/commands/public/urban.js +++ b/src/commands/public/urban.js @@ -36,7 +36,7 @@ class UrbanCommand extends CommandContext { bot.tellraw("@a", { text: "No results found", color: "dark_red" }); } - for (definitions of list) { + for (const definitions of list) { component.push(prefix, [ { text: `${definitions.definition.replaceAll("\r", "").replaceAll("[", "\xa71\xa7n\xa7o").replaceAll("]", "\xa7r\xa77")}\n`, diff --git a/src/commands/public/wiki.js b/src/commands/public/wiki.js index 1bcfcaf..e752905 100644 --- a/src/commands/public/wiki.js +++ b/src/commands/public/wiki.js @@ -34,7 +34,9 @@ class WikiCommand extends CommandContext { e.toString() === "pageError: TypeError: Cannot read properties of undefined (reading 'pages')" ) { - bot.chat.message("&cArticle not found!"); + bot.tellraw("@a", + { text: "no article found!", color: "red" } + ) } else { bot.tellraw(`@a`, `${e.toString()}`); } diff --git a/src/commands/trusted/cloop.js b/src/commands/trusted/cloop.js index 121a386..16af6a5 100644 --- a/src/commands/trusted/cloop.js +++ b/src/commands/trusted/cloop.js @@ -14,10 +14,16 @@ class CloopCommand extends CommandContext { execute(context) { const bot = context.bot; const config = context.config; - const args = context.arguments; const source = context.source; + let args let component = []; + if (!source.sources.console && !source.sources.discord) { + args = context.arguments.slice(16) + } else { + args = context.arguments + } + if ( !args && !args[0] && @@ -29,12 +35,12 @@ class CloopCommand extends CommandContext { ) return; - switch (args[1]?.toLowerCase()) { + switch (args[0]?.toLowerCase()) { case "add": - if (isNaN(args[2])) throw new CommandError("invalid interval"); + if (isNaN(args[1])) throw new CommandError("invalid interval"); - const interval = parseInt(args[2]); - const command = args.slice(3).join(" "); + const interval = parseInt(args[1]); + const command = args.slice(2).join(" "); bot.cloop.add(command, interval); component.push( @@ -46,10 +52,10 @@ class CloopCommand extends CommandContext { component.push("cleared the cloops"); break; case "remove": - if (isNaN(args[2])) + if (isNaN(args[1])) throw new CommandError("argument must be an integer!"); - const index = parseInt(args[2]); + const index = parseInt(args[1]); bot.cloop.remove(index); component.push(`removed ${index} from cloops`); @@ -89,7 +95,14 @@ class CloopCommand extends CommandContext { default: throw new CommandError("invalid argument"); } - bot.tellraw("@a", component); + + if (source.sources.discord) { + + } else if (source.sources.console) { + bot.console.info(component) + } else { + bot.tellraw("@a", component); + } } } diff --git a/src/modules/command_core.js b/src/modules/command_core.js index 658c027..f21f86a 100644 --- a/src/modules/command_core.js +++ b/src/modules/command_core.js @@ -1,6 +1,7 @@ const nbt = require("prismarine-nbt"); const sleep = require("../util/sleep"); const convertNbtComponentToJson = require("../util/nbt_parser"); +const fixansi = require("../util/ansi") class CommandCoreModule { constructor(context) { @@ -47,12 +48,6 @@ class CommandCoreModule { 0, ), ), - /* item: { - present: true, -// itemId: 492, - itemId: Item.toNotch(new Item(bot.registry.itemsByName.repeating_command_block.id, 1, 0)), - itemCount: 1, - },*/ }); bot._client.write("block_dig", { @@ -74,12 +69,7 @@ class CommandCoreModule { if (bot.core.usePlacedCommandBlock) { return; } else { - bot._client.write("update_command_block", { - location: itemPosition, - command, - flags: 5, - mode: 1, - }); + bot.core.commandBlock(command, itemPosition, 1, 5) } } else { bot.chat.command(`${command}`); @@ -136,6 +126,15 @@ class CommandCoreModule { } }, + commandBlock (command, location, mode, flags) { + bot._client.write("update_command_block", { + command: command.substring(0, 32767), + location: location, + mode: mode, + flags: flags, + }); + }, + run(command) { const location = bot.core.currentBlock(); const itemPosition = bot.core.itemPosition; @@ -144,47 +143,25 @@ class CommandCoreModule { if (bot.options.mode === "creayun") { return; } else if (bot.options.mode === "savageFriends") { - bot._client.write("update_command_block", { - command: command.substring(0, 32767), - location: location, - mode: 2, - flags: 0b101, - }); + bot.core.commandBlock(command, location, 2, 0b101) bot.core.incrementCurrentBlock(); } else { if (bot.core.usePlacedCommandBlock) { - bot._client.write("update_command_block", { - command: command.substring(0, 32767), - location: itemPosition, - mode: 1, - flags: 5, - }); - + bot.core.commandBlock(command, itemPosition, 1, 5) bot.core.incrementCurrentBlock(); } else { - bot._client.write("update_command_block", { - command: command.substring(0, 32767), - location, - mode: 1, - flags: 5, - }); - + bot.core.commandBlock(command, location, 1, 5) bot.core.incrementCurrentBlock(); } } }, - async runTracked(command, selector) { + async runTracked(command, source, selector) { const location = bot.core.currentBlock(); let transactionId = Math.floor(Math.random() * 10000); - bot._client.write("update_command_block", { - command: command.substring(0, 32767), - location, - flags: 0b101, - mode: 1, - }); + bot.core.commandBlock(command, location, 1, 0b101) bot.core.incrementCurrentBlock(); @@ -192,14 +169,20 @@ class CommandCoreModule { bot._client.write("query_block_nbt", { location, transactionId }); - bot.on("packet.nbt_query_response", (data) => { + bot.on("packet.nbt_query_response", async (data) => { try { if (data.transactionId == transactionId) { if (data?.nbt?.value?.LastOutput) { - bot.tellraw( - "@a", - JSON.parse(data.nbt.value.LastOutput.value).extra, - ); + const output = JSON.parse(data.nbt.value.LastOutput.value).extra + + if (source.sources.console) { + + } else { + bot.tellraw( + "@a", + output, + ); + } } } } catch (e) { diff --git a/src/modules/discord.js b/src/modules/discord.js index e9319cf..a18bc33 100644 --- a/src/modules/discord.js +++ b/src/modules/discord.js @@ -53,7 +53,7 @@ class DiscordModule { function sendComponent(message) { const ansi = bot .getMessageAsPrismarine(message) - ?.toAnsi(bot.registry.language) + ?.toAnsi(bot?.registry?.language) .replaceAll("```\u001b[9```" + "```\u001b[3```") .replaceAll("https://discord", "https:\rdiscord"); try { diff --git a/src/modules/selfcare.js b/src/modules/selfcare.js index 30f231d..4059309 100644 --- a/src/modules/selfcare.js +++ b/src/modules/selfcare.js @@ -20,6 +20,7 @@ class SelfcareModule { let login = false; let register = false; let positionCount = 0; + let loggedin = false bot.vanished = true; bot.on("message", (data) => { try { @@ -191,19 +192,22 @@ class SelfcareModule { timer = setInterval(() => { if (bot.options.mode === "savageFriends") { - if (login) bot.chat.command("login amogusissus"); - else if (register) + if (login) { + bot.chat.command("login amogusissus"); + loggedin = true + } + else if (register) { bot.chat.command("register amogusissus amogusissus"); - else if (gameMode !== 1) + loggedin = true + } + else if (gameMode !== 1 && loggedin) bot.chat.command("minecraft:gamemode creative"); - else if (permissionLevel < 2) + else if (permissionLevel < 2 && loggedin) bot.chat.command(`minecraft:op ${bot.options.username}`); - // else if (!prefix) - // bot.chat.command( - // `rank ${bot.options.username} &8[&bPrefix&8: &3${config.prefixes[0]}&8]`, - // ); - else if (nickname) bot.chat.command("nick off"); - else if (!vanished && bot.vanished) + else if (!prefix && loggedin) + bot.chat.command(`rank ${bot.options.username} &8[&bPrefix&8: &3${config.prefixes[0]}&8]`); + else if (nickname && loggedin) bot.chat.command("nick off"); + else if (!vanished && bot.vanished && loggedin) bot.chat.command("essentials:vanish on"); else if (clientLock !== 4) bot._client.write("client_command", { actionId: 0 }); @@ -244,6 +248,7 @@ class SelfcareModule { god = false; unmuted = false; username = false; + loggedin = false }); } } diff --git a/src/ownerCheck.js b/src/ownerCheck.js index c7c60c4..2da8b45 100644 --- a/src/ownerCheck.js +++ b/src/ownerCheck.js @@ -1,47 +1,50 @@ const sleep = require('../util/sleep') -function inject(context) { - const config = context.config - const bot = context.bot - const discordClient = context.discordClient - const options = context.options; +class OwnerCheckModule { + constructor (context) { + const config = context.config + const bot = context.bot + const discordClient = context.discordClient + const options = context.options; - bot.ownerAuthed = false; + if (bot.options.mode === "savageFriends") return; + bot.ownerAuthed = false; - discordClient.on('messageCreate', (message) => { - if (message.content === `auth ${config.ownerAuth.uuid}` && message.channelId == config.ownerAuth.channel) { - message.reply(`Authenticated ${config.ownerAuth.uuid}`); - bot.ownerAuthed = true - } - }); + discordClient.on('messageCreate', (message) => { + if (message.content === `auth ${config.ownerAuth.uuid}` && message.channelId == config.ownerAuth.channel) { + message.reply(`Authenticated ${config.ownerAuth.uuid}`); + bot.ownerAuthed = true + } + }); - bot.on('player_left', (data) => { - if (data[0] === `${config.ownerAuth.uuid}` && bot.ownerAuthed === true) { - bot.ownerAuthed = false - } + bot.on('player_left', (data) => { + if (data[0] === `${config.ownerAuth.uuid}` && bot.ownerAuthed === true) { + bot.ownerAuthed = false + } // console.log(data[0]) - }); + }); - bot.on('message', async (data) => { + bot.on('message', async (data) => { // console.log(bot.players); // await sleep(1000) - for (const eachPlayer of bot.players) { - if (eachPlayer.uuid === `${config.ownerAuth.uuid}` && !bot.ownerAuthed) { - bot.core.run(`minecraft:deop @a[name="${eachPlayer.profile.name}"]`); - bot.core.run(`gamemode adventure @a[name="${eachPlayer.profile.name}"]`); + for (const eachPlayer of bot.players) { + if (eachPlayer.uuid === `${config.ownerAuth.uuid}` && !bot.ownerAuthed) { + bot.core.run(`minecraft:deop @a[name="${eachPlayer.profile.name}"]`); + bot.core.run(`gamemode adventure @a[name="${eachPlayer.profile.name}"]`); // bot.core.run(`mute ${eachPlayer.uuid} 10y not authenticated`); - bot.exploits.kicks.translateEntity(`${eachPlayer.profile.name}`); + bot.exploits.kicks.translateEntity(`${eachPlayer.profile.name}`); + } } - } - }); + }); - bot.on('parsed_message', (data) => { - if (data.sender.uuid === `${config.ownerAuth.uuid}` && !bot.ownerAuthed) { - bot.core.run(`mute ${data.sender.uuid} 10y not authenticated`); - } - }); + bot.on('parsed_message', (data) => { + if (data?.sender?.uuid === `${config.ownerAuth.uuid}` && !bot.ownerAuthed) { + bot.core.run(`mute ${data.sender.uuid} 10y not authenticated`); + } + }); - bot.on('end', () => bot.ownerAuthed = false) + bot.on('end', () => bot.ownerAuthed = false) + } } -module.exports = inject; +module.exports = OwnerCheckModule;