diff --git a/.gitignore b/.gitignore index 1ea43e0..755fbf6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,4 @@ node_modules -config.yml +config.js .git src/modules/exploits.js -logs -src/modules/custom_chat.js -src/util/core_util.js -src/data/filter.json diff --git a/README.md b/README.md index c14fd87..8b77ad0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ # FNFBoyfriendBot -some things were git ignored from the repo that are needed for some things to work so you gotta recreate them \ No newline at end of file +some things were git ignored from the repo that are needed for some things to work so you gotta recreate them + + +FNFBoyfriendBot is a minecraft java bot made for the server kaboom.pw + +# Setup: + 1. make sure to have nodejs npm and git installed + + 2. run npm i + + 3. fix some modules and stuff + + 4. edit the config + + 5. node src diff --git a/src/bot.js b/src/bot.js index 7c8363f..7bb288a 100644 --- a/src/bot.js +++ b/src/bot.js @@ -1,10 +1,8 @@ const mc = require('minecraft-protocol'); const { EventEmitter } = require('events'); -EventEmitter.defaultMaxListeners = 5e6; -const util = require('util'); -const ChatMessage = require('prismarine-chat'); +EventEmitter.defaultMaxListeners = 200; + function createBot(options = {}, config) { - let endCount = 0; const bot = new EventEmitter(); bot.options = { // Set some default values in options @@ -26,46 +24,26 @@ function createBot(options = {}, config) { }) client.on('disconnect', data => { - bot.emit("disconnect", data); - bot.console.warn(`${ChatMessage(bot._client.version).fromNotch("§8[§bClient Reconnect§8]§r")?.toAnsi()} ${ChatMessage(bot._client.version).fromNotch(data.reason)?.toAnsi()}`) + bot.emit("clientDisconnect", data.reason); }) client.on('end', reason => { bot.emit('end', reason); - if (reason === "socketClosed") return; - bot.console.warn(ChatMessage(bot._client.version).fromNotch(`§8[§bClient Reconnect§8]§r ${reason}`)?.toAnsi()); }) client.on('error', error => { - endCount++ - if (endCount === 10) { - bot.console.info('stopped logging disconnect messages for now...'); - bot?.discord?.channel?.send('stopped logging disconnect messages for now...'); - return; - } else if (endCount > 10) { - return; - } else { - bot.console.warn(ChatMessage(bot._client.version).fromNotch('§8[§bClient Reconnect§8]§r ')?.toAnsi() + util.inspect(error.toString())) - bot?.discord?.channel?.send(error.toString()); - } + bot.emit('clientDisconnect', error.toString()); }) client.on("keep_alive", ({ keepAliveId }) => { - bot.emit("keep_alive", { keepAliveId }) }) client.on('kick_disconnect', (data) => { - bot.emit("kick_disconnect", data.reason) - bot.console?.warn(`${ChatMessage(bot._client.version).fromNotch("§8[§bClient Reconnect§8]§r")?.toAnsi()} ${ChatMessage(bot._client.version).fromNotch(data.reason)?.toAnsi()}`) - bot?.discord?.channel?.send(util.inspect(data.reason)) - }) - - client.on('success', (data) => { - endCount = 0; + bot.emit("clientDisconnect", data.reason) }) process.on("uncaughtException", (e) => { -// console?.warn(e.stack) + }); }) diff --git a/src/commands/admin/filter.js b/src/commands/admin/filter.js deleted file mode 100644 index b180555..0000000 --- a/src/commands/admin/filter.js +++ /dev/null @@ -1,155 +0,0 @@ -const CommandError = require('../../util/command_error'); - -module.exports = { - data: { - name: 'filter', - trustLevel: 2, - aliases: [ - "blacklist", - ], - description: 'filter players', - usages: [ - "add ", - "list", - "-ignorecase add / -regex add ", - "-regex add ", - "clear", - "remove ", - ], - }, - execute (context) { - const bot = context.bot; - const args = context.arguments; - const config = context.config; - let component = []; - - if (!args && !args[0] && !args[1] && !args[2] && !args[3] && !args[4] && !args[5] && !args[6]) return; - - switch (args[1]) { - case "add": - if (bot.filter.list().find((e) => e.name === args[2])) throw new CommandError('this player is already in the filter!'); - bot.filter.add(`${args[2]}`, false, false); - bot.chat.message(`added ${args[2]} to the filter`); - break; - case "list": - if (bot.filter.list().length === 0) { - component.push({ - translate: "%s: (%s)", - color: config.colors.commands.tertiary, - with: [ - { text: "Filtered", color: config.colors.commands.primary }, - { text: `${bot.filter.list().length}`, color: config.colors.integer } - ] - }); - } else { - let index = 0; - let filterList = []; - - for (const players of bot.filter.list()) { - - if (players.regex) { - if (players.ignorecase) { - filterList.push({ - translate: "%s: %s (%s %s)", - color: config.colors.commands.tertiary, - with: [ - { text: `${index}`, color: config.colors.integer }, - { text: `${players.name}`, color: config.colors.commands.primary }, - { text: "regexed", color: config.colors.commands.primary }, - { text: "ignorecased", color: config.colors.commands.primary }, - ] - }); - } else { - filterList.push({ - translate: "%s: %s (%s)", - color: config.colors.commands.tertiary, - with: [ - { text: `${index}`, color: config.colors.integer }, - { text: `${players.name}`, color: config.colors.commands.primary }, - { text: "regexed", color: config.colors.commands.primary }, - ] - }); - } - } else if (players.ignorecase) { - filterList.push({ - translate: "%s: %s (%s)", - color: config.colors.commands.tertiary, - with: [ - { text: `${index}`, color: config.colors.integer }, - { text: `${players.name}`, color: config.colors.commands.primary }, - { text: "ignorecase", color: config.colors.commands.primary }, - ] - }); - } else { - filterList.push({ - translate: "%s: %s", - color: config.colors.commands.tertiary, - with: [ - { text: `${index}`, color: config.colors.integer }, - { text: `${players.name}`, color: config.colors.commands.primary } - ] - }); - } - filterList.push('\n'); - index++; - } - - filterList.pop(); - - component.push({ - translate: "%s: (%s)", - color: config.colors.commands.tertiary, - with: [ - { text: "Players", color: config.colors.commands.primary }, - { text: `${bot.filter.list().length}`, color: config.colors.integer } - ] - }); - - component.push('\n'); - component.push(filterList); - - } - - bot.tellraw("@a", component); - break; - case "remove": - bot.filter.remove(args[2]); - bot.chat.message(`removed the index ${args[2]} from the filter`); - break; - case "-ignorecase": - switch (args[2]) { - case "-regex": - switch (args[3]) { - case "add": - if (bot.filter.list().find((e) => e.name === args[4])) throw new CommandError('this player is already in the filter!'); - bot.filter.add(`${args[4]}`, true, true); - bot.chat.message(`added ${args[4]} to the filter`); - break; - } - break; - case "add": - if (bot.filter.list().find((e) => e.name === args[3])) throw new CommandError('this player is already in the filter!'); - - bot.filter.add(`${args[3]}`, true, false); - bot.chat.message(`added ${args[3]} to the filter`); - break; - } - break; - case "-regex": - switch (args[2]) { - case "add": - if (bot.filter.list().find((e) => e.name === args[3])) throw new CommandError('this player is already in the filter!'); - bot.filter.add(`${args[3]}`, false, true); - bot.chat.message(`added ${args[3]} to the filter`); - break; - } - break; - case "clear": - bot.filter.clear(); - bot.chat.message('cleared the filter'); - break; - default: - throw new CommandError('invalid argument'); - } - }, -} diff --git a/src/commands/console/console.js b/src/commands/console/console.js index 44bee1d..b210b9b 100644 --- a/src/commands/console/console.js +++ b/src/commands/console/console.js @@ -1,3 +1,5 @@ +const CommandError = require('../../util/command_error'); + module.exports = { data: { name: 'console', @@ -38,27 +40,8 @@ module.exports = { eachBot.console.server = server; } break - case 'customchat': - if (args[1] === 'off' || args[1] === 'false' || args[1] === 'disable') { - bot.customChat.enabled = false - bot.console.info('Custom Chat disabled'); - } if (args[1] === 'on' || args[1] === 'true' || args[1] === 'enable') { - bot.customChat.enabled = true; - bot.console.info('Custom Chat enabled'); - } - break case 'say': - if (bot.customChat.enabled === false) { - bot.chat.send(args.slice(1).join(' ')) -// bot.commandManager.executeString(bot.console.source, `echo ${args.slice(1).join(' ')}`) - } else if (bot.customChat.enabled === true) { - if (args.slice(1).join(' ').startsWith('/')) { - bot.chat.command(`${args.slice(1).join(' ').substring(1)}`) - return; - } - bot.customChat.chat(args.slice(1).join(' ')); - } - + bot.chat.send(args.slice(1).join(' ')); break case "validate": case "validation": @@ -66,30 +49,18 @@ module.exports = { switch (args[1]?.toLowerCase()) { case "owner": case "o": - if (bot.customChat.enabled === true) { - bot.customChat.chat(`${config.prefixes[0]}${args.slice(2).shift()} ${bot.validation.owner} ${args.slice(3).join(' ')}`) - } else if (bot.customChat.enabled === false) { - bot.chat.message(`${config.prefixes[0]}${args.slice(2).shift()} ${bot.validation.owner} ${args.slice(3).join(' ')}`) - } + bot.chat.message(`${config.prefixes[0]}${args.slice(2).shift()} ${bot.validation.owner} ${args.slice(3).join(' ')}`) break case "admin": case "a": - if (bot.customChat.enabled === true) { - bot.customChat.chat(`${config.prefixes[0]}${args.slice(2).shift()} ${bot.validation.admin} ${args.slice(3).join(' ')}`) - } else if (bot.customChat.enabled === false) { - bot.chat.message(`${config.prefixes[0]}${args.slice(2).shift()} ${bot.validation.admin} ${args.slice(3).join(' ')}`) - } + bot.chat.message(`${config.prefixes[0]}${args.slice(2).shift()} ${bot.validation.admin} ${args.slice(3).join(' ')}`) break case "trusted": case "t": - if (bot.customChat.enabled === true) { - bot.customChat.chat(`${config.prefixes[0]}${args.slice(2).shift()} ${bot.validation.trusted} ${args.slice(3).join(' ')}`); - } else if (bot.customChat.enabled === false) { - bot.chat.message(`${config.prefixes[0]}${args.slice(2).shift()} ${bot.validation.trusted} ${args.slice(3).join(' ')}`); - } + bot.chat.message(`${config.prefixes[0]}${args.slice(2).shift()} ${bot.validation.trusted} ${args.slice(3).join(' ')}`); break default: - bot.chat.message(bot.getMessageAsPrismarine({ translate: "command.unknown.argument", color: "dark_red" })?.toMotd().replaceAll("§","&")) + throw new CommandError({ translate: "command.unknown.argument", color: "dark_red" }) } break case 'logging': @@ -121,7 +92,7 @@ module.exports = { } break default: - bot.chat.message(bot.getMessageAsPrismarine({ translate: "command.unknown.argument", color: "dark_red" })?.toMotd().replaceAll("§","&")) + throw new CommandError({ translate: "command.unknown.argument", color: "dark_red" }) } } } diff --git a/src/commands/owner/kill.js b/src/commands/owner/kill.js index bbd3dda..a86d56e 100644 --- a/src/commands/owner/kill.js +++ b/src/commands/owner/kill.js @@ -1,7 +1,7 @@ module.exports = { data: { name: 'kill', - trustLevel: 3, + trustLevel: 4, aliases: [ "suicide", "quit", diff --git a/src/commands/owner/servereval.js b/src/commands/owner/servereval.js index 53c5ad6..cc7c347 100644 --- a/src/commands/owner/servereval.js +++ b/src/commands/owner/servereval.js @@ -4,7 +4,7 @@ const util = require('util'); module.exports = { data: { name: 'servereval', - trustLevel: 3, + trustLevel: 4, aliases: [ "se" ], diff --git a/src/commands/public/help.js b/src/commands/public/help.js index 0e6ce60..a3c6935 100644 --- a/src/commands/public/help.js +++ b/src/commands/public/help.js @@ -249,10 +249,22 @@ module.exports = { } } - component.push(public); - component.push(trusted); - component.push(admin); - component.push(owner); + if (public.length > 0) { + component.push(public); + } + + if (trusted.length > 0) { + component.push(trusted); + } + + if (admin.length > 0) { + component.push(admin); + } + + if (owner.length > 0) { + component.push(owner); + } + if (source.sources.console) { component.push(Console); diff --git a/src/data/default_config.js b/src/data/default_config.js new file mode 100644 index 0000000..cdee641 --- /dev/null +++ b/src/data/default_config.js @@ -0,0 +1,114 @@ +module.exports = { + prefixes: [ + "!", + ], + + discord: { + token: "discord token here", + prefix: "!", + invite: "discord invite here", + enabled: true, + presence: { + name: "amogus", + status: "dnd" + }, + + roles: { + trusted: "trusted", + admin: "admin", + fullAccess: "full access", + owner: "FNFBoyfriendBot Owner" + } + }, + + core: { + name: { text: "FNFBoyfriendBot Core", color: "#00FFFF" }, + itemName: { text: "FNFBoyfriendBot core item", color: "#00FFFF" }, + itemRefill: true, + refillInterval: 300000, + // refilling core via item is buggy rn i recommend setting itemRefill to false for now + area: { + start: { + x: 0, + y: 0, + z: 0, + }, + end: { + x: 15, + y: 0, + z: 15, + } + } + }, + + weatherApiKey: "weather api token here", + + debug: { + commandSetMessage: false + }, + + keys: { + trusted: "trusted key here", + admin: "admin key here", + owner: "owner key here" + }, + + colors: { + integer: "gold", + discord: { + embed: "#000000", + error: "#FF0000" + }, + + commands: { + primary: "blue", + secondary: "aqua", + tertiary: "gray" + }, + + help: { + public: "blue", + trusted: "dark_aqua", + admin: "aqua", + owner: "light_purple", + console: "dark_purple" + } + }, + + console: { + prefix: "c." + }, + + logsFolder: { + path: "../../../", + // this is being loaded from the modules so make sure it starts with ../../ + name: "fnfboyfriendbot-logs", + }, + + bots: [ + // usernameGen is for a random username + // if private is set to true then the server ip for the server will be hidden + // channelId is for discord logging + // logging is for console logging + // reconnectDelay is for the delay for reconnecting to a server + // modes: + // kaboom: for the server kaboom.pw + // savageFriends: for the server savage Friends + // creayun for the server creayun + { + host: "localhost", + username: "FNFBoyfriendBot", + usernameGen: true, + version: "1.20.2", + serverName: "localhost", + private: false, + reconnectDelay: 6000, + channelId: "discord channel ip here", + logging: true, + mode: "kaboom", + selfcareInterval: 300 + } + ] +} + + diff --git a/src/data/default_config.yml b/src/data/default_config.yml deleted file mode 100644 index 47ff2be..0000000 --- a/src/data/default_config.yml +++ /dev/null @@ -1,81 +0,0 @@ -prefixes: - - "!" - -discord: - token: "discord token here" - prefix: "!" - invite: "discord invite here" - enabled: false - presence: - name: "amogus" - status: "dnd" - roles: - trusted: "trusted" - admin: "admin" - fullAccess: "full access" - owner: "FNFBoyfriendBot Owner" - -core: - name: { text: "FNFBoyfriendBot Core", color: "#00FFFF" } - itemName: { text: "FNFBoyfriendBot core item", color: "#00FFFF" } - itemRefill: true - # refilling core via item is buggy rn i recommend setting itemRefill to false for now - area: - start: - x: 0 - y: 0 - z: 0 - end: - x: 15 - y: 0 - z: 15 - -keys: - trusted: "trusted key here" - admin: "admin key here" - owner: "owner key here" - -weatherApiKey: "" - -colors: - integer: "gold" - discord: - embed: "#000000" - error: "#FF0000" - commands: - primary: "dark_blue" - secondary: "blue" - tertiary: "gray" - help: - public: "dark_blue" - trusted: "blue" - admin: "aqua" - owner: "light_purple" - console: "dark_purple" - -console: - prefix: "c." - -logsFolder: - path: "../../" - # this is being loaded from the modules so make sure it starts with ../../ - name: "logs" - -bots: - # modes: kaboom, savageFriends, creayun - # private is for hiding the server ip in netmsg - # reconnectDelay is for reconnecting the bot to the server on a delay - # serverName is whatever you set the name as for the server - # usernameGen is for generating random usernames - # channelId is for the discord channel - - host: "localhost" - username: "FNFBoyfriendBot" - usernameGen: true - version: "1.20.2" - serverName: "localhost" - private: false - reconnectDelay: 6000 - channelId: "discord channel id here" - logging: false - mode: "kaboom" - diff --git a/src/data/info.json b/src/data/info.json index 89fc5c8..14d10df 100644 --- a/src/data/info.json +++ b/src/data/info.json @@ -1,8 +1,8 @@ { "buildstring": { - "build": "2150", + "build": "2200", "codename": "", - "version": "v7.0.4", - "url":"https://code.chipmunk.land/Parker2991/FridayNightFunkinBoyfriendBot" + "version": "v7.0.5", + "url": "https://code.chipmunk.land/Parker2991/FridayNightFunkinBoyfriendBot.git" } } diff --git a/src/index.js b/src/index.js index 5de8f3f..f05cfd7 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,5 @@ const createBot = require('./bot.js'); const readline = require('readline'); -const js_yaml = require('js-yaml'); const fs = require('fs'); const path = require('path'); const { Client, GatewayIntentBits } = require('discord.js'); @@ -10,19 +9,15 @@ const CommandSource = require('./util/command_source'); console.log('Starting FNFBoyfriendBot'); -if (fs.existsSync(path.join(__dirname, "../config.yml")) === false) { +if (!fs.existsSync(path.join(__dirname, "../config.js"))) { console.warn("Config not found creating config from the default config"); fs.copyFileSync( - path.join(__dirname, "./data/default_config.yml"), - path.join(__dirname, "../config.yml") + path.join(__dirname, "./data/default_config.js"), + path.join(__dirname, "../config.js") ) } -try { - config = require('js-yaml').load(fs.readFileSync(path.join(__dirname, '../', 'config.yml'))) -} catch (e) { - console.log(e.stack); -} +const config = require('../config.js'); const rl = readline.createInterface({ input: process.stdin, @@ -35,11 +30,32 @@ const bots = []; let bot; for (const options of config.bots) { - bot = new createBot(options, config); + bot = createBot(options, config); bots.push(bot); bot.bots = bots; require('./util/loadModules')(bot, options, config, discordClient); + + let disconnectCount = 0; bot.console.readlineInterface(rl); + + bot.on('clientDisconnect', (data) => { + try { + disconnectCount++ + + if (disconnectCount === 10) { + bot.console.info('stopped logging disconnect messages for now...'); + bot?.discord?.channel?.send('stopped logging disconnect messages for now...'); + return; + } else if (disconnectCount > 10) { + return; + } else { + bot.console.warn(bot.getMessageAsPrismarine(`§8[§bClient Reconnect§8]§r ${data}`)?.toAnsi()) + bot?.discord?.channel?.send(data.toString()); + } + } catch (e) { + console.log(e.stack); + } + }); } discordClient.on('messageCreate', (message) => { diff --git a/src/modules/boot.js b/src/modules/boot.js deleted file mode 100644 index 5e0dffb..0000000 --- a/src/modules/boot.js +++ /dev/null @@ -1,28 +0,0 @@ -function inject (context) { - const bot = context.bot; - const config = context.config; - const options = context.options; - const info = require('../data/info.json'); - bot.on("packet.login", (data) => { - if (bot.options.mode === "creayun") return - if (new Date().getDay() === 5) { - bot.chat.message('Gettin\' freaky on a friday night!'); - } else { - bot.chat.message(`&9FNF&3Boyfriend&1Bot &b${info.buildstring.version} &fcreated by &4Parker&02991`); - } - }) - - process.on('SIGINT', (data) => { - bot.chat.message('Killing bot.....'); - process.exit(5); - }); -} - -module.exports = { - data: { - enabled: true, - name: "boot", - type: "start up" - }, - inject -}; diff --git a/src/modules/chat.js b/src/modules/chat.js index c305d23..bb87cf2 100644 --- a/src/modules/chat.js +++ b/src/modules/chat.js @@ -30,142 +30,22 @@ function inject (context) { bot.on('packet.profileless_chat', packet => { const message = tryParse(packet.message) const sender = tryParse(packet.name) - bot.emit('profileless_chat', { - message, - type: packet.type, - sender - }) + switch (packet.type) { case 1: - if (config?.debug?.chat?.profileless?.packetType === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PR Chat", color: "blue" }, - { text: "type", color: "light_purple" }, - { text: "1", color: "gold" }, - { translate: "chat.type.emote", with: [ sender, message ]} - ] - }); - } if (config?.debug?.chat?.profileless?.json === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PR Chat", color: "blue" }, - { text: "type", color: "light_purple" }, - { text: "1", color: "gold" }, - JSON.stringify({ - translate: "chat.type.emote", with: [ sender, message ] - }) - ] - }) - } else { - bot.emit('message', { translate: "chat.type.emote", with: [ sender, message ]}) - } + bot.emit('message', { translate: "chat.type.emote", with: [ sender, message ]}) break case 2: - if (config?.debug?.chat?.profileless?.packetType === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PR Chat", color: "blue" }, - { text: "type", color: "light_purple" }, - { text: "2", color: "gold" }, - { translate: "commands.message.display.incoming", with: [ sender, message ], color: "gray", italic: true } - ] - }) - } if (config?.debug?.chat?.profileless?.json === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PR Chat", color: "blue" }, - { text: "type", color: "light_purple" }, - { text: "2", color: "gold" }, - JSON.stringify({ - translate: "commands.message.display.incoming", with: [ sender, message ], color: "gray", italic: true - }) - ] - }) - } else { - bot.emit('message', { translate: "commands.message.display.incoming", with: [ sender, message ], color: "gray", italic: true }) - } + bot.emit('message', { translate: "commands.message.display.incoming", with: [ sender, message ], color: "gray", italic: true }) break case 3: - if (config?.debug?.chat?.profileless?.packetType === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PR Chat", color: "blue" }, - { text: "type", color: "light_purple" }, - { text: "3", color: "gold" }, - { translate: "commands.message.display.outgoing", with: [ sender, message ], color: "gray", italic: true } - ] - }) - } if (config?.debug?.chat?.profileless?.json === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PR Chat", color: "blue" }, - { text: "type", color: "light_purple" }, - { text: "3", color: "gold" }, - JSON.stringify({ - translate: "commands.message.display.outgoing", with: [ sender, message ], color: "gray", italic: true - }) - ] - }) - } else { - bot.emit('message', [{ translate: "commands.message.display.outgoing", with: [ sender, message ], color: "gray", italic: true }]) - } + bot.emit('message', [{ translate: "commands.message.display.outgoing", with: [ sender, message ], color: "gray", italic: true }]) break case 4: - if (config?.debug?.chat?.profileless?.packetType === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PR Chat", color: "blue" }, - { text: "type", color: "light_purple" }, - { text: "4", color: "gold" }, - message - ] - }) - } if (config?.debug?.chat?.profileless?.json === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PR Chat", color: "blue" }, - { text: "type", color: "light_purple" }, - { text: "4", color: "gold" }, - JSON.stringify(message) - ] - }) - } else { - bot.emit('message', [message]); - } + bot.emit('message', [message]); break case 5: - if (config?.debug?.chat?.profileless?.packetType === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PR Chat", color: "blue" }, - { text: "type", color: "light_purple" }, - { text: "5", color: "gold" }, - { translate: 'chat.type.announcement', with: [ sender, message ]} - ] - }) - } if (config?.debug.chat?.profileless?.json === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PR Chat", color: "blue" }, - { text: "type", color: "light_purple" }, - { text: "5", color: "gold" }, - JSON.stringify({ translate: 'chat.type.announcement', with: [ sender, message ]}) - ] - }) - } else { - bot.emit('message', [{ translate: 'chat.type.announcement', with: [ sender, message ]}]) - } + bot.emit('message', [{ translate: 'chat.type.announcement', with: [ sender, message ]}]) break } tryParsingMessage(message, { senderName: sender, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine }) @@ -173,132 +53,22 @@ function inject (context) { bot.on('packet.player_chat', (packet, data) => { const unsigned = tryParse(packet.unsignedChatContent) - bot.emit('player_chat', { plain: packet.plainMessage, unsigned, senderUuid: packet.senderUuid }) + switch (packet.type) { case 5: - if (config?.debug?.chat?.player?.packetType === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PL Chat", color: "green" }, - { text: "type", color: "dark_green"}, - { text: "5", color: "gold" }, - { translate: "chat.type.announcement", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ]} - ] - }) - } if (config?.debug?.chat?.player?.json === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PL Chat", color: "green" }, - { text: "type", color: "dark_green"}, - { text: "5", color: "gold" }, - JSON.stringify({ translate: "chat.type.announcement", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ]}) - ] - }) - } else { - bot.emit('message', { translate: "chat.type.announcement", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ]}) - } + bot.emit('message', { translate: "chat.type.announcement", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ]}) break case 4: - if (config?.debug?.chat?.player?.packetType === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PL Chat", color: "green" }, - { text: "type", color: "dark_green"}, - { text: "4", color: "gold" }, - unsigned - ] - }) - } if (config?.debug?.chat?.player?.json === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PL Chat", color: "green" }, - { text: "type", color: "dark_green"}, - { text: "4", color: "gold" }, - JSON.stringify(unsigned) - ] - }) - } else { - bot.emit('message', unsigned); - } + bot.emit('message', unsigned); break case 3: - if (config?.debug?.chat?.player?.packetType === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PL Chat", color: "green" }, - { text: "type", color: "dark_green"}, - { text: "3", color: "gold" }, - { translate: "commands.message.display.outgoing", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ], color: "gray", italic: true } - ] - }) - } if (config?.debug?.chat?.player?.json === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PL Chat", color: "green" }, - { text: "type", color: "dark_green"}, - { text: "3", color: "gold" }, - JSON.stringify({ translate: "commands.message.display.outgoing", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ], color: "gray", italic: true }) - ] - }) - } else { - bot.emit('message', { translate: "commands.message.display.outgoing", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ], color: "gray", italic: true }) - } + bot.emit('message', { translate: "commands.message.display.outgoing", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ], color: "gray", italic: true }); break case 2: - if (config?.debug?.chat?.player?.packetType === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PL Chat", color: "green" }, - { text: "type", color: "dark_green"}, - { text: "2", color: "gold" }, - { translate: "commands.message.display.incoming", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ], color: "gray", italic: true } - ] - }) - } if (config?.debug?.chat?.player?.json === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PL Chat", color: "green" }, - { text: "type", color: "dark_green"}, - { text: "2", color: "gold" }, - JSON.stringify({ translate: "commands.message.display.incoming", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ], color: "gray", italic: true }) - ] - }) - } else { - bot.emit('message', { translate: "commands.message.display.incoming", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ], color: "gray", italic: true }) - } + bot.emit('message', { translate: "commands.message.display.incoming", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ], color: "gray", italic: true }) break case 1: - if (config?.debug?.chat?.player?.packetType === true) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PL Chat", color: "green" }, - { text: "type", color: "dark_green"}, - { text: "1", color: "gold" }, - { translate: "chat.type.emote", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ]} - ] - }) - } if (config?.debug?.chat?.player?.json) { - bot.emit('message', { - translate: "[%s | %s: %s] %s", - with: [ - { text: "PL Chat", color: "green" }, - { text: "type", color: "dark_green"}, - { text: "1", color: "gold" }, - JSON.stringify({ translate: "chat.type.emote", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ]}) - ] - }) - } else { - bot.emit('message', { translate: "chat.type.emote", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ]}) - } + bot.emit('message', { translate: "chat.type.emote", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ]}) break } tryParsingMessage(unsigned, { senderUuid: packet.senderUuid, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine }) @@ -308,7 +78,6 @@ function inject (context) { const message = tryParse(packet.content) if (message.translate === "advMode.setCommand.success" && config?.debug?.commandSetMessage === false) return; if (message.translate === 'multiplayer.message_not_delivered') return - bot.emit('system_chat', { message, actionbar: packet.isActionBar }) if (packet.isActionBar) { return @@ -316,25 +85,8 @@ function inject (context) { if (message.translate === "advMode.notAllowed" || message?.translate?.startsWith("قيادة المجموعة")) return; - if (config?.debug?.chat?.system?.packetType === true) { - bot.emit('message', { - translate: "[%s] %s", - with: [ - { text: "System Chat", color: "dark_blue"}, - message - ] - }) - } if (config?.debug?.chat?.system?.json === true) { - bot.emit('message', { - translate: "[%s] %s", - with: [ - { text: "System Chat", color: "dark_blue"}, - JSON.stringify(message) - ] - }) - } else { - bot.emit('message', message); - } + bot.emit('message', message); + tryParsingMessage(message, { players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine }); }) @@ -358,7 +110,52 @@ function inject (context) { return undefined } - require('../util/chat_util')(bot); + + bot.chat = { + message (message) { + const acc = 0; + const bitset = Buffer.allocUnsafe(3); + bitset[0] = acc & 0xFF; + bitset[1] = (acc >> 8) & 0xFF; + bitset[2] = (acc >> 16) & 0xFF; + bot._client.write('chat_message', { + message: message?.substring(0, 256)?.replaceAll('§','&'), + timestamp: BigInt(Date.now()), + salt: 0n, + offset: 0, + acknowledged: bitset + }) + }, + + command (command) { + bot._client.write('chat_command', { + command: command?.substring(0, 256)?.replaceAll('§','&'), + timestamp: BigInt(Date.now()), + salt: 0n, + argumentSignatures: [], + signedPreview: false, + messageCount: 0, + acknowledged: Buffer.alloc(3), + previousMessages: [] + }) + }, + + send (message) { + if (message.startsWith('/')) { + bot.chat.command(message.substring(1)) + return; + } + bot.chat.message(message) + } + } + + bot.tellraw = (selector, message) => { + if (bot.options.mode === "savageFriends") { + bot.core.run(`minecraft:tellraw ${selector} ` + JSON.stringify(bot.getMessageAsPrismarine(message)?.toMotd())) + } else { + bot.core.run(`minecraft:tellraw ${selector} ` + JSON.stringify(message)) + } + } } module.exports = { data: { diff --git a/src/modules/command_core.js b/src/modules/command_core.js index f24f858..f959964 100644 --- a/src/modules/command_core.js +++ b/src/modules/command_core.js @@ -1,6 +1,6 @@ -const mcData = require('minecraft-data')('1.20.2'); const nbt = require('prismarine-nbt'); const sleep = require('../util/sleep'); + function inject (context) { const bot = context.bot; const config = context.config; @@ -48,7 +48,7 @@ function inject (context) { slot: 36, item: { present: true, - itemId: mcData.itemsByName.repeating_command_block.id, + itemId: bot.registry.itemsByName.repeating_command_block.id, itemCount: 1, nbtData: nbt.comp({ BlockEntityTag: nbt.comp({ @@ -175,7 +175,7 @@ function inject (context) { } }, - async runTracked (command) { + async runTracked (command, selector) { const location = bot.core.itemPosition; let transactionId = Math.floor(Math.random() * 10000); @@ -183,7 +183,7 @@ function inject (context) { slot: 36, item: { present: true, - itemId: mcData.itemsByName.repeating_command_block.id, + itemId: bot.registry.itemsByName.repeating_command_block.id, itemCount: 1, nbtData: nbt.comp({ BlockEntityTag: nbt.comp({ @@ -233,22 +233,81 @@ function inject (context) { if (data.transactionId == transactionId) { if (data?.nbt?.value?.LastOutput) { bot.tellraw("@a", JSON.parse(data.nbt.value.LastOutput.value).extra); - bot.tellraw(`@a[name="${bot.options.username}"]`, { - translate: "fnfboyfriendbot_command_block_output", - extra: [ - JSON.parse(data.nbt.value.LastOutput.value).extra - ] - }); } } } catch (e) { console.log(e.stack) } }); + + bot._client.removeListener('nbt_query_response'); } } - require('../util/core_util')(bot, config, options); + if (options.mode === "creayun") return; + let timer; + bot.on('packet.block_change', (data) => { + try { + if (data?.location?.x === bot?.core?.position?.x && data?.location?.y === bot?.core?.position?.y && data?.location?.z === bot?.core?.position?.z && data.type === 0) { + bot.core.move(bot.position); + } + } catch (e) { + bot.console.warn(e.toString()); + } + }); + + bot.on('move', async () => { + try { + if (bot.options.mode === "savageFriends") { + await sleep(2000); + bot.chat.command('/removenear commandblock'); + await sleep(2000); + bot.core.move(bot.position); + + } else { + bot.core.move(bot.position); + } + } catch (e) { + bot.console.warn(e.toString()); + } + }); + + bot.on('packet.login', () => { + timer = setInterval(() => { + bot.core.move(bot.position) + }, config.core.refillInterval) + }); + + bot.on('end', () => { + if (timer) clearInterval(timer); + }); + + bot.on('packet.multi_block_change', (data) => { + try { + if (bot.options.mode !== "kaboom") return; + + let broken = true; + + if ( + data.chunkCoordinates.x === Math.floor(bot.core.position.x / 16) + && + data.chunkCoordinates.y === Math.floor(bot.core.position.y / 16) + && + data.chunkCoordinates.z === Math.floor(bot.core.position.z / 16) + ) { + for (const state of data.records) { + if ((state >= 7906) && (state >= 7917)) broken = false; + if ((state >= 12527) && (state >= 12538)) broken = false; + if ((state >= 12515) && (state >= 12526)) broken = false; + else broken = true; + } + + if (broken === true) bot.core.move(bot.position); + } + } catch (e) { + console.log(e.stack); + } + }) } module.exports = { data: { diff --git a/src/modules/command_handler.js b/src/modules/command_handler.js index a842483..3bfeb18 100644 --- a/src/modules/command_handler.js +++ b/src/modules/command_handler.js @@ -5,14 +5,13 @@ function inject (context) { const bot = context.bot; const config = context.config; const options = context.options; - const { MessageBuilder } = require('prismarine-chat')(bot.options.version); + bot.on("parsed_message", (data) => { if (data.type !== "minecraft:chat") return; const prefixes = config.prefixes; prefixes.map((prefix) => { const plainMessage = bot.getMessageAsPrismarine(data.contents)?.toString(); -// console.log(plainMessage); if (!plainMessage.startsWith(prefix)) return const command = plainMessage.substring(prefix.length) const source = new CommandSource(data.sender, { discord: false, console: false }, true) diff --git a/src/modules/command_manager.js b/src/modules/command_manager.js index 75905a5..70d35fd 100644 --- a/src/modules/command_manager.js +++ b/src/modules/command_manager.js @@ -2,7 +2,6 @@ const fs = require('fs'); const path = require('path'); const CommandError = require('../util/command_error.js'); const CommandSource = require('../util/command_source'); -const { EmbedBuilder } = require('discord.js'); const fixansi = require('../util/ansi'); const cmdMgrUtil = require('../util/command_manager_util'); const sleep = require('../util/sleep.js'); @@ -32,7 +31,7 @@ async function inject (context) { ] })?.toAnsi()); } else { - bot.tellraw("@a", { + throw new CommandError({ translate: "%s%s%s %s", color: "dark_gray", with: [ @@ -49,20 +48,8 @@ async function inject (context) { return command?.execute({ bot, source, arguments: args, config, discordClient }); } catch (error) { -// console.error(error); - if (error instanceof CommandError) { - if (options.mode !== "kaboom") { - bot.chat.message(`&4${bot.getMessageAsPrismarine(error._message)?.toMotd().replaceAll('§','&')}`); - } else { - if (error.toString().length > 256) { - bot.tellraw("@a", error._message); - } else if (error.toString().length < 256) { - bot.chat.message(`${bot.getMessageAsPrismarine(error._message)?.toMotd().replaceAll('§','&')}`); - } else { - bot.tellraw("@a", error._message); - } - } + bot.tellraw("@a", error._message); } else { bot.tellraw("@a", { translate: "command.failed", @@ -100,7 +87,7 @@ async function inject (context) { if (!command?.discordExecute) { throw new CommandError(`${command.data.name} command is not supported in discord!`); } else if (source.sources.discord) { - return command?.discordExecute({ bot, source, arguments: args, config, discordClient, EmbedBuilder, fixansi }); + return command?.discordExecute({ bot, source, arguments: args, config, discordClient, fixansi }); } } catch (error) { if (error instanceof CommandError) { diff --git a/src/modules/command_suggestion.js b/src/modules/command_suggestion.js deleted file mode 100644 index e4b919c..0000000 --- a/src/modules/command_suggestion.js +++ /dev/null @@ -1,52 +0,0 @@ -function inject (context) { - const bot = context.bot - if (bot.options.mode !== "kaboom") return - bot.on('system_chat', (data) => { - try { - const message = data.message; -// console.log(message); - if (message.translate === "fnfboyfriendbot_request_command_suggestion") { - const extra = message.extra; - const uuidString = extra[0].text; - const uuidMatch = bot.players.find((e) => e.uuid === uuidString); - if (Array.isArray(extra) && extra.length > 0) { - const commandSuggestions = { - extra: [ - { text: "fnfboyfriendbot_request_command_suggestion" }, - ...bot.commandManager.commandlist.map((c) => { - const aliases = c.data.aliases.length > 0 ? c.data.aliases : []; - return { - extra: [ - c.data.trustLevel === 0 ? "PUBLIC" : - c.data.trustLevel === 1 ? "TRUSTED" : - c.data.trustLevel === 2 ? "ADMIN" : - c.data.trustLevel === 3 ? "OWNER" : - "OWNER", - "true", - ...aliases - ], - text: c.data.name - }; - }) - ], - text: "" - }; - const jsonString = (commandSuggestions); - bot.tellraw(`@a[name="${uuidMatch.profile.name}"]`, jsonString); - } - } - } catch (e) { - if (e.toString() === "TypeError: Cannot read properties of undefined (reading '0')") return - else console.log(e.stack) - } - }) -} -module.exports = { - data: { - enabled: true, - name: "command suggestion", - type: "commands" - }, - inject -}; - diff --git a/src/modules/console.js b/src/modules/console.js index 944b422..acaad50 100644 --- a/src/modules/console.js +++ b/src/modules/console.js @@ -16,7 +16,7 @@ function inject (context) { if (args.startsWith(config.console.prefix)) { return bot.commandManager.executeString(bot.console.source, args.substring(config.console.prefix.length)) } else if (args.startsWith("")) { - return bot.commandManager.executeString(bot.console.source, `console say ${args.substring(0)}`); + bot.chat.send(args); } rl.on('close', () => { this.readline = null; @@ -56,12 +56,11 @@ function inject (context) { bot.on('message', (message) => { if (!options.logging) return; - if (ratelimit > 10 || message?.translate === "fnfboyfriendbot_command_block_output" || message?.translate === "fnfboyfriendbot_request_command_suggestion") return; + if (ratelimit > 10) return; bot.console.log(bot.getMessageAsPrismarine(message)?.toAnsi()); bot.console.fileLogger(`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} logs] [${options.serverName}] ${bot.getMessageAsPrismarine(message)?.toString()}`); ratelimit++ }); - } module.exports = { diff --git a/src/modules/discord.js b/src/modules/discord.js index cdc010f..e54efb7 100644 --- a/src/modules/discord.js +++ b/src/modules/discord.js @@ -1,7 +1,6 @@ const fixansi = require('../util/ansi'); const CommandSource = require('../util/command_source'); -const util = require('util') function inject (context) { const bot = context.bot; const config = context.config; @@ -55,7 +54,6 @@ function inject (context) { } bot.on('message', (message) => { - if (message?.translate === "fnfboyfriendbot_command_block_output" || message?.translate === "fnfboyfriendbot_request_command_suggestion") return; sendComponent(message); }); diff --git a/src/modules/fileLogger.js b/src/modules/fileLogger.js index 24da75d..3e6b49e 100644 --- a/src/modules/fileLogger.js +++ b/src/modules/fileLogger.js @@ -3,6 +3,7 @@ const path = require("path"); const { createGzip } = require("zlib"); const readline = require('readline'); const { Console } = require("console"); + function inject (context) { const bot = context.bot; const config = context.config; diff --git a/src/modules/filter.js b/src/modules/filter.js deleted file mode 100644 index d398388..0000000 --- a/src/modules/filter.js +++ /dev/null @@ -1,154 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -function inject (context) { - const bot = context.bot; - const config = context.config; - const options = context.options; - - - if (options.mode !== "kaboom") return; - - bot.filter = { - list () { - try { - return JSON.parse(fs.readFileSync(path.join(__dirname, '../data/filter.json'))); - } catch (e) { - bot.console.warn(e.toString()) - } - }, - - add (Player, ignoreCase, Regex) { - var data = JSON.parse(fs.readFileSync(path.join(__dirname, '../data/filter.json'))); - const filterAdd = { name: Player, ignorecase: ignoreCase, regex: Regex }; - - data.push(filterAdd); - - fs.writeFileSync(path.join(__dirname, '../data/filter.json'), JSON.stringify(data)); - - this.doAll(); - }, - - remove (index) { - var data = JSON.parse(fs.readFileSync(path.join(__dirname, '../data/filter.json'))); - - data.splice(index, 1); - - fs.writeFileSync(path.join(__dirname, '../data/filter.json'), JSON.stringify(data)); - }, - - clear () { - var data = JSON.parse(fs.readFileSync(path.join(__dirname, '../data/filter.json'))); - - data = []; - - fs.writeFileSync(path.join(__dirname, '../data/filter.json'), JSON.stringify(data)); - }, - - doAll () { - for (const filtered of JSON.parse(fs.readFileSync(path.join(__dirname, '../data/filter.json')))) { - for (const players of bot.players) { - if (filtered.ignorecase === true) { - if (filtered.regex === true) { - let regex = new RegExp(filtered.name.toLowerCase()); - if (regex.test(players.profile.name.toLowerCase())) { - bot.core.run(`execute run gamemode adventure @a[name="${players.profile.name.toLowerCase()}"]`); - bot.core.run(`execute run deop @a[name="${players.profile.name.toLowerCase()}"]`) - } - } else { - if (filtered.name.toLowerCase() === players.profile.name.toLowerCase()) { - bot.core.run(`execute run gamemode adventure @a[name="${players.profile.name.toLowerCase()}"]`); - bot.core.run(`execute run deop @a[name="${players.profile.name}"]`); - } - } - } else if (filtered.regex === true) { - let regex = new RegExp(filtered.name); - if (regex.test(players.profile.name)) { - bot.core.run(`execute run gamemode adventure @a[name="${players.profile.name}"]`); - bot.core.run(`execute run deop @a[name="${players.profile.name}"]`); - } - } else { - if (filtered.name === players.profile.name) { - bot.core.run(`execute run gamemode adventure @a[name="${players.profile.name}"]`); - bot.core.run(`execute run deop @a[name="${players.profile.name}"]`); - } - } - } - } - } - } - - bot.on('parsed_message', (data) => { - try { - for (const filtered of JSON.parse(fs.readFileSync(path.join(__dirname, '../data/filter.json')))) { - if (filtered.ignorecase === true) { - if (filtered.regex === true) { - let regex = new RegExp(filtered.name.toLowerCase()); - if (regex.test(data.sender.profile.name.toLowerCase())) { - bot.core.run(`essentials:mute ${data.sender.uuid} 10y`); - } - } else { - if (data.sender.profile.name.toLowerCase() === filtered.name.toLowerCase()) { - bot.core.run(`essentials:mute ${data.sender.uuid} 10y`); - } - } - } else if (filtered.regex === true) { - let regex = new RegExp(filtered.name); - if (regex.test(data.sender.profile.name)) { - bot.core.run(`essentials:mute ${data.sender.uuid} 10y`); - } - } else { - if (data.sender.profile.name === filtered.name) { - bot.core.run(`essentials:mute ${data.sender.uuid} 10y`); - } - } - } - } catch (e) { - console.log(e.stack); - } - }); - - bot.on('player_info', (data) => { - for (const filtered of JSON.parse(fs.readFileSync(path.join(__dirname, '../data/filter.json')))) { - for (const players of bot.players) { - if (filtered.ignorecase === true) { - if (filtered.regex === true) { - let regex = new RegExp(filtered.name.toLowerCase()); - if (regex.test(players.profile.name.toLowerCase())) { - bot.core.run(`execute run gamemode adventure @a[name="${players.profile.name}"]`); - bot.core.run(`execute run deop @a[name="${players.profile.name}"]`); - bot.exploits.kicks.item(`@a[name="${players.profile.name}"]`); - } - } else { - if (filtered.name.toLowerCase() === players.profile.name.toLowerCase()) { - bot.core.run(`execute run gamemode adventure @a[name="${players.profile.name}"]`); - bot.core.run(`execute run deop @a[name="${players.profile.name}"]`); - bot.exploits.kicks.item(`@a[name="${players.profile.name}"]`); - } - } - } else if (filtered.regex === true) { - let regex = new RegExp(filtered.name); - if (regex.test(players.profile.name)) { - bot.core.run(`execute run gamemode adventure @a[name="${players.profile.name}"]`); - bot.core.run(`execute run deop @a[name="${players.profile.name}"]`); - } - } else { - if (players.profile.name === filtered.name) { - bot.core.run(`execute run gamemode adventure @a[name="${players.profile.name}"]`); - bot.core.run(`execute run deop @a[name="${players.profile.name}"]`); - bot.exploits.kicks.item(`@a[name="${players.profile.name}"]`); - } - } - } - } - }); -} - -module.exports = { - data: { - enabled: true, - name: "filter", - type: "blacklist" - }, - inject -} diff --git a/src/modules/player_list.js b/src/modules/player_list.js index f1ade50..270be65 100644 --- a/src/modules/player_list.js +++ b/src/modules/player_list.js @@ -31,6 +31,7 @@ function inject (context) { player.vanished = true; } else { bot.players = bot.players.filter(_ => _.uuid != player.uuid); + bot._client.removeListener('tab_complete'); bot.emit("player_left", player); } }) diff --git a/src/modules/position.js b/src/modules/position.js index 913a953..58b0e39 100644 --- a/src/modules/position.js +++ b/src/modules/position.js @@ -15,16 +15,6 @@ function inject (context) { bot.emit('move') }) - bot.on('move', () => { - if (config?.debug?.position?.bot === true) { - bot.console.debug(`Bot Position: ${JSON.stringify(bot.position)}`) - } if (config?.debug?.position?.core === true) { - bot.console.debug(`Core Position: ${JSON.stringify(bot.core.position)}`) - } if (config?.debug?.position?.coreItem === true) { - bot.console.debug(`Core Item Position: ${JSON.stringify(bot.core.itemPosition)}`) - } - }); - bot.on('end', () => { bot.position = null }) } diff --git a/src/modules/reconnect.js b/src/modules/reconnect.js index 3a166be..6a1e267 100644 --- a/src/modules/reconnect.js +++ b/src/modules/reconnect.js @@ -6,7 +6,6 @@ function inject (context) { const options = context.options; bot.on('end', () => { bot._client.removeAllListeners(); - if (bot.reconnectDelay < 0) return setTimeout(() => { if (options.usernameGen) { client = options.client ?? mc.createClient(options, options.username = usernameGen(bot)) diff --git a/src/modules/selfcare.js b/src/modules/selfcare.js index ef07d83..191e710 100644 --- a/src/modules/selfcare.js +++ b/src/modules/selfcare.js @@ -19,9 +19,9 @@ function inject (context) { let register = false; let positionCount = 0; bot.vanished = true - bot.on('system_chat', (data) => { + bot.on('message', (data) => { try { - const stringMessage = bot.getMessageAsPrismarine(data.message)?.toString(); + const stringMessage = bot.getMessageAsPrismarine(data)?.toString(); if (options.mode === "savageFriends") { if (stringMessage === "Please, login with the command: /login ") login = true; else if (stringMessage === "Successful login!") login = false; @@ -42,8 +42,8 @@ function inject (context) { else if (stringMessage === "Successfully enabled CommandSpy.") commandSpy = true; else if (stringMessage === "Successfully disabled CommandSpy") commandSpy = false; else if (stringMessage === "Successfully disabled CommandSpy.") commandSpy = false; - else if (stringMessage === `Vanish for ${bot.options.username}: enabled`) vanished = true; - else if (stringMessage === `Vanish for ${bot.options.username}: disabled`) vanished = false; + else if (stringMessage === `Vanish for ${bot._client.username}: enabled`) vanished = true; + else if (stringMessage === `Vanish for ${bot._client.username}: disabled`) vanished = false; else if (stringMessage === `You now have the tag: &8[&bPrefix&8: &3${config.prefixes[0]}&8]` || stringMessage === "Something went wrong while saving the prefix. Please check console.") prefix = true; else if (stringMessage?.startsWith("You now have the tag: ") || stringMessage === "You no longer have a tag") prefix = false else if (stringMessage?.startsWith("You have been muted")) unmuted = true; @@ -53,12 +53,12 @@ function inject (context) { else if (stringMessage === "God mode enabled.") god = true; else if (stringMessage === "Teleportation disabled.") teleportToggle = true; else if (stringMessage === "Teleportation enabled.") teleportToggle = false; - else if (stringMessage === `Successfully set your username to "${bot.username}"`) { + else if (stringMessage === `Successfully set your username to "${bot._client.username}"`) { username = false return } else if (stringMessage?.startsWith("Successfully set your username to ")) username = true - else if (stringMessage === `You already have the username "${bot.username}"`) username = false + else if (stringMessage === `You already have the username "${bot._client.username}"`) username = false else if (stringMessage === `You no longer have a nickname.`) nickname = false; else if (stringMessage?.startsWith('Your nickname is now ')) nickname = true; } @@ -115,17 +115,17 @@ function inject (context) { } else if (bot.options.mode === "kaboom") { if (permissionLevel < 2) bot.chat.command('op @s[type=player]'); else if (gameMode !== 1) bot.chat.command('minecraft:gamemode creative'); - else if (!commandSpy) bot.chat.command('commandspy on'); - else if (username) bot.chat.command(`username ${bot.options.username}`) + else if (username) bot.chat.command(`username ${bot._client.username}`) else if (nickname) bot.chat.command(`nick off`) else if (!prefix) bot.chat.command(`prefix &8[&bPrefix&8: &3${config.prefixes[0]}&8]`); - else if (!vanished && bot.vanished) bot.chat.command(`essentials:vanish on`); + else if (!vanished && bot.vanished) bot.core.run(`essentials:vanish ${bot._client.username} on`); + else if (!commandSpy) bot.core.run(`commandspy ${bot.uuid} on`); else if (unmuted) bot.core.run(`essentials:mute ${bot.uuid}`); else if (!god) bot.core.run(`god ${bot.options.username} enable`); else if (!teleportToggle) bot.core.run(`tptoggle ${bot.options.username} disable`); else if (clientLock !== 4) bot._client.write("client_command", { actionId: 0 }); } - }, 1000); + }, options.selfcareInterval); }); bot.on('end', () => { if (timer) clearInterval(timer) diff --git a/src/modules/team.js b/src/modules/team.js deleted file mode 100644 index 3afaad3..0000000 --- a/src/modules/team.js +++ /dev/null @@ -1,60 +0,0 @@ -const sleep = require('../util/sleep'); - -function inject (context) { - const bot = context.bot; - const options = context.options; - const config = context.config; - - if (options.mode !== "kaboom" || config.team.enabled === false) return; - bot.on("packet.login", async () => { - if (options.mode === "kaboom") { - await sleep(100); - bot.chat.command(`minecraft:team add ${config.team.name}`); - await sleep(100); - bot.core.run(`minecraft:team join ${config.team.name} @a[name="${bot.options.username}"]`); - } - }) - - bot.on("packet.teams", async (data) => { - try { - if (data.team === config.team.name) { - data?.players?.map(async (player) => { - if (player !== bot.options.username) { - await sleep(100); - bot.core.run(`minecraft:team empty ${config.team.name}`); - await sleep(100); - bot.core.run(`minecraft:team join ${config.team.name} @a[name="${bot.options.username}"]`); - // this removes players who are not the bot - } - }); - - if (data.mode == 1) { - // this is checking if the team has been deleted - bot.core.run(`minecraft:team add ${config.team.name}`); - await sleep(100); - bot.core.run(`minecraft:team join ${config.team.name} @a[name="${bot.options.username}"]`); - } if (data.name !== JSON.stringify(config.team.displayName)) { - // this checks if the team displayName matches the one set in the config - bot.core.run(`minecraft:team modify ${config.team.name} displayName ${JSON.stringify(config.team.displayName)}`); - } if (data.prefix !== JSON.stringify(config.team.prefix)) { - // this checks if the team prefix matches the one set in the config - bot.core.run(`minecraft:team modify ${config.team.name} prefix ${JSON.stringify(config.team.prefix)}`); - } if (data.suffix !== JSON.stringify(config.team.suffix)) { - // this checks if the team suffix matches the one set in the config - bot.core.run(`minecraft:team modify ${config.team.name} suffix ${JSON.stringify(config.team.suffix)}`) - } - } - } catch (e) { - console.log(e.stack) - } - }) -} - -module.exports = { - data: { - enabled: true, - name: "teams", - type: "extras" - }, - inject -} diff --git a/src/util/chat_util.js b/src/util/chat_util.js deleted file mode 100644 index 9078bfe..0000000 --- a/src/util/chat_util.js +++ /dev/null @@ -1,68 +0,0 @@ -const sleep = require('./sleep'); -module.exports = (bot) => { - bot.chat = { - message (message) { - const acc = 0; - const bitset = Buffer.allocUnsafe(3); - bitset[0] = acc & 0xFF; - bitset[1] = (acc >> 8) & 0xFF; - bitset[2] = (acc >> 16) & 0xFF; - bot._client.write('chat_message', { - message: message?.substring(0, 256)?.replaceAll('§','&'), - timestamp: BigInt(Date.now()), - salt: 0n, - offset: 0, - acknowledged: bitset - }) - }, - - command (command) { - bot._client.write('chat_command', { - command: command?.substring(0, 256)?.replaceAll('§','&'), - timestamp: BigInt(Date.now()), - salt: 0n, - argumentSignatures: [], - signedPreview: false, - messageCount: 0, - acknowledged: Buffer.alloc(3), - previousMessages: [] - }) - }, - - send (message) { - if (message.startsWith('/')) { - bot._client.write('chat_command', { - command: message?.substring(1).substring(0, 256)?.replaceAll('§','&'), - timestamp: BigInt(Date.now()), - salt: 0n, - argumentSignatures: [], - signedPreview: false, - messageCount: 0, - acknowledged: Buffer.alloc(3), - previousMessages: [] - }) - return; - } - const acc = 0; - const bitset = Buffer.allocUnsafe(3); - bitset[0] = acc & 0xFF; - bitset[1] = (acc >> 8) & 0xFF; - bitset[2] = (acc >> 16) & 0xFF; - bot._client.write('chat_message', { - message: message?.substring(0, 256)?.replaceAll('§','&'), - timestamp: BigInt(Date.now()), - salt: 0n, - offset: 0, - acknowledged: bitset - }) - } - } - - bot.tellraw = (selector, message) => { - if (bot.options.mode === "savageFriends") { - bot.core.run(`minecraft:tellraw ${selector} ` + JSON.stringify(bot.getMessageAsPrismarine(message)?.toMotd())) - } else { - bot.core.run(`minecraft:tellraw ${selector} ` + JSON.stringify(message)) - } - } -} diff --git a/src/util/core_util.js b/src/util/core_util.js new file mode 100644 index 0000000..fd4b370 --- /dev/null +++ b/src/util/core_util.js @@ -0,0 +1,77 @@ +const sleep = require('./sleep'); + +function coreUtil (bot, config, options) { + if (options.mode === "creayun") return; + let timer; + bot.on('packet.block_change', (data) => { + try { +// if (bot.options.mode === "savageFriends") return; + // type 12521 = repeating_command_block + // type 12533 = chain_command_block + // type 7912 = command_block + // type 0 = air + if (data?.location?.x === bot?.core?.position?.x && data?.location?.y === bot?.core?.position?.y && data?.location?.z === bot?.core?.position?.z && data.type === 0) { + bot.core.move(bot.position); + } + } catch (e) { + bot.console.warn(e.toString()); + } + }); + + bot.on('move', async () => { + try { + if (bot.options.mode === "savageFriends") { + await sleep(2000); + bot.chat.command('/removenear commandblock'); + await sleep(2000); + bot.core.move(bot.position); + + } else { + bot.core.move(bot.position); + } + } catch (e) { + bot.console.warn(e.toString()); + } + }); + + bot.on('packet.login', () => { + timer = setInterval(() => { + bot.core.move(bot.position) + }, config.core.refillInterval) + }); + + bot.on('end', () => { + if (timer) clearInterval(timer); + }); + + + bot.on('packet.multi_block_change', (data) => { + try { + if (bot.options.mode !== "kaboom") return; + + let broken = true; + + if ( + data.chunkCoordinates.x === Math.floor(bot.core.position.x / 16) + && + data.chunkCoordinates.y === Math.floor(bot.core.position.y / 16) + && + data.chunkCoordinates.z === Math.floor(bot.core.position.z / 16) + ) { + for (const state of data.records) { + if ((state >= 7906) && (state >= 7917)) broken = false; + if ((state >= 12527) && (state >= 12538)) broken = false; + if ((state >= 12515) && (state >= 12526)) broken = false; + else broken = true; + } + + if (broken === true) bot.core.move(bot.position); +// console.log(broken); + } + + } catch (e) { + console.log(e.stack); + } + }) +} +module.exports = coreUtil; diff --git a/src/util/usernameGen.js b/src/util/usernameGen.js index c94fc4c..3ceefb8 100644 --- a/src/util/usernameGen.js +++ b/src/util/usernameGen.js @@ -1,10 +1,5 @@ -function usernameGen (bot, config) { -// const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; - if (bot.options.mode === "savageFriends" || bot.options.mode === "creayun") { - characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; - } else { - characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_-+={]}[|\\:;>.<,/?ඞ♋' - } +function usernameGen () { + const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; let username = ''; for (let i = 0; i < 3 + Math.floor(Math.random() * 14); i++ ) { const randomIndex = Math.floor(Math.random() * characters.length);