From 572e09989c4506d80fff7cfbcd2ca1593592d351 Mon Sep 17 00:00:00 2001 From: Parker2991 Date: Fri, 6 Dec 2024 11:04:23 -0500 Subject: [PATCH] v6.1.3, build: 1210, 12/06/24 refratured the core. fixed reconnect spam. added coresettings so that the core can be configured via command. added team selfcare. --- package-lock.json | 8 +- .../public => removed-scrapped-crap}/bots.js | 0 src/bot.js | 31 ++- src/commands/admin/coreSettings.js | 102 ++++++++++ src/commands/owner/servereval.js | 3 +- src/commands/public/core.js | 9 +- src/commands/public/help.js | 30 ++- src/commands/public/refillcore.js | 9 +- src/commands/public/weather.js | 4 +- src/commands/trusted/validate.js | 2 +- src/data/default_config.yml | 43 ++++- src/index.js | 12 +- src/modules/command_core.js | 177 ++++++++++-------- src/modules/command_manager.js | 6 +- src/modules/console.js | 2 +- src/modules/discord.js | 2 +- src/modules/player_list.js | 16 +- src/modules/position.js | 5 +- src/modules/selfcare.js | 62 +++--- src/modules/tab_complete.js | 8 +- src/modules/team.js | 52 +++++ src/util/ChatParsers/Creayun.js | 4 + src/util/ChatParsers/VanillaChat.js | 4 +- 23 files changed, 425 insertions(+), 166 deletions(-) rename {src/commands/public => removed-scrapped-crap}/bots.js (100%) create mode 100644 src/commands/admin/coreSettings.js create mode 100644 src/modules/team.js diff --git a/package-lock.json b/package-lock.json index e44e69e..3b6c494 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3,10 +3,10 @@ "lockfileVersion": 3, "requires": true, "buildstring": { - "version": "v6.1.2", - "build": "1200", - "releaseDate": "11/22/24", - "codename": "§eHazardous §4Massacre", + "version": "v6.1.3", + "build": "1210", + "releaseDate": "1/06/24", + "codename": "", "url": "https://code.chipmunk.land/Parker2991/FridayNightFunkinBoyfriendBot" }, "packages": { diff --git a/src/commands/public/bots.js b/removed-scrapped-crap/bots.js similarity index 100% rename from src/commands/public/bots.js rename to removed-scrapped-crap/bots.js diff --git a/src/bot.js b/src/bot.js index 3061d4d..dc8ffb5 100644 --- a/src/bot.js +++ b/src/bot.js @@ -2,9 +2,9 @@ const mc = require('minecraft-protocol'); const { EventEmitter } = require('events'); EventEmitter.defaultMaxListeners = 5e6; const util = require('util'); -const createRegistry = require('prismarine-registry'); const ChatMessage = require('prismarine-chat'); function createBot(options = {}, config) { + let endCount = 0; const bot = new EventEmitter(); bot.options = { // Set some default values in options @@ -17,15 +17,15 @@ function createBot(options = {}, config) { bot.on('init_client', client => { client.on('packet', (data, meta) => { bot.emit('packet', data, meta) - bot.emit('packet.' + meta.name, data) + bot.emit('packet.' + meta.name, data); }) - client.on('login', () => { + client.on('login', (data) => { bot.uuid = client.uuid bot.username = client.username - bot.registry = createRegistry(client.version) + bot.registry = require('prismarine-registry')(client.version); bot.registry.language = require('./data/language.json'); - bot.emit('registry_ready', bot.registry) + bot.emit('registry_ready', bot.registry); }) client.on('disconnect', data => { @@ -36,14 +36,21 @@ function createBot(options = {}, config) { 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()) - // bot = undefined; -// config = undefined; + bot.console.warn(ChatMessage(bot._client.version).fromNotch(`§8[§bClient Reconnect§8]§r ${reason}`)?.toAnsi()); }) client.on('error', error => { - bot.console.warn(ChatMessage(bot._client.version).fromNotch('§8[§bClient Reconnect§8]§r ')?.toAnsi() + util.inspect(error.toString())) - bot?.discord?.channel?.send(error.toString()) + 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()); + } }) client.on("keep_alive", ({ keepAliveId }) => { @@ -56,6 +63,10 @@ function createBot(options = {}, config) { bot?.discord?.channel?.send(util.inspect(data.reason)) }) + client.on('success', (data) => { + endCount = 0; + }) + process.on("uncaughtException", (e) => { // console?.warn(e.stack) }); diff --git a/src/commands/admin/coreSettings.js b/src/commands/admin/coreSettings.js new file mode 100644 index 0000000..768a0dc --- /dev/null +++ b/src/commands/admin/coreSettings.js @@ -0,0 +1,102 @@ +const CommandError = require('../../util/command_error'); + +module.exports = { + data: { + name: 'coresettings', + trustLevel: 2, + aliases: [ + "cbsettings" + ], + description: 'change the bots core settings', + usages: [ + "useplacedcommandblock ", + "area start ", + "area end ", + "refillmethod/rcmethod " + ], + }, + execute (context) { + const bot = context.bot + const args = context.arguments; + const config = context.config; + if (!args && !args[0] && !args[1] && !args[2] && !args[3] && !args[4] && !args[5]) return; + switch (args[1]?.toLowerCase()) { + case "useplacedcommandblock": + switch (args[2]?.toLowerCase()) { + case "on": + case "true": + case "enable": + bot.core.usePlacedCommandBlock = true; + bot.chat.message('now using the placed command block'); + break; + case "off": + case "false": + case "disable": + bot.core.usePlacedCommandBlock = false; + bot.chat.message('no longer using the placed command block'); + break; + default: + if (bot.core.usePlacedCommandBlock) { + bot.chat.message("the bot is currently using the placed command block to run its commands"); + } else { + bot.chat.message("the bot is currently using its command block core to run its commands"); + } + } + break; + case "area": + switch (args[2]?.toLowerCase()) { + case "start": + if (isNaN(args[3]) || isNaN(args[4]) || isNaN(args[5])) { + bot.core.area.start = config.core.area.start; + bot.chat.message("arguments were NaN, defaulting to config core start coords"); + } else { + bot.core.area.start = { + x: Number(args[3]), + y: Number(args[4]), + z: Number(args[5]) + }; + bot.chat.message(`setting core start pos to x: ${args[3]}, y: ${args[4]}, z: ${args[5]}`); + } + break; + case "end": + if (isNaN(args[3]) || isNaN(args[4]) || isNaN(args[5])) { + bot.core.area.end = config.core.area.end; + bot.chat.message("arguments were NaN, defaulting to config core end coords"); + } else { + bot.core.area.end = { + x: Number(args[3]), + y: Number(args[4]), + z: Number(args[5]) + }; + + bot.chat.message(`setting core end pos to x: ${args[3]}, y: ${args[4]}, z: ${args[5]}`); + } + break; + default: + bot.chat.message(`core start pos: x: ${bot.core.area.start.x}, y: ${bot.core.area.start.y}, z: ${bot.core.area.start.z}, and end pos: x: ${bot.core.area.end.x}, y: ${bot.core.area.end.y}, z: ${bot.core.area.end.z} `) + } + break; + case "refillmethod": + case "rcmethod": + switch (args[2]?.toLowerCase()) { + case "item": + config.core.itemRefill = true; + bot.chat.message('now refilling via item'); + break; + case "chat": + config.core.itemRefill = false; + bot.chat.message('now refilling via chat'); + break; + default: + if (config.core.itemRefill) { + bot.chat.message("currently filling core via item"); + } else { + bot.chat.message("currently filling core via chat"); + } + } + break; + default: + throw new CommandError('invalid argument'); + } + }, +} diff --git a/src/commands/owner/servereval.js b/src/commands/owner/servereval.js index dc97637..a5ec7a9 100644 --- a/src/commands/owner/servereval.js +++ b/src/commands/owner/servereval.js @@ -6,6 +6,7 @@ module.exports = { name: 'servereval', trustLevel: 3, aliases: [ + "se" ], description: 'run code unisolated', usages: [ @@ -25,7 +26,7 @@ module.exports = { } else if (bot.options.useChat || bot.options.isSavage) { bot.chat.message(bot.getMessageAsPrismarine({ text: util.inspect(eval(script), { stylize }).substring(0, 32700) })?.toMotd().replaceAll('§','&')) } else { - bot.tellraw(`@a`, [ + bot.tellraw(`@a[name="${source.player.profile.name}"]`, [ { text: util.inspect(eval(script), { stylize }).substring(0, 32700), hoverEvent: { diff --git a/src/commands/public/core.js b/src/commands/public/core.js index a6f07e0..0ac0d37 100644 --- a/src/commands/public/core.js +++ b/src/commands/public/core.js @@ -1,5 +1,5 @@ const CommandError = require('../../util/command_error') -const sleep = require('../../util/sleep'); + module.exports = { data: { name: 'core', @@ -17,12 +17,7 @@ module.exports = { execute (context) { const bot = context.bot const message = context.arguments.join(' '); - bot.core.runTracked(message); -/* bot.on('commandBlockOutput', (packet) => { - bot.tellraw("@a", require('util').inspect(packet)); - console.log(packet); - })*/ -// bot.core.commandBlockOutput() + bot.core.run(message); }, discordExecute (context) { const bot = context.bot; diff --git a/src/commands/public/help.js b/src/commands/public/help.js index 6e7da0d..ba61fce 100644 --- a/src/commands/public/help.js +++ b/src/commands/public/help.js @@ -348,12 +348,40 @@ module.exports = { setTimeout(() => { bot.chat.message(bot.getMessageAsPrismarine(trusted)?.toMotd().replaceAll("§","&")); }, 400) - setTimeout(() => { + setTimexout(() => { bot.chat.message(bot.getMessageAsPrismarine(admin)?.toMotd()?.replaceAll('§','&')) }, 400) setTimeout(() => { bot.chat.message(bot.getMessageAsPrismarine(owner).toMotd().replaceAll("§","&")); }, 400) + } else if (bot.options.isCreayun) { + bot.chat.message(bot.getMessageAsPrismarine([ + { + text: 'Commands (', + color: 'gray' + }, + { + text: length, + color: 'gold' + }, + { + text: ') ', + color: 'gray' + }, + category, + ])?.toMotd().replaceAll('§','&')) + setTimeout(() => { + bot.chat.message(bot.getMessageAsPrismarine(public)?.toMotd().replaceAll("§","&")) + }, 2500) + setTimeout(() => { + bot.chat.message(bot.getMessageAsPrismarine(trusted)?.toMotd().replaceAll("§","&")); + }, 2500) + setTimeout(() => { + bot.chat.message(bot.getMessageAsPrismarine(admin)?.toMotd()?.replaceAll('§','&')) + }, 2500) + setTimeout(() => { + bot.chat.message(bot.getMessageAsPrismarine(owner).toMotd().replaceAll("§","&")); + }, 2500) } else if (admin.length === 0) { bot.tellraw(`@a[name="${source?.player?.profile?.name}"]`, [ { text: 'Commands (', color: 'gray' }, diff --git a/src/commands/public/refillcore.js b/src/commands/public/refillcore.js index 78dcf7c..82a9457 100644 --- a/src/commands/public/refillcore.js +++ b/src/commands/public/refillcore.js @@ -12,13 +12,16 @@ module.exports = { ], }, execute (context) { - const bot = context.bot - bot.core.refill() + const bot = context.bot; + const config = context.config; + bot.core.move(); bot.tellraw("@a", "Refilling core,...") }, + discordExecute (context) { const bot = context.bot; - bot.core.refill(); + const config = context.config; + bot.core.move(); bot.tellraw("@a", "Refilling core,..."); } } diff --git a/src/commands/public/weather.js b/src/commands/public/weather.js index 45c2a75..fcc291e 100644 --- a/src/commands/public/weather.js +++ b/src/commands/public/weather.js @@ -8,7 +8,7 @@ module.exports = { ], description: 'check the weather of cities', usages: [ - "" + "" ], }, async execute (context) { @@ -18,7 +18,7 @@ module.exports = { const source = context.source; try { let component = []; - const weather = await request(`https://api.weatherapi.com/v1/current.json?key=${config.weatherApiKey}&q=${args.join(' ')}`); + const weather = await request(`https://api.weatherapi.com/v1/current.json?key=${config.weatherApiKey}&q=${args.join(' ')?.replaceAll(' ', ',')}`); const info = await weather.body.json(); component.push({ translate: "%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s%s (%s%s)\n%s: %s %s %s (%s %s %s)\n%s: %s\n%s: %s", diff --git a/src/commands/trusted/validate.js b/src/commands/trusted/validate.js index 6c5a817..bc7d089 100644 --- a/src/commands/trusted/validate.js +++ b/src/commands/trusted/validate.js @@ -33,7 +33,7 @@ module.exports = { if (roles?.some(role => role.name === `${config.discord.roles.trusted}`)) { bot.discord.message.reply('Valid trusted user') bot.chat.message(`Valid trusted user [${bot.discord.message.member.user.username}]`) - } else if (roles?.some(role => role.name === `${config.discord.roles.owner}`)) { + } else if (roles?.some(role => role.name === `${config.discord.roles.owner}` || role.name === `${config.discord.roles.fullAccess}`)) { bot.discord.message.reply('Valid Owner user') bot.chat.message(`Valid Owner User [${bot.discord.message.member.user.username}]`); } diff --git a/src/data/default_config.yml b/src/data/default_config.yml index e4f1c21..603199f 100644 --- a/src/data/default_config.yml +++ b/src/data/default_config.yml @@ -1,21 +1,22 @@ prefixes: - "!" + discord: token: "discord token here" prefix: "!" invite: "discord invite here" - enabled: true + enabled: false roles: trusted: "trusted" admin: "admin" + fullAccess: "full access" owner: "FNFBoyfriendBot Owner" core: - # core refill methods: - # chat: refill core in chat - # item refill core in a command block placed by the bot - name: {"translate":"outOfMemory.message"} - method: 'item' + 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 @@ -26,7 +27,36 @@ core: y: 0 z: 15 +team: + name: "FNFBoyfriendBot" + suffix: { + color: "dark_gray", + translate: " [ %s ]", + with: [ + { color: "dark_red", text: "https://sus.red" } + ] + } + # make sure if nothing is set as the suffix it is set as { text: "" } as the packet reads "" as { text: "" } + prefix: { + color: "dark_gray", + translate: "[%s: %s] ", + with: [ + { color: "aqua", text: "Prefix" }, + { color: "dark_aqua", text: "!" } + ] + } + displayName: { + translate: "%s%s%s", + with: [ + { color: "dark_blue", text: "FNF" }, + { color: "dark_aqua", text: "Boyfriend" }, + { color: "blue", text: "Bot" } + ] + } + # color HAS to come first before any components or it will break! dont ask why, its because of how nmp parses it + commandSetMessage: false +# ^^ this is for when commands are ran in core keys: trusted: "trusted key here" @@ -47,7 +77,6 @@ colors: console: prefix: "c." - filelogger: false bots: - host: "localhost" diff --git a/src/index.js b/src/index.js index eba66b9..f5e94d1 100644 --- a/src/index.js +++ b/src/index.js @@ -9,23 +9,25 @@ const { Client, GatewayIntentBits } = require('discord.js'); const { MessageContent, GuildMessages, Guilds } = GatewayIntentBits; const discordClient = new Client({ intents: [Guilds, GuildMessages, MessageContent] }); console.log('Starting FNFBoyfriendBot'); -process.stdout.write('\x1b]2;Starting FNFBoyfriendBot please wait,.....\x1b\x5c') -checks(); +process.stdout.write('\x1b]2;Starting FNFBoyfriendBot please wait,.....\x1b\x5c'); try { config = js_yaml.load(fs.readFileSync(path.join(__dirname, '../', 'config.yml'))) } catch (e) { console.log(e.stack); } -if (config.core.method !== 'item' && config.core.method !== 'chat') { + +checks(config); + +/*if (config.core.method !== 'item' && config.core.method !== 'chat') { config.core.method = 'item'; console.warn('invalid core method type defaulting to item'); -} +}*/ const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }) -//console.log(completion); + if (config.discord.enabled) discordClient.login(config.discord.token); const bots = []; for (const options of config.bots) { diff --git a/src/modules/command_core.js b/src/modules/command_core.js index 29a6711..8811c77 100644 --- a/src/modules/command_core.js +++ b/src/modules/command_core.js @@ -1,4 +1,5 @@ const mcData = require('minecraft-data')('1.20.2'); +const nbt = require('prismarine-nbt'); function core (context) { const bot = context.bot; @@ -12,9 +13,13 @@ function core (context) { position: null, + itemPosition: null, + currentBlockRelative: { x: 0, y: 0, z: 0 }, - refill () { + usePlacedCommandBlock: false, + + chatRefill () { const pos = bot.core.position const { start, end } = bot.core.area @@ -30,45 +35,62 @@ function core (context) { instead of tping to a set cords cuz fuck you im not doing that */ const command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} repeating_command_block{CustomName:'${JSON.stringify(config.core.name)}'} destroy` - if (config.core.method === 'chat') { - bot.chat.command(`${command}`) - } else if (config.core.method === 'item') { - bot._client.write('set_creative_slot', { - slot: 36, - item: { - present: true, - itemId: mcData.itemsByName.command_block.id, - itemCount: 1, - nbtData: { } - } - }); + bot.chat.command(`${command}`) + }, - bot._client.write('block_dig', { - status: 0, - location: { - x: bot.position.x, - y: bot.position.y, - z: bot.position.z - }, - face: 0 - }); + itemRefill () { + const pos = bot.core.position; + const { start, end } = bot.core.area; + const itemPosition = bot.core.itemPosition; - bot._client.write('block_place', { - hand: 0, - location: { - x: bot.position.x, - y: bot.position.y, - z: bot.position.z - }, - direction: 0, - cursorX: 0.1, - cursorY: 0, - cursorZ: 0.1, - insideBlock: false - }); + if (!pos) return; + if (bot.options.useChat || bot.options.isCreayun || bot.options.isSavage) return; + if (isNaN(pos.x + pos.x)) { + bot.chat.command('spawn'); + return + } + /*^^^ + for checking is the core pos is null and if so + it will not refill core until the pos is not NaN + instead of tping to a set cords cuz fuck you im not doing that + */ + const command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} repeating_command_block{CustomName:'${JSON.stringify(config.core.name)}'} destroy` + bot._client.write('set_creative_slot', { + slot: 36, + item: { + present: true, + itemId: mcData.itemsByName.repeating_command_block.id, + itemCount: 1, + nbtData: nbt.comp({ + BlockEntityTag: nbt.comp({ + CustomName: nbt.string(JSON.stringify(config.core.itemName)) + }) + }) + } + }); + + bot._client.write('block_dig', { + status: 0, + location: itemPosition, + face: 0 + }); + + bot._client.write('block_place', { + hand: 0, + location: itemPosition, + direction: 0, + cursorX: 0.1, + cursorY: 0, + cursorZ: 0.1, + insideBlock: false + }); + + if (bot.core.usePlacedCommandBlock) { + return + } else { bot._client.write('update_command_block', { - location: bot.position, + location: itemPosition, command, flags: 5, mode: 1 @@ -81,8 +103,19 @@ function core (context) { x: Math.floor(pos.x / 16) * 16, y: 0, z: Math.floor(pos.z / 16) * 16 + }; + + bot.core.itemPosition = { + x: pos.x, + y: pos.y -1, + z: pos.z + } + + if (config.core.itemRefill === true) { + bot.core.itemRefill(); + } else { + bot.core.chatRefill(); } - bot.core.refill() }, currentBlock () { @@ -116,54 +149,34 @@ function core (context) { }, run (command) { - const eee = Math.floor(Math.random() * 10000) - const location = bot.core.currentBlock() - if (!location) return + const location = bot.core.currentBlock(); + const itemPosition = bot.core.itemPosition; + + if (!location) return; if (bot.options.isSavage || bot.options.isCreayun || bot.options.useChat) { return } else { - bot._client.write('update_command_block', { command: command.substring(0, 32767), location, mode: 1, flags: 0b100 }); - bot._client.write('query_block_nbt', ({ location: location, transactionId: eee})); - bot.core.incrementCurrentBlock(); + if (bot.core.usePlacedCommandBlock) { + bot._client.write('update_command_block', { + command: command.substring(0, 32767), + location: itemPosition, + mode: 1, + flags: 5, + }); + + bot.core.incrementCurrentBlock(); + } else { + bot._client.write('update_command_block', { + command: command.substring(0, 32767), + location, + mode: 1, + flags: 5 + }); + + bot.core.incrementCurrentBlock(); + } } }, - - runTracked (command) { - const transactionId = Math.floor(Math.random() * 1000); - const location = bot.core.currentBlock(); - if (!location) return; - - if (bot.position.y !== bot.core.position.y) { - bot.chat.command(`minecraft:tp ${bot.core.position.x} ${bot.core.position.y} ${bot.core.position.z}`) - } - - bot._client.write('update_command_block', { - command: command.substring(0, 32767), - location, - flags: 5, - mode: 1, -// LastOutput: true, - }); - - bot.core.incrementCurrentBlock(); - - bot._client.write('query_block_nbt', { - location, - transactionId - }); - - bot.on('packet.nbt_query_response', (data) => { -// transactionId, - try { - if (data.transactionId === transactionId) { - bot.tellraw("@a", require('util').inspect(data.value)) - bot.tellraw("@a", JSON.stringify(data.value)) - } - } catch (e) { - bot.tellraw("@a", require("util").inspect(e.stack)); - } - }) - } } if (bot.options.isSavage || bot.options.isCreayun) return @@ -174,11 +187,11 @@ function core (context) { bot.on('packet.block_change', (data) => { // console.log('data pos ' + JSON.stringify(data.location)) // console.log('core pos ' +JSON.stringify(bot.core.position)); - if (data.type === 0) { + // if (data.type === 0) { // console.log('data pos ' + JSON.stringify(data.location)); // console.log('core position ' + JSON.stringify(bot.core.position)); // bot.core.refill(); - } + //} }) } module.exports = core; diff --git a/src/modules/command_manager.js b/src/modules/command_manager.js index 616fb4e..bceae80 100644 --- a/src/modules/command_manager.js +++ b/src/modules/command_manager.js @@ -57,7 +57,7 @@ async function command_manager (context) { break; case 1: if (source?.sources?.discord) { - const hasRole = roles?.some(role => role.name === `${config.discord.roles.trusted}` || role.name === `${config.discord.roles.admin}` || role.name === `${config.discord.roles.owner}`) + const hasRole = roles?.some(role => role.name === `${config.discord.roles.trusted}` || role.name === `${config.discord.roles.admin}` || role.name === `${config.discord.roles.fullAccess}` || role.name === `${config.discord.roles.owner}`) if (!hasRole) throw new CommandError({ translate: 'You are not trusted or the owner!', color: "dark_red" }) } else if (!source?.sources.console) { if (args.length === 0) throw new CommandError({ text: "Please provide a trusted, admin or owner hash", color: "dark_red" }); @@ -66,7 +66,7 @@ async function command_manager (context) { break; case 2: if (source?.sources?.discord) { - const hasRole = roles?.some(role => role.name === `${config.discord.roles.admin}` || role.name === `${config.discord.roles.owner}`) + const hasRole = roles?.some(role => role.name === `${config.discord.roles.admin}` || role.name === `${config.discord.roles.fullAccess}` ||role.name === `${config.discord.roles.owner}`) if (!hasRole) throw new CommandError({ translate: 'You are not trusted or the owner!', color: "dark_red" }) } else if (!source?.sources?.console) { if (args.length === 0) throw new CommandError({ text: "Please provide an admin or owner hash", color: 'dark_red' }) @@ -75,7 +75,7 @@ async function command_manager (context) { break; case 3: if (source?.sources?.discord) { - const hasRole = roles?.some(role => role.name === `${config.discord.roles.owner}`) + const hasRole = roles?.some(role => role.name === `${config.discord.roles.owner}` || role.name === `${config.discord.roles.fullAccess}`) if (!hasRole) throw new CommandError({ translate: 'You are not the owner!', color: "dark_red" }) } else if (!source?.sources?.console) { if (args.length === 0 && bot.validation.owner) throw new CommandError({ text: "Please provide an owner hash", color: "dark_red" }) diff --git a/src/modules/console.js b/src/modules/console.js index c19abf7..7a5b1bb 100644 --- a/src/modules/console.js +++ b/src/modules/console.js @@ -93,7 +93,7 @@ function Console (context) { 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++ }) -// console.log(ratelimit) + bot.on('bossBar', (message) => { if (!options.logging) return; if (ratelimit > 10) return; diff --git a/src/modules/discord.js b/src/modules/discord.js index b31a880..8731171 100644 --- a/src/modules/discord.js +++ b/src/modules/discord.js @@ -42,7 +42,7 @@ function discord (context) { try { bot?.discord?.channel?.send(`\`\`\`ansi\n${discordQueue.join('\n').substring(0, 1984)}\n\`\`\``) } catch (error) { - bot.console.warn(error.toString()) + console.error(error.toString()) } discordQueue = [] }, 2000) diff --git a/src/modules/player_list.js b/src/modules/player_list.js index d82bd6e..baaa3fe 100644 --- a/src/modules/player_list.js +++ b/src/modules/player_list.js @@ -18,19 +18,20 @@ function player_list (context) { action(entry) } } - + bot.emit("player_info", packet); }) bot.on('packet.player_remove', async ({players}) => { // players has uuids of the players let player_completion = (await bot.tab_complete('scoreboard players add ')).filter(_ => _.tooltip == undefined) // exclude @a, @r, @s, @e, @p -aaa bot.players.forEach(async player => { - if(!players.includes(player.uuid)) return + if (!players.includes(player.uuid)) return const a = player_completion.filter(_ => _.match == player.profile.name) - if(a.length >= 1) { - player.vanished = true + if (a.length >= 1) { + player.vanished = true; } else { - bot.players = bot.players.filter(_ => _.uuid != player.uuid) + bot.players = bot.players.filter(_ => _.uuid != player.uuid); + bot.emit("player_left", player); } }) }) @@ -47,6 +48,11 @@ function player_list (context) { displayName: undefined, vanished: false }) + if (entry.vanished) { + bot.emit("player_vanished", entry); + } else { + bot.emit("player_joined", entry); + } } function initializeChat (entry) { diff --git a/src/modules/position.js b/src/modules/position.js index 4dece6f..367ac4e 100644 --- a/src/modules/position.js +++ b/src/modules/position.js @@ -1,14 +1,13 @@ - function position (context) { const bot = context.bot; - bot.position = null + bot.position = null; bot.on('packet.position', packet => { bot.position = { x: packet.flags & 1 ? (this.x + packet.x) : packet.x, y: packet.flags & 2 ? (this.y + packet.y) : packet.y, z: packet.flags & 4 ? (this.z + packet.z) : packet.z - } + }; bot._client.write('teleport_confirm', { teleportId: packet.teleportId }) diff --git a/src/modules/selfcare.js b/src/modules/selfcare.js index 5927657..36cc7a5 100644 --- a/src/modules/selfcare.js +++ b/src/modules/selfcare.js @@ -1,3 +1,5 @@ +const sleep = require('../util/sleep'); + function selfcare (context) { const bot = context.bot; const config = context.config; @@ -17,8 +19,6 @@ function selfcare (context) { let register = false; let positionCount = 0; bot.vanished = true - // You now have the tag: &8[&bPrefix&8: &3~&8] - // You no longer have a tag bot.on('systemChat', (message) => { const stringMessage = bot.getMessageAsPrismarine(message)?.toString(); if (options.isSavage) { @@ -32,17 +32,8 @@ function selfcare (context) { else if (stringMessage === "You're already logged in!") register = false; else if (stringMessage === "Successful login!") register = false; -/* -You're already logged in! -Please, register to the server with the command: /register -Please, login with the command: /login -Successfully registered! -Successful login! -You already have registered this username! -*/ } else if (options.isKaboom) { -// const stringMessage = bot.getMessageAsPrismarine(message)?.toString(); if (stringMessage === "Successfully enabled CommandSpy") commandSpy = true; else if (stringMessage === "Successfully enabled CommandSpy.") commandSpy = true; else if (stringMessage === "Successfully disabled CommandSpy") commandSpy = false; @@ -96,31 +87,54 @@ You already have registered this username! } }, 1000) }) - - bot.on("packet.teams", (data) => { +/* + bot.on("packet.teams", async (data) => { if (options.isSavage || options.isCreayun) return; try { -/* - if (data.team !== "FNFBoyfriendBot") { - bot.chat.command(`minecraft:team add FNFBoyfriendBot`); +// console.log(data); +// bot.chat.command('minecraft:team add FNFBoyfriendBot'); +// if (data.team === "FNFBoyfriendBot") return; + if (data.team === "FNFBoyfriendBot" && data.mode === 1) { + bot.core.run("minecraft:team add FNFBoyfriendBot"); } - if (data.mode > 1 && !data.team === "FNFBoyfriendBot") { - bot.chat.command(`minecraft:team add FNFBoyfriendBot`); + + for (const eachPlayer of data?.players) { + if (eachPlayer !== bot.options.username) { + bot.core.run("minecraft:team empty FNFBoyfriendBot"); + await sleep(100); + bot.core.run("minecraft:team join FNFBoyfriendBot"); + } } - if (data.team === "FNFBoyfriendBot") { - console.log(data); - } -*/ } catch (e) { console.log(e.stack) } - }) + })*/ +/* + { + team: 'FNFBoyfriendBot', + mode: 3, + name: undefined, + friendlyFire: undefined, + nameTagVisibility: undefined, + collisionRule: undefined, + formatting: undefined, + prefix: undefined, + suffix: undefined, + players: [ 'Parker2991' ] +} +*/ + let timer; - bot.on('packet.login', (packet) => { + bot.on('packet.login', async (packet) => { entityId = packet.entityId; gameMode = packet.gameMode; clientLock = packet.gameMode; +/* if (bot.options.isKaboom) { + bot.core.run('minecraft:team add FNFBoyfriendBot'); + await sleep(100); + bot.core.run('minecraft:team join FNFBoyfriendBot'); + }*/ timer = setInterval(() => { if (bot.options.isSavage && !bot.options.isKaboom && !bot.options.isCreayun) { if (login) bot.chat.command('login amogusissus'); diff --git a/src/modules/tab_complete.js b/src/modules/tab_complete.js index c0712b6..5e55387 100644 --- a/src/modules/tab_complete.js +++ b/src/modules/tab_complete.js @@ -9,9 +9,9 @@ module.exports = (context) => { }) const tab_completeH = (packet) => { bot._client.removeListener('tab_complete', tab_completeH) - resolve(packet.matches) - } - bot._client.once('tab_complete', tab_completeH) - }) + resolve(packet.matches) + } + bot._client.once('tab_complete', tab_completeH) + }) } } diff --git a/src/modules/team.js b/src/modules/team.js new file mode 100644 index 0000000..1884ee9 --- /dev/null +++ b/src/modules/team.js @@ -0,0 +1,52 @@ +const sleep = require('../util/sleep'); + +module.exports = (context) => { + const bot = context.bot; + const options = context.options; + const config = context.config; + + bot.on("packet.login", async () => { + if (options.isKaboom) { + 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) => { + if (options.isSavage || options.isCreayun) return; + try { + if (data.team === config.team.name) { +// console.log(data); + 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) + } + }) +} diff --git a/src/util/ChatParsers/Creayun.js b/src/util/ChatParsers/Creayun.js index d363319..0b1de86 100644 --- a/src/util/ChatParsers/Creayun.js +++ b/src/util/ChatParsers/Creayun.js @@ -1,6 +1,7 @@ const ChatMessage = require('prismarine-chat')('1.20.2'); const util = require('util'); function creayun (messageobj, data) { + try { let match; let sender; const stringify = message => new ChatMessage(message).toString() @@ -21,5 +22,8 @@ function creayun (messageobj, data) { // console.log(sender) return { sender, contents: match[3], type: 'minecraft:chat'}; } + } catch (e) { + console.log(e.toString()) + } } module.exports = creayun; diff --git a/src/util/ChatParsers/VanillaChat.js b/src/util/ChatParsers/VanillaChat.js index bdf96e5..510a8f3 100644 --- a/src/util/ChatParsers/VanillaChat.js +++ b/src/util/ChatParsers/VanillaChat.js @@ -14,10 +14,10 @@ function VanillaChat (message, data, context) { const stringUsername = data.getMessageAsPrismarine(senderComponent).toString() // TypeError: data.getMessageAsPrismarine is not a function sender = data.players.find(player => player.profile.name === stringUsername) } - if (!sender) return stringUsername + if (!sender) return //stringUsername return { sender, contents, type: 'minecraft:chat', senderComponent } } catch(e) { - console.error(`${e.toString()}`) + console.error(`${e.stack}`) } } module.exports = VanillaChat;