From 422db19bdb2165c10510aa2bf66c08e1261481bd Mon Sep 17 00:00:00 2001 From: Parker2991 Date: Fri, 22 Aug 2025 11:52:57 -0500 Subject: [PATCH] reverted back to components and other stuff --- package-lock.json | 50 +++++ package.json | 1 + src/bot.js | 10 +- src/chat_parsers/chipmunkmod.js | 47 +++-- src/chat_parsers/creayun.js | 7 +- src/chat_parsers/kaboom.js | 69 ++++--- src/chat_parsers/vanilla.js | 8 +- src/command_util/command_context.js | 2 +- src/command_util/command_error.js | 4 +- src/command_util/command_source.js | 2 +- src/command_util/command_trust_level.js | 2 +- src/commands.old/console/console.js | 2 +- src/commands.old/public/core.js | 4 +- src/commands.old/public/info.js | 9 +- src/commands.old/public/mcserver.js | 7 +- src/commands.old/public/netmsg.js | 4 +- src/commands.old/public/refillcore.js | 4 +- src/commands.old/public/urban.js | 52 ++--- src/commands.old/public/wiki.js | 4 +- src/commands.old/trusted/cloop.js | 9 +- src/commands/admin/kick.js | 19 +- src/commands/console/console.js | 29 +-- src/commands/owner/kill.js | 13 +- src/commands/public/core.js | 26 +-- src/commands/public/echo.js | 15 +- src/commands/public/help.js | 166 +++------------ src/commands/public/info.js | 42 ++-- src/commands/public/list.js | 51 +++++ src/commands/public/mcserver.js | 51 +++++ src/commands/public/refillcore.js | 19 +- src/commands/public/test.js | 47 +++++ src/commands/trusted/auth.js | 81 ++++---- src/commands/trusted/cloop.js | 23 ++- src/commands/trusted/reconnect.js | 19 +- src/commands/trusted/validate.js | 50 +++-- src/help-layout.txt | 5 - src/index.js | 20 +- src/modules/auth.js | 34 ++-- src/modules/boot.js | 7 - src/modules/chat.js | 180 ++++++++++------- src/modules/command_core.js | 44 ++-- src/modules/command_handler.js | 24 ++- src/modules/command_loop.js | 2 +- src/modules/command_manager.js | 252 ++++++++++++----------- src/modules/command_spy.js | 66 +++--- src/modules/console.js | 39 +++- src/modules/custom_channel_test.js | 55 +++++ src/modules/discord.js | 2 +- src/modules/player_list.js | 8 +- src/modules/reconnect.js | 2 +- src/modules/registry.js | 2 +- src/modules/selfcare.js | 141 ++++++++----- src/modules/tab_complete.js | 2 +- src/ownerCheck.js | 55 +++-- src/plugins/database.js | 6 +- src/plugins/validation.js | 2 +- src/selfcare.js.old | 255 ------------------------ src/selfcare/auth/login.js | 16 ++ src/selfcare/auth/register.js | 17 ++ src/selfcare/entity/gamemode.js | 14 +- src/selfcare/entity/icu.js | 21 +- src/selfcare/entity/op.js | 13 +- src/selfcare/essentials/god.js | 5 +- src/selfcare/essentials/mute.js | 13 +- src/selfcare/essentials/nickname.js | 10 +- src/selfcare/essentials/vanish.js | 10 +- src/selfcare/extras/command_spy.js | 19 +- src/selfcare/extras/prefix.js | 27 ++- src/selfcare/extras/username.js | 31 +-- src/util/ansi.js | 2 +- src/util/between.js | 2 +- src/util/loadModules.js | 4 +- src/util/loadPlugins.js | 4 +- 73 files changed, 1236 insertions(+), 1123 deletions(-) create mode 100644 src/commands/public/list.js create mode 100644 src/commands/public/mcserver.js create mode 100644 src/commands/public/test.js delete mode 100644 src/help-layout.txt delete mode 100644 src/modules/boot.js create mode 100644 src/modules/custom_channel_test.js delete mode 100644 src/selfcare.js.old create mode 100644 src/selfcare/auth/login.js create mode 100644 src/selfcare/auth/register.js diff --git a/package-lock.json b/package-lock.json index ce5a88e..8c916ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "axios": "^1.11.0", "discord.js": "^14.21.0", "js-yaml": "^4.1.0", + "mariadb": "^3.4.5", "matrix-js-sdk": "^36.2.0", "minecraft-data": "^3.95.1", "minecraft-protocol": "^1.60.1", @@ -428,6 +429,12 @@ "integrity": "sha512-trOc4AAUThEz9hapPtSd7wf5tiQKvTtu5b371UxXdTuqzIh0ArcRspRP0i0Viu+LXstIQ1z96t1nsPxT9ol01g==", "license": "MIT" }, + "node_modules/@types/geojson": { + "version": "7946.0.16", + "resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.16.tgz", + "integrity": "sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==", + "license": "MIT" + }, "node_modules/@types/node": { "version": "24.2.1", "resolved": "https://registry.npmjs.org/@types/node/-/node-24.2.1.tgz", @@ -789,6 +796,15 @@ "node": ">=0.4.0" } }, + "node_modules/denque": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/denque/-/denque-2.1.0.tgz", + "integrity": "sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==", + "license": "Apache-2.0", + "engines": { + "node": ">=0.10" + } + }, "node_modules/discontinuous-range": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/discontinuous-range/-/discontinuous-range-1.0.0.tgz", @@ -1158,6 +1174,18 @@ "npm": ">=1.3.7" } }, + "node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", @@ -1385,6 +1413,12 @@ "url": "https://tidelift.com/funding/github/npm/loglevel" } }, + "node_modules/lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", + "license": "ISC" + }, "node_modules/macaddress": { "version": "0.5.3", "resolved": "https://registry.npmjs.org/macaddress/-/macaddress-0.5.3.tgz", @@ -1397,6 +1431,22 @@ "integrity": "sha512-ThQLOhN86ZkJ7qemtVRGYM+gRgR8GEXNli9H/PMvpnZsE44Xfh3wx9kGJaldg314v85m+bFW6WBMaVHJc/c3zA==", "license": "MIT" }, + "node_modules/mariadb": { + "version": "3.4.5", + "resolved": "https://registry.npmjs.org/mariadb/-/mariadb-3.4.5.tgz", + "integrity": "sha512-gThTYkhIS5rRqkVr+Y0cIdzr+GRqJ9sA2Q34e0yzmyhMCwyApf3OKAC1jnF23aSlIOqJuyaUFUcj7O1qZslmmQ==", + "license": "LGPL-2.1-or-later", + "dependencies": { + "@types/geojson": "^7946.0.16", + "@types/node": "^24.0.13", + "denque": "^2.1.0", + "iconv-lite": "^0.6.3", + "lru-cache": "^10.4.3" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", diff --git a/package.json b/package.json index 7188d40..feb1aae 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "axios": "^1.11.0", "discord.js": "^14.21.0", "js-yaml": "^4.1.0", + "mariadb": "^3.4.5", "matrix-js-sdk": "^36.2.0", "minecraft-data": "^3.95.1", "minecraft-protocol": "^1.60.1", diff --git a/src/bot.js b/src/bot.js index c1a3465..6f998e5 100644 --- a/src/bot.js +++ b/src/bot.js @@ -6,7 +6,7 @@ let disconnectCount = 0; EventEmitter.defaultMaxListeners = Infinity; class Bot { - constructor (options = {}, config) { + constructor(options = {}, config) { const bot = new EventEmitter(); bot.options = { // Set some default values in options @@ -26,6 +26,8 @@ class Bot { bot.uuid = client.uuid; bot.username = client.username; bot.loggedIn = true; + disconnectCount = 0; + bot.reconnectDelay = options.reconnectDelay; }); client.on("disconnect", (data) => { @@ -83,11 +85,6 @@ class Bot { process.on("uncaughtException", (e) => { bot.console.warn(`${e.stack}`); }); - - client.on("success", () => { - disconnectCount = 0; - bot.reconnectDelay = options.reconnectDelay; - }); }); const client = options.client ?? new mc.createClient(bot.options); @@ -98,4 +95,3 @@ class Bot { } } module.exports = Bot; - diff --git a/src/chat_parsers/chipmunkmod.js b/src/chat_parsers/chipmunkmod.js index d278dbf..13375c3 100644 --- a/src/chat_parsers/chipmunkmod.js +++ b/src/chat_parsers/chipmunkmod.js @@ -1,27 +1,42 @@ -function chipmunkmod (message, data, context, bot) { +function chipmunkmod(message, data, context, bot) { try { - if (message === null || typeof message !== 'object') return - if (message.with?.length < 3 || (message.translate !== '[%s] %s › %s' && message.translate !== '%s %s › %s')) return + if (message === null || typeof message !== "object") return; + if ( + message.with?.length < 3 || + (message.translate !== "[%s] %s › %s" && + message.translate !== "%s %s › %s") + ) + return; - const senderComponent = message.with[1] - const contents = message.with[2] - let sender - const hoverEvent = senderComponent.hoverEvent - if (hoverEvent?.action === 'show_entity') { - const id = hoverEvent.contents.id + const senderComponent = message.with[1]; + const contents = message.with[2]; + let sender; + const hoverEvent = senderComponent.hoverEvent; + if (hoverEvent?.action === "show_entity") { + const id = hoverEvent.contents.id; - sender = data.players.find(player => player.uuid === id) + sender = data.players.find((player) => player.uuid === id); } else { - const stringUsername = data.getMessageAsPrismarine(senderComponent).toString() // TypeError: data.getMessageAsPrismarine is not a function + const stringUsername = data + .getMessageAsPrismarine(senderComponent) + .toString(); // TypeError: data.getMessageAsPrismarine is not a function - sender = data.players.find(player => player.profile.name === stringUsername) + sender = data.players.find( + (player) => player.profile.name === stringUsername, + ); } if (!sender) return null; - return { sender, contents, type: 'minecraft:chat', chatType: ["system"], senderComponent } - } catch(e) { - console.error(e) + return { + sender, + contents, + type: "minecraft:chat", + chatType: ["system"], + senderComponent, + }; + } catch (e) { + console.error(e); } } -module.exports = chipmunkmod +module.exports = chipmunkmod; diff --git a/src/chat_parsers/creayun.js b/src/chat_parsers/creayun.js index 27ff69f..c8b30f5 100644 --- a/src/chat_parsers/creayun.js +++ b/src/chat_parsers/creayun.js @@ -12,7 +12,12 @@ function parseMessage(messageobj, data) { match = message.match(playerWithPrefix); sender = data.players.find((player) => player.profile.name === match[2]); - return { sender, contents: match[3], chatType: "player", type: "minecraft:chat" }; + return { + sender, + contents: match[3], + chatType: "player", + type: "minecraft:chat", + }; } } catch (e) { console.log(e.stack); diff --git a/src/chat_parsers/kaboom.js b/src/chat_parsers/kaboom.js index c89908b..da31b53 100644 --- a/src/chat_parsers/kaboom.js +++ b/src/chat_parsers/kaboom.js @@ -1,43 +1,60 @@ -const util = require('util') +const util = require("util"); -function kaboom (message, data) { - if (message === null || typeof message !== 'object') return +function kaboom(message, data) { + if (message === null || typeof message !== "object") return; - if (message.text !== '' || !Array.isArray(message.extra) || message.extra.length < 3) return - - const children = message.extra + if ( + message.text !== "" || + !Array.isArray(message.extra) || + message.extra.length < 3 + ) + return; - const prefix = children[0] - let displayName = data.senderName ?? { text: '' } - let contents = { text: '' } + const children = message.extra; - if (isSeparatorAt(children, 1)) { // Missing/blank display name - if (children.length > 3) contents = children[3] + const prefix = children[0]; + let displayName = data.senderName ?? { text: "" }; + let contents = { text: "" }; + + if (isSeparatorAt(children, 1)) { + // Missing/blank display name + if (children.length > 3) contents = children[3]; } else if (isSeparatorAt(children, 2)) { - displayName = children[1] - if (children.length > 4) contents = children[4] + displayName = children[1]; + if (children.length > 4) contents = children[4]; } else { - return undefined + return undefined; } - const playerListDisplayName = { extra: [prefix, displayName], text: '' } - let sender + const playerListDisplayName = { extra: [prefix, displayName], text: "" }; + let sender; if (data.uuid) { - sender = data.players.find(player => player.uuid === data.senderUuid) + sender = data.players.find((player) => player.uuid === data.senderUuid); } else { - const playerListDisplayName = { extra: [prefix, displayName], text: '' } + const playerListDisplayName = { extra: [prefix, displayName], text: "" }; - sender = data.players.find(player => util.isDeepStrictEqual(player.displayName, playerListDisplayName)) + sender = data.players.find((player) => + util.isDeepStrictEqual(player.displayName, playerListDisplayName), + ); } - - if (!sender) return undefined - - return { sender, contents, type: 'minecraft:chat', chatType: ["player", "profileless"], displayName } + + if (!sender) return undefined; + + return { + sender, + contents, + type: "minecraft:chat", + chatType: ["player", "profileless"], + displayName, + }; } -function isSeparatorAt (children, start) { - return (children[start]?.text === ':' || children[start]?.text === '\xa7f:') && children[start + 1]?.text === ' ' +function isSeparatorAt(children, start) { + return ( + (children[start]?.text === ":" || children[start]?.text === "\xa7f:") && + children[start + 1]?.text === " " + ); } -module.exports = kaboom +module.exports = kaboom; diff --git a/src/chat_parsers/vanilla.js b/src/chat_parsers/vanilla.js index 43af0a9..cc07def 100644 --- a/src/chat_parsers/vanilla.js +++ b/src/chat_parsers/vanilla.js @@ -23,7 +23,13 @@ function parseMessage(message, data, context) { ); } if (!sender) return; //stringUsername - return { sender, contents, type: "minecraft:chat", chatType: ["player", "profileless"], senderComponent }; + return { + sender, + contents, + type: "minecraft:chat", + chatType: ["player", "profileless"], + senderComponent, + }; } catch (e) { console.error(`${e.stack}`); } diff --git a/src/command_util/command_context.js b/src/command_util/command_context.js index 6216c3b..03340d0 100644 --- a/src/command_util/command_context.js +++ b/src/command_util/command_context.js @@ -6,7 +6,7 @@ class CommandContext { this.data.description = description; this.data.trustLevel = trustLevel; this.data.usages = usages; - this.data.playerOnly = playerOnly + this.data.playerOnly = playerOnly; } } module.exports = CommandContext; diff --git a/src/command_util/command_error.js b/src/command_util/command_error.js index 809c643..a954ab3 100644 --- a/src/command_util/command_error.js +++ b/src/command_util/command_error.js @@ -14,5 +14,5 @@ class CommandError extends Error { get message() { return stringify(this._message); } -}; -module.exports = CommandError \ No newline at end of file +} +module.exports = CommandError; diff --git a/src/command_util/command_source.js b/src/command_util/command_source.js index 345f722..3a51e01 100644 --- a/src/command_util/command_source.js +++ b/src/command_util/command_source.js @@ -2,7 +2,7 @@ class CommandSource { constructor(player, sources, ChatType) { this.player = player; this.sources = sources; - this.ChatType = ChatType + this.ChatType = ChatType; this.player.hash = null; } } diff --git a/src/command_util/command_trust_level.js b/src/command_util/command_trust_level.js index 460c1af..c1bcfbe 100644 --- a/src/command_util/command_trust_level.js +++ b/src/command_util/command_trust_level.js @@ -7,4 +7,4 @@ class command_trust_level { disabled = 5; } -module.exports = command_trust_level; \ No newline at end of file +module.exports = command_trust_level; diff --git a/src/commands.old/console/console.js b/src/commands.old/console/console.js index 300a3b9..99af13e 100644 --- a/src/commands.old/console/console.js +++ b/src/commands.old/console/console.js @@ -1,5 +1,5 @@ const CommandContext = require("../../command_util/command_context"); -const CommandError = require('../../command_util/command_error') +const CommandError = require("../../command_util/command_error"); class ConsoleCommand extends CommandContext { constructor() { diff --git a/src/commands.old/public/core.js b/src/commands.old/public/core.js index a0a51ed..ff6370d 100644 --- a/src/commands.old/public/core.js +++ b/src/commands.old/public/core.js @@ -12,7 +12,7 @@ class core extends CommandContext { execute(context) { const bot = context.bot; const args = context.arguments; - const source = context.source + const source = context.source; if (args.includes("$username") || args.includes("$uuid")) { bot.players.forEach((eachPlayer) => { @@ -21,7 +21,7 @@ class core extends CommandContext { .join(" ") .replaceAll("$username", eachPlayer.profile.name) .replaceAll("$uuid", eachPlayer.uuid), - source + source, ); // await sleep(1000) }); diff --git a/src/commands.old/public/info.js b/src/commands.old/public/info.js index accf732..88e7885 100644 --- a/src/commands.old/public/info.js +++ b/src/commands.old/public/info.js @@ -321,7 +321,7 @@ class InfoCommand extends CommandContext { color: config.colors.commands.primary, }, { - text: `${(Math.floor(os.totalmem() / 1048576) - Math.floor(os.freemem() / 1048576))}`, + text: `${Math.floor(os.totalmem() / 1048576) - Math.floor(os.freemem() / 1048576)}`, color: config.colors.integer, }, { text: "MB", color: config.colors.commands.secondary }, @@ -343,7 +343,7 @@ class InfoCommand extends CommandContext { color: config.colors.commands.primary, }, { - text: `${(Math.floor(os.totalmem() / 1048576) - Math.floor(os.freemem() / 1048576))}`, + text: `${Math.floor(os.totalmem() / 1048576) - Math.floor(os.freemem() / 1048576)}`, color: config.colors.integer, }, { text: "MB", color: config.colors.commands.secondary }, @@ -480,7 +480,10 @@ class InfoCommand extends CommandContext { { text: "CPU cores", color: config.colors.commands.primary }, { text: `${os.cpus().length}`, color: config.colors.integer }, { text: "Processes", color: config.colors.commands.primary }, - { text: `${execSync("ps aux | wc -l").toString().replace('\n','')}`, color: config.colors.integer }, + { + text: `${execSync("ps aux | wc -l").toString().replace("\n", "")}`, + color: config.colors.integer, + }, { text: "Node Version", color: config.colors.commands.primary }, { text: `${process.version}`, diff --git a/src/commands.old/public/mcserver.js b/src/commands.old/public/mcserver.js index cbf3718..ef3f6ed 100644 --- a/src/commands.old/public/mcserver.js +++ b/src/commands.old/public/mcserver.js @@ -38,16 +38,15 @@ class McserverCommand extends CommandContext { ], }); - if (source.sources.console) { bot.console.info(bot.getMessageAsPrismarine(component)?.toAnsi()); } else { bot.tellraw("@a", component); } } catch (e) { - console.log(e.stack) + console.log(e.stack); bot.chat.message(`${e.toString()}`); } } -}; -module.exports = McserverCommand \ No newline at end of file +} +module.exports = McserverCommand; diff --git a/src/commands.old/public/netmsg.js b/src/commands.old/public/netmsg.js index d40b659..5c832e7 100644 --- a/src/commands.old/public/netmsg.js +++ b/src/commands.old/public/netmsg.js @@ -61,5 +61,5 @@ class NetmsgCommand extends CommandContext { eachBot.tellraw("@a", component); } } -}; -module.exports = NetmsgCommand \ No newline at end of file +} +module.exports = NetmsgCommand; diff --git a/src/commands.old/public/refillcore.js b/src/commands.old/public/refillcore.js index abfae39..4a90567 100644 --- a/src/commands.old/public/refillcore.js +++ b/src/commands.old/public/refillcore.js @@ -10,5 +10,5 @@ class RefillcoreCommand extends CommandContext { bot.core.move(bot.position); bot.tellraw("@a", "Refilling core,..."); } -}; -module.exports = RefillcoreCommand +} +module.exports = RefillcoreCommand; diff --git a/src/commands.old/public/urban.js b/src/commands.old/public/urban.js index 1975553..a28094b 100644 --- a/src/commands.old/public/urban.js +++ b/src/commands.old/public/urban.js @@ -2,9 +2,9 @@ const CommandError = require("../../command_util/command_error"); const { request } = require("undici"); const CommandContext = require("../../command_util/command_context"); const fixansi = require("../../util/ansi"); -const fs = require('fs') -const path = require('path') -const { AttachmentBuilder } = require('discord.js') +const fs = require("fs"); +const path = require("path"); +const { AttachmentBuilder } = require("discord.js"); class UrbanCommand extends CommandContext { constructor() { @@ -84,36 +84,38 @@ class UrbanCommand extends CommandContext { if (source.sources.console) { bot.console.info(bot.getMessageAsPrismarine(component)?.toAnsi()); } else if (source.sources.discord) { - - const discordOutput = fixansi(bot.getMessageAsPrismarine(component)?.toAnsi()) + const discordOutput = fixansi( + bot.getMessageAsPrismarine(component)?.toAnsi(), + ); if (discordOutput.length > 2000) { - const output = fs.writeFileSync(path.join(__dirname, '../../output.txt'), JSON.stringify(bot.getMessageAsPrismarine(component)?.toString())) - - const file = new AttachmentBuilder(path.join(__dirname, '../../output.txt')) - - bot.discord.message.reply('output', { - files: [file] - }) -// bot.discord.message.reply('meow') //[{ -// files: path.join(__dirname, '../../output.txt') - // }]) - - - -// fs.unlinkSync(path.join(__dirname, '../../output.txt')) - } else { - bot.discord.message.reply( - `\`\`\`ansi\n${discordOutput}\`\`\``, + const output = fs.writeFileSync( + path.join(__dirname, "../../output.txt"), + JSON.stringify(bot.getMessageAsPrismarine(component)?.toString()), ); + + const file = new AttachmentBuilder( + path.join(__dirname, "../../output.txt"), + ); + + bot.discord.message.reply("output", { + files: [file], + }); + // bot.discord.message.reply('meow') //[{ + // files: path.join(__dirname, '../../output.txt') + // }]) + + // fs.unlinkSync(path.join(__dirname, '../../output.txt')) + } else { + bot.discord.message.reply(`\`\`\`ansi\n${discordOutput}\`\`\``); } -// console.log(discordOutput.length) + // console.log(discordOutput.length) } else if (bot.options.mode === "savageFriends") { bot.core.run(`minecraft:tellraw @a ${JSON.stringify(component)}`); } else { bot.tellraw(`@a`, component); } } -}; +} -module.exports = UrbanCommand \ No newline at end of file +module.exports = UrbanCommand; diff --git a/src/commands.old/public/wiki.js b/src/commands.old/public/wiki.js index e752905..a701666 100644 --- a/src/commands.old/public/wiki.js +++ b/src/commands.old/public/wiki.js @@ -34,9 +34,7 @@ class WikiCommand extends CommandContext { e.toString() === "pageError: TypeError: Cannot read properties of undefined (reading 'pages')" ) { - bot.tellraw("@a", - { text: "no article found!", color: "red" } - ) + bot.tellraw("@a", { text: "no article found!", color: "red" }); } else { bot.tellraw(`@a`, `${e.toString()}`); } diff --git a/src/commands.old/trusted/cloop.js b/src/commands.old/trusted/cloop.js index 16af6a5..2b449c2 100644 --- a/src/commands.old/trusted/cloop.js +++ b/src/commands.old/trusted/cloop.js @@ -15,13 +15,13 @@ class CloopCommand extends CommandContext { const bot = context.bot; const config = context.config; const source = context.source; - let args + let args; let component = []; if (!source.sources.console && !source.sources.discord) { - args = context.arguments.slice(16) + args = context.arguments.slice(16); } else { - args = context.arguments + args = context.arguments; } if ( @@ -97,9 +97,8 @@ class CloopCommand extends CommandContext { } if (source.sources.discord) { - } else if (source.sources.console) { - bot.console.info(component) + bot.console.info(component); } else { bot.tellraw("@a", component); } diff --git a/src/commands/admin/kick.js b/src/commands/admin/kick.js index 51cd10d..6bc14d9 100644 --- a/src/commands/admin/kick.js +++ b/src/commands/admin/kick.js @@ -1,17 +1,18 @@ const CommandError = require("../../command_util/command_error"); const CommandContext = require("../../command_util/command_context"); -const CommandTrustLevel = require('../../command_util/command_trust_level') -const trustLevel = new CommandTrustLevel() +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); class kick extends CommandContext { constructor() { - super("kick", [], "kick a player from the server", trustLevel.admin, [ - "invalidstring", - "item", - "te", - ], - false - ); + super( + "kick", + [], + "kick a player from the server", + trustLevel.admin, + ["invalidstring", "item", "te"], + false, + ); } execute(context) { const bot = context.bot; diff --git a/src/commands/console/console.js b/src/commands/console/console.js index 26a51c2..1f5e86a 100644 --- a/src/commands/console/console.js +++ b/src/commands/console/console.js @@ -1,19 +1,24 @@ const CommandContext = require("../../command_util/command_context"); -const CommandError = require('../../command_util/command_error') -const CommandTrustLevel = require('../../command_util/command_trust_level') -const trustLevel = new CommandTrustLevel() +const CommandError = require("../../command_util/command_error"); +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); class console extends CommandContext { constructor() { - super("console", ["c"], "runs commands made for the bots console", trustLevel.console, [ - "server/srv ", - "customchat ", - "say ", - "validate/validation/val ", - "logging/togglelogging/logtoconsole ", - ], - false - ); + super( + "console", + ["c"], + "runs commands made for the bots console", + trustLevel.console, + [ + "server/srv ", + "customchat ", + "say ", + "validate/validation/val ", + "logging/togglelogging/logtoconsole ", + ], + false, + ); } execute(context) { const bot = context.bot; diff --git a/src/commands/owner/kill.js b/src/commands/owner/kill.js index 1f6edf1..9e9bec0 100644 --- a/src/commands/owner/kill.js +++ b/src/commands/owner/kill.js @@ -1,10 +1,17 @@ const CommandContext = require("../../command_util/command_context"); -const CommandTrustLevel = require('../../command_util/command_trust_level') -const trustLevel = new CommandTrustLevel() +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); class kill extends CommandContext { constructor() { - super("kill", ["suicide", "quit"], "kill the bots process", trustLevel.owner, [""], false); + super( + "kill", + ["suicide", "quit"], + "kill the bots process", + trustLevel.owner, + [""], + false, + ); } execute(context) { const bot = context.bot; diff --git a/src/commands/public/core.js b/src/commands/public/core.js index 8d7930a..f895e98 100644 --- a/src/commands/public/core.js +++ b/src/commands/public/core.js @@ -1,30 +1,23 @@ const sleep = require("../../util/sleep"); const CommandContext = require("../../command_util/command_context"); -const CommandTrustLevel = require('../../command_util/command_trust_level') -const trustLevel = new CommandTrustLevel() +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); class core extends CommandContext { constructor() { - super("core", - [ - "cb", - "cbrun", - "corerun" - ], + super( + "core", + ["cb", "cbrun", "corerun"], "run commands in core", trustLevel.public, - [ - "$username ", - "$uuid ", - "", - ], - false + ["$username ", "$uuid ", ""], + false, ); } execute(context) { const bot = context.bot; const args = context.arguments; - const source = context.source + const source = context.source; if (args.includes("$username") || args.includes("$uuid")) { bot.players.forEach((eachPlayer) => { @@ -33,9 +26,8 @@ class core extends CommandContext { .join(" ") .replaceAll("$username", eachPlayer.profile.name) .replaceAll("$uuid", eachPlayer.uuid), - source + source, ); - // await sleep(1000) }); } else if (bot.options.mode === "savageFriends") { bot.core.run(args.join(" ")); diff --git a/src/commands/public/echo.js b/src/commands/public/echo.js index 2d02740..8c94bfc 100644 --- a/src/commands/public/echo.js +++ b/src/commands/public/echo.js @@ -1,13 +1,16 @@ const CommandContext = require("../../command_util/command_context"); -const CommandTrustLevel = require('../../command_util/command_trust_level') -const trustLevel = new CommandTrustLevel() +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); class echo extends CommandContext { constructor() { - super("echo", ["say", "botsay"], "make me say something!", trustLevel.public, [ - '', - ], - true + super( + "echo", + ["say", "botsay"], + "make me say something!", + trustLevel.public, + [""], + true, ); } diff --git a/src/commands/public/help.js b/src/commands/public/help.js index 64aa7d9..ee21733 100644 --- a/src/commands/public/help.js +++ b/src/commands/public/help.js @@ -11,7 +11,6 @@ class help extends CommandContext { "see a list of commands", trustLevel.public, [""], - false ); } @@ -20,7 +19,6 @@ class help extends CommandContext { const args = context.arguments; const config = context.config; const source = context.source; - const { MessageBuilder } = require('prismarine-chat')('1.20.2'); let component = []; let infoComponent = []; @@ -30,126 +28,30 @@ class help extends CommandContext { let admin = []; let owner = []; let Console = []; - let Commands = []; - function cat () { - return new MessageBuilder() - .setTranslate("(%s | %s | %s | %s)") - .setColor(config.colors.commands.tertiary) - .addWith( - new MessageBuilder() - .setText("Public") - .setColor(config.colors.help.public), - new MessageBuilder() - .setText("Trusted") - .setColor(config.colors.help.trusted), - new MessageBuilder() - .setText("Admin") - .setColor(config.colors.help.admin), - new MessageBuilder() - .setText("Owner") - .setColor(config.colors.help.owner) - ) - } - - function command_count () { - return new MessageBuilder() - .setTranslate("%s: (%s) %s \u203a") - .setColor(config.colors.commands.tertiary) - .addWith( - new MessageBuilder() - .setText("Commands") - .setColor(config.colors.commands.secondary), - new MessageBuilder() - .setText(`${bot.commandManager.commandlist.length}`) - .setColor(config.colors.integer), - cat() - ) - } - -// component.push(command_count() + '\n'); - - for (const commands of bot.commandManager.commandlist) { - switch (commands.data.trustLevel) { - case 0: - Public.push( - new MessageBuilder() - .setText('') - .addExtra( - new MessageBuilder() - .setText(commands.data.name + ' ') - .setColor(config.colors.help.public), - ) - ) - break - case 1: - trusted.push( - new MessageBuilder() - .setText('') - .addExtra( - new MessageBuilder() - .setText(commands.data.name + ' ') - .setColor(config.colors.help.trusted), - ) - ) - break - case 2: - admin.push( - new MessageBuilder() - .setText('') - .addExtra( - new MessageBuilder() - .setText(commands.data.name + ' ') - .setColor(config.colors.help.admin), - ) - ) - break - case 3: - owner.push( - new MessageBuilder() - .setText('') - .addExtra( - new MessageBuilder() - .setText(commands.data.name + ' ') - .setColor(config.colors.help.owner), - ) - ) - break - case 4: - Console.push( - new MessageBuilder() - .setText('') - .addExtra( - new MessageBuilder() - .setText(commands.data.name + ' ') - .setColor(config.colors.help.console), - ) - ) - break - } - - if ( - args[0]?.toLowerCase() === commands.data.name?.toLowerCase() || - commands.data.aliases.find( - (e) => e?.toLowerCase() === args[0]?.toLowerCase(), - ) - ) { - -/* for (const usages of commands.data.usages) { - - }*/ - } - } - if (Public.length > 0) Commands.push(Public, '\n') - if (trusted.length > 0) Commands.push(trusted, '\n') - if (admin.length > 0) Commands.push(admin, '\n') - if (owner.length > 0) Commands.push(owner) - if (source.sources.console && Console.length > 0) Commands.push('\n', Console) - - component.push([command_count(), '\n', Commands]) - bot.tellraw("@a", component) -/* + let cat = { + translate: "(%s | %s | %s | %s)", + color: config.colors.commands.tertiary, + with: [ + { text: "Public", color: config.colors.help.public }, + { text: "Trusted", color: config.colors.help.trusted }, + { text: "Admin", color: config.colors.help.admin }, + { text: "Owner", color: config.colors.help.owner }, + ], + }; + component.push({ + translate: "%s: (%s) %s \u203a\n", + color: config.colors.commands.tertiary, + with: [ + { text: "Commands", color: config.colors.commands.secondary }, + { + text: `${bot.commandManager.commandlist.length}`, + color: config.colors.integer, + }, + cat, + ], + }); for (const commands of bot.commandManager.commandlist) { switch (commands.data.trustLevel) { case 0: @@ -433,6 +335,9 @@ class help extends CommandContext { }); break; default: +/* bot.chat.message( + `fuck you ${commands.data.name} has a invalid trust level`, + );*/ } if ( @@ -491,16 +396,7 @@ class help extends CommandContext { }); infoComponent.push(usagesComponent); - - if (source?.sources.console) { - bot.console.info(bot.getMessageAsPrismarine(infoComponent)?.toAnsi()); - } else if (source.sources.discord) { - bot.discord.message.reply( - `\`\`\`ansi\n${fixansi(bot.getMessageAsPrismarine(infoComponent)?.toAnsi())}\`\`\``, - ); - } else { - bot.tellraw(`@a`, infoComponent); - } + source.sendFeedback(infoComponent) return; } } @@ -528,15 +424,7 @@ class help extends CommandContext { component.push(Console); } - if (source?.sources?.console) { - bot.console.info(bot.getMessageAsPrismarine(component)?.toAnsi()); - } else if (source.sources.discord) { - bot.discord.message.reply( - `\`\`\`ansi\n${fixansi(bot.getMessageAsPrismarine(component)?.toAnsi())}\`\`\``, - ); - } else { - bot.tellraw("@a", component); - }*/ + source.sendFeedback(component) } } diff --git a/src/commands/public/info.js b/src/commands/public/info.js index 1e9407f..7b658ac 100644 --- a/src/commands/public/info.js +++ b/src/commands/public/info.js @@ -5,8 +5,8 @@ const botInfo = require("../../data/info.json"); const fixansi = require("../../util/ansi.js"); const { execSync } = require("child_process"); const CommandContext = require("../../command_util/command_context"); -const CommandTrustLevel = require('../../command_util/command_trust_level') -const trustLevel = new CommandTrustLevel() +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); function format(seconds) { function pad(s) { @@ -26,18 +26,23 @@ function format(seconds) { class info extends CommandContext { constructor() { - super("info", ["information"], "check the bots info", trustLevel.public, [ - "about", - "config ", - "contributors/credits", - "discord", - "loaded", - "usages ", - "uptimes/uptime ", - "server", - "version/ver", - ], - false + super( + "info", + ["information"], + "check the bots info", + trustLevel.public, + [ + "about", + "config ", + "contributors/credits", + "discord", + "loaded", + "usages ", + "uptimes/uptime ", + "server", + "version/ver", + ], + false, ); } @@ -325,7 +330,7 @@ class info extends CommandContext { color: config.colors.commands.primary, }, { - text: `${(Math.floor(os.totalmem() / 1048576) - Math.floor(os.freemem() / 1048576))}`, + text: `${Math.floor(os.totalmem() / 1048576) - Math.floor(os.freemem() / 1048576)}`, color: config.colors.integer, }, { text: "MB", color: config.colors.commands.secondary }, @@ -347,7 +352,7 @@ class info extends CommandContext { color: config.colors.commands.primary, }, { - text: `${(Math.floor(os.totalmem() / 1048576) - Math.floor(os.freemem() / 1048576))}`, + text: `${Math.floor(os.totalmem() / 1048576) - Math.floor(os.freemem() / 1048576)}`, color: config.colors.integer, }, { text: "MB", color: config.colors.commands.secondary }, @@ -484,7 +489,10 @@ class info extends CommandContext { { text: "CPU cores", color: config.colors.commands.primary }, { text: `${os.cpus().length}`, color: config.colors.integer }, { text: "Processes", color: config.colors.commands.primary }, - { text: `${execSync("ps aux | wc -l").toString().replace('\n','')}`, color: config.colors.integer }, + { + text: `${execSync("ps aux | wc -l").toString().replace("\n", "")}`, + color: config.colors.integer, + }, { text: "Node Version", color: config.colors.commands.primary }, { text: `${process.version}`, diff --git a/src/commands/public/list.js b/src/commands/public/list.js new file mode 100644 index 0000000..4a85bcb --- /dev/null +++ b/src/commands/public/list.js @@ -0,0 +1,51 @@ +const CommandError = require("../../command_util/command_error"); +const CommandContext = require("../../command_util/command_context"); +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); + +class list extends CommandContext { + constructor() { + super("list", ["pl", "playerlist"], "check whos online on the server", trustLevel.public, [ + "", + ]); + } + execute(context) { + const bot = context.bot; + const args = context.arguments; + const config = context.config; + const source = context.source; + let component = []; + let infoComponent = []; + let playerCount = []; + + playerCount.push({ + translate: "%s: (%s)\n", + color: config.colors.commands.tertiary, + with: [ + { text: "Players", color: config.colors.commands.primary }, + { text: `${bot.players.length}`, color: config.colors.integer }, + ] + }); + + component.push(playerCount); + + for (const player of bot.players) { + component.push({ + translate: "%s \u203a %s [%s: %s]", + color: config.colors.commands.tertiary, + with: [ + player.displayName ?? player.profile.name, + { text: `${player.uuid}`, color: config.colors.commands.primary }, + { text: "Latency", color: config.colors.commands.primary }, + { text: `${player.latency}`, color: config.colors.integer } + ] + }); + component.push("\n"); + } + component.pop(); + + source.sendFeedback(component) + } +} + +module.exports = list; diff --git a/src/commands/public/mcserver.js b/src/commands/public/mcserver.js new file mode 100644 index 0000000..2026c9b --- /dev/null +++ b/src/commands/public/mcserver.js @@ -0,0 +1,51 @@ +const mc = require("minecraft-protocol"); +const util = require("util"); +const CommandContext = require("../../command_util/command_context"); +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); + +class mcserver extends CommandContext { + constructor() { + super("mcserver", ["pingserver"], "pings minecraft servers", trustLevel.public, [""]); + } + + async execute(context) { + const bot = context.bot; + const config = context.config; + const args = context.arguments; + const [host, port] = args[0].split(":"); + const source = context.source; + const server = await mc.ping({ host, port: Number(port ?? 25565) }); + let component = []; + + try { + component.push({ + translate: "%s: %s:%s\n%s: (%s/%s)\n%s: %s\n%s", + color: config.colors.commands.tertiary, + with: [ + { text: "ip", color: config.colors.commands.primary }, + { text: `${host}`, color: config.colors.commands.secondary }, + { + text: `${Number(port ?? 25565)}`, + color: config.colors.commands.secondary, + }, + { text: "players", color: config.colors.commands.primary }, + { text: `${server.players.online}`, color: config.colors.integer }, + { text: `${server.players.max}`, color: config.colors.integer }, + { text: "server version", color: config.colors.commands.primary }, + { + text: `${server.version.name}`, + color: config.colors.commands.secondary, + }, + server.description, + ], + }); + + source.sendFeedback(component) + } catch (e) { + console.log(e.stack); + bot.chat.message(`${e.toString()}`); + } + } +} +module.exports = mcserver; diff --git a/src/commands/public/refillcore.js b/src/commands/public/refillcore.js index cefbe24..496310a 100644 --- a/src/commands/public/refillcore.js +++ b/src/commands/public/refillcore.js @@ -1,13 +1,16 @@ const CommandContext = require("../../command_util/command_context"); -const CommandTrustLevel = require('../../command_util/command_trust_level') -const trustLevel = new CommandTrustLevel() +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); class refillcore extends CommandContext { constructor() { - super("rc", ["refill", "refillcore"], "refill the bots core", trustLevel.public, [ - '', - ], - true + super( + "rc", + ["refill", "refillcore"], + "refill the bots core", + trustLevel.public, + [""], + true, ); } @@ -15,8 +18,8 @@ class refillcore extends CommandContext { const bot = context.bot; const args = context.arguments; - bot.core.move(bot.position) - bot.tellraw("@a", 'refilling core') + bot.core.move(bot.position); + bot.tellraw("@a", "refilling core"); } } diff --git a/src/commands/public/test.js b/src/commands/public/test.js new file mode 100644 index 0000000..217a6ec --- /dev/null +++ b/src/commands/public/test.js @@ -0,0 +1,47 @@ +const CommandContext = require("../../command_util/command_context"); +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); + +class test extends CommandContext { + constructor() { + super( + "test", + [], + "", + trustLevel.public, + [""], + true, + ); + } + + execute(context) { + const bot = context.bot; + const args = context.arguments; + const source = context.source + + if ( + !args + && + !args[0] + && + !args[1] + && + !args[2] + ) return; + +// console.log(args[2]) + + switch (args[0]) { + case "send": + bot.extras.send(args[1], args.slice(2).join(" ")) + source.sendFeedback(`sent ${args.slice(2).join(" ")} to channel ${args[1]}`) + break + case "register": + bot.extras.register(args[1]) + source.sendFeedback(`registered ${args[1]} channel`) + break + } + } +} + +module.exports = test; diff --git a/src/commands/trusted/auth.js b/src/commands/trusted/auth.js index d5fda69..6b98237 100644 --- a/src/commands/trusted/auth.js +++ b/src/commands/trusted/auth.js @@ -1,61 +1,66 @@ const CommandContext = require("../../command_util/command_context"); -const CommandTrustLevel = require('../../command_util/command_trust_level') -const CommandError = require('../../command_util/command_error'); -const trustLevel = new CommandTrustLevel() +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const CommandError = require("../../command_util/command_error"); +const trustLevel = new CommandTrustLevel(); class auth extends CommandContext { constructor() { - super("auth", ["authentication"], "auth through the bot so you dont need to use a hash everytime", trustLevel.trusted, [""], false); + super( + "auth", + ["authentication"], + "auth through the bot so you dont need to use a hash everytime", + trustLevel.trusted, + [""], + false, + ); } execute(context) { const bot = context.bot; const args = context.arguments; const source = context.source; const config = context.config; - const uuid = source.player.uuid - const { MessageBuilder } = require('prismarine-chat')(bot.registry.version) + const uuid = source.player.uuid; + let component = [] - if (bot.auth.list.find((e) => e?.player === uuid)) throw new CommandError(`You are already authed!`) + if (bot.auth.list.find((e) => e?.player === uuid)) + throw new CommandError(`You are already authed!`); if (source.player.hash === "trusted") { - source.player.authed = true + source.player.authed = true; bot.auth.add({ player: uuid, - trustLevel: "trusted" - }) - source.sendFeedback( - new MessageBuilder() - .setText("Authed as Trusted") - .setColor(config.colors.help.trusted) - ) - - } - else if (source.player.hash === "admin") { - source.player.authed = true - bot.auth.add({ - player: uuid, - trustLevel: "admin" - }) - source.sendFeedback( - new MessageBuilder() - .setText("Authed as Admin") - .setColor(config.colors.help.admin) - ) - } + trustLevel: "trusted", + }); - else if (source.player.hash === "owner") { - source.player.authed = true + component.push({ + text: "Authed as Trusted", + color: config.colors.help.trusted + }) + } else if (source.player.hash === "admin") { + source.player.authed = true; + bot.auth.add({ + player: uuid, + trustLevel: "admin", + }); + + component.push({ + text: "Authed as Admin", + color: config.colors.help.admin + }) + } else if (source.player.hash === "owner") { + source.player.authed = true; bot.auth.add({ player: source.player.uuid, - trustLevel: "owner" + trustLevel: "owner", + }); + component.push({ + text: "Authed as Owner", + color: config.colors.help.owner }) - source.sendFeedback( - new MessageBuilder() - .setText("Authed as Owner") - .setColor(config.colors.help.owner) - ) } + + source.sendFeedback(component) } } -module.exports = auth +module.exports = auth; diff --git a/src/commands/trusted/cloop.js b/src/commands/trusted/cloop.js index 613793e..bef2988 100644 --- a/src/commands/trusted/cloop.js +++ b/src/commands/trusted/cloop.js @@ -1,23 +1,24 @@ const CommandError = require("../../command_util/command_error"); const fixAnsi = require("../../util/ansi"); const CommandContext = require("../../command_util/command_context"); -const CommandTrustLevel = require('../../command_util/command_trust_level') -const trustLevel = new CommandTrustLevel() +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); class cloop extends CommandContext { constructor() { - super("cloop", ["commandloop", "loop"], "loops commands", trustLevel.trusted, [ - "add ", - "remove ", - "list", - "clear", - ]); + super( + "cloop", + ["commandloop", "loop"], + "loops commands", + trustLevel.trusted, + ["add ", "remove ", "list", "clear"], + ); } execute(context) { const bot = context.bot; const config = context.config; const source = context.source; - const args = context.arguments + const args = context.arguments; let component = []; if ( @@ -92,8 +93,8 @@ class cloop extends CommandContext { throw new CommandError("invalid argument"); } - source.sendFeedback(component) + source.sendFeedback(component); } } -module.exports = cloop +module.exports = cloop; diff --git a/src/commands/trusted/reconnect.js b/src/commands/trusted/reconnect.js index 50135ed..10c04ee 100644 --- a/src/commands/trusted/reconnect.js +++ b/src/commands/trusted/reconnect.js @@ -1,19 +1,26 @@ const CommandContext = require("../../command_util/command_context"); -const CommandTrustLevel = require('../../command_util/command_trust_level') -const trustLevel = new CommandTrustLevel() +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); class reconnect extends CommandContext { constructor() { - super("reconnect", ["end"], "reconnect the bot", trustLevel.trusted, [""], false); + super( + "reconnect", + ["end"], + "reconnect the bot", + trustLevel.trusted, + [""], + false, + ); } execute(context) { const bot = context.bot; const args = context.arguments; const source = context.source; const config = context.config; - - bot._client.end() + + bot._client.end(); } } -module.exports = reconnect +module.exports = reconnect; diff --git a/src/commands/trusted/validate.js b/src/commands/trusted/validate.js index 7b508e6..4c69d42 100644 --- a/src/commands/trusted/validate.js +++ b/src/commands/trusted/validate.js @@ -1,34 +1,44 @@ const CommandContext = require("../../command_util/command_context"); -const CommandTrustLevel = require('../../command_util/command_trust_level') -const trustLevel = new CommandTrustLevel() +const CommandTrustLevel = require("../../command_util/command_trust_level"); +const trustLevel = new CommandTrustLevel(); class validate extends CommandContext { constructor() { - super("validate", ["val"], "validate through the bot", trustLevel.trusted, [""], false); + super( + "validate", + ["val"], + "validate through the bot", + trustLevel.trusted, + [""], + false, + ); } execute(context) { const bot = context.bot; const args = context.arguments; const source = context.source; const config = context.config; - const { MessageBuilder } = require('prismarine-chat')(bot.registry.version) + let component = [] - if (source.player.hash === "trusted") source.sendFeedback( - new MessageBuilder() - .setText('Valid Trusted Hash') - .setColor(config.colors.help.trusted) - ) - else if (source.player.hash === "admin") source.sendFeedback( - new MessageBuilder() - .setText('Valid Admin Hash') - .setColor(config.colors.help.admin) - ) - else if (source.player.hash === "owner") source.sendFeedback( - new MessageBuilder() - .setText('Valid Owner Hash') - .setColor(config.colors.help.owner) - ) + if (source.player.hash === "trusted") + component.push({ + text: "Valid Trusted Hash", + color: config.colors.help.trusted + }) + + else if (source.player.hash === "admin") + component.push({ + text: "Valid Admin Hash", + color: config.colors.help.admin + }) + else if (source.player.hash === "owner") + component.push({ + text: "Valid Owner Hash", + color: config.colors.help.owner + }) + + source.sendFeedback(component) } } -module.exports = validate +module.exports = validate; diff --git a/src/help-layout.txt b/src/help-layout.txt deleted file mode 100644 index 031461e..0000000 --- a/src/help-layout.txt +++ /dev/null @@ -1,5 +0,0 @@ -Commands (19) (Public | Trusted | Admin | Owner) \u203a -~core ~echo ~help ~info ~list ~mcserver ~netmsg ~refillcore ~urban ~weather ~wiki -~cloop ~validate -~kick ~coresettings ~reconnect -~kill diff --git a/src/index.js b/src/index.js index 8cf1184..cf41995 100644 --- a/src/index.js +++ b/src/index.js @@ -2,13 +2,19 @@ const createBot = require("./bot.js"); const readline = require("readline"); const fs = require("fs"); const path = require("path"); -const loadModules = require("./util/loadModules") -const loadPlugins = require("./util/loadPlugins") +const loadModules = require("./util/loadModules"); +const loadPlugins = require("./util/loadPlugins"); const { Client, GatewayIntentBits, Partials } = require("discord.js"); -const { MessageContent, GuildMessages, Guilds, DirectMessages } = GatewayIntentBits; +const { MessageContent, GuildMessages, Guilds, DirectMessages } = + GatewayIntentBits; const discordClient = new Client({ - intents: [Guilds, GuildMessages, MessageContent, GatewayIntentBits.DirectMessages], - partials: [ Partials.Channel ] + intents: [ + Guilds, + GuildMessages, + MessageContent, + GatewayIntentBits.DirectMessages, + ], + partials: [Partials.Channel], }); const CommandSource = require("./command_util/command_source"); @@ -36,7 +42,7 @@ let options; let bot; for (const botOptions of config.bots) { - options = botOptions + options = botOptions; bot = new createBot(options, config); bots.push(bot); @@ -44,7 +50,7 @@ for (const botOptions of config.bots) { loadModules(bot, options, config, discordClient); bot.console.readlineInterface(rl); } -loadPlugins(bot, options, config, discordClient) +loadPlugins(bot, options, config, discordClient); discordClient.on("messageCreate", (message) => { try { if (message.author.id === bot.discord.client.user.id) return; diff --git a/src/modules/auth.js b/src/modules/auth.js index 713f03d..437887d 100644 --- a/src/modules/auth.js +++ b/src/modules/auth.js @@ -1,32 +1,32 @@ class auth { - constructor (context) { - const bot = context.bot - const options = context.options - const config = context.config + constructor(context) { + const bot = context.bot; + const options = context.options; + const config = context.config; bot.auth = { list: [], - find (player) { - this.list.find() + find(player) { + this.list.find(); }, - add (player) { - this.list.push(player) + add(player) { + this.list.push(player); }, - remove (player) { + remove(player) { this.list.splice(player, 1); }, - clear () { + clear() { this.list = []; }, - } + }; - bot.on('end', () => bot.auth.clear()) + bot.on("end", () => bot.auth.clear()); - bot.on('player_left', (data) => { - const players = bot.auth.list.find((e) => e?.player === data[0])?.player - if (players === data[0]) bot.auth.remove(data) - }) + bot.on("player_left", (data) => { + const players = bot.auth.list.find((e) => e?.player === data[0])?.player; + if (players === data[0]) bot.auth.remove(data); + }); } } -module.exports = auth; \ No newline at end of file +module.exports = auth; diff --git a/src/modules/boot.js b/src/modules/boot.js deleted file mode 100644 index 7c8585f..0000000 --- a/src/modules/boot.js +++ /dev/null @@ -1,7 +0,0 @@ -class boot { - constructor () { - - } -} - -module.exports = boot; \ No newline at end of file diff --git a/src/modules/chat.js b/src/modules/chat.js index f6840a8..466d3aa 100644 --- a/src/modules/chat.js +++ b/src/modules/chat.js @@ -1,8 +1,8 @@ const loadPrismarineChat = require("prismarine-chat"); const KaboomChatParser = require("../chat_parsers/kaboom"); const CreayunChatParser = require("../chat_parsers/creayun"); -const ChipmunkModChatParser = require("../chat_parsers/chipmunkmod") -const VanilaChatParser = require("../chat_parsers/vanilla") +const ChipmunkModChatParser = require("../chat_parsers/chipmunkmod"); +const VanilaChatParser = require("../chat_parsers/vanilla"); const convertNbtComponentToJson = require("../util/nbt_parser"); function tryParse(json) { @@ -22,51 +22,68 @@ class chat { bot.on("registry_ready", (registry) => { ChatMessage = loadPrismarineChat(registry); }); - + if (options.mode === "savageFriends") { bot.chatParsers = [CreayunChatParser]; } else { - bot.chatParsers = [KaboomChatParser, ChipmunkModChatParser, VanilaChatParser]; + bot.chatParsers = [ + KaboomChatParser, + ChipmunkModChatParser, + VanilaChatParser, + ]; } - + bot.on("packet.profileless_chat", (packet) => { - let message - let sender + let message; + let sender; message = tryParse(packet.message); sender = tryParse(packet.name); switch (packet.type) { case 1: - bot.emit("message", { - translate: "chat.type.emote", - with: [sender, message], + bot.emit("message", { + type: "minecraft:disguised_chat", + message: { + translate: "chat.type.emote", + with: [sender, message], + } }); break; case 2: bot.emit("message", { - translate: "commands.message.display.incoming", - with: [sender, message], - color: "gray", - italic: true, - }); - break; - case 3: - bot.emit("message", [ - { - translate: "commands.message.display.outgoing", + type: "minecraft:disguised_chat", + message: { + translate: "commands.message.display.incoming", with: [sender, message], color: "gray", italic: true, + } + }); + break; + case 3: + bot.emit("message", + { + type: "minecraft:disguised_chat", + message: { + translate: "commands.message.display.outgoing", + with: [sender, message], + color: "gray", + italic: true + } }, - ]); + ); break; case 4: - bot.emit("message", [message]); + bot.emit("message", { + type: "minecraft:disguised_chat", + message: message + }); break; case 5: - bot.emit("message", [ - { translate: "chat.type.announcement", with: [sender, message] }, - ]); + bot.emit("message", { + type: "minecraft:disguised_chat", + message: { translate: "chat.type.announcement", with: [sender, message] }, + }); break; } }); @@ -78,49 +95,64 @@ class chat { switch (packet.type) { case 5: bot.emit("message", { - translate: "chat.type.announcement", - with: [ - bot.players.find((player) => player.uuid === packet.senderUuid) - .profile.name, - packet.plainMessage, - ], + type: "minecraft:player_chat", + message: { + translate: "chat.type.announcement", + with: [ + bot.players.find((player) => player.uuid === packet.senderUuid) + .profile.name, + packet.plainMessage, + ], + }, }); break; case 4: - bot.emit("message", unsigned); + bot.emit("message", { + type: "minecraft:player_chat", + message: unsigned, + }); break; case 3: 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, + type: "minecraft:player_chat", + 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: bot.emit("message", { - translate: "commands.message.display.incoming", - with: [ - bot.players.find((player) => player.uuid === packet.senderUuid) - .profile.name, + type: "minecraft:player_chat", + message: { + translate: "commands.message.display.incoming", + with: [ + bot.players.find((player) => player.uuid === packet.senderUuid) + .profile.name, packet.plainMessage, - ], - color: "gray", - italic: true, + ], + color: "gray", + italic: true, + }, }); break; case 1: bot.emit("message", { - translate: "chat.type.emote", - with: [ - bot.players.find((player) => player.uuid === packet.senderUuid) - .profile.name, - packet.plainMessage, - ], + type: "minecraft:player_chat", + message: { + translate: "chat.type.emote", + with: [ + bot.players.find((player) => player.uuid === packet.senderUuid) + .profile.name, + packet.plainMessage, + ], + }, }); break; } @@ -128,7 +160,7 @@ class chat { senderUuid: packet.senderUuid, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine, - chatType: "player" + chatType: "player", }); }); @@ -137,16 +169,11 @@ class chat { message = tryParse(packet.content); -// console.log(packet.content) - /* -{"translate":"%s","with":[{"color":"red", -"translate":"chomens_bot.command_handler.invalid_hash","fallback":"Invalid %s hash","with":["TRUSTED"]},"chomens_bot_command_output"]} - */ if ( message.translate === "advMode.setCommand.success" && config?.debug?.commandSetMessage === false ) - return; + return; if (message.translate === "multiplayer.message_not_delivered") return; if (packet.isActionBar) { @@ -155,31 +182,34 @@ class chat { if (message.translate === "advMode.notAllowed") return; - bot.emit("message", message); - bot.emit("system_chat", message) - - if (bot.options.mode !== "savageFriends") return + bot.emit("message", { + type: "minecraft:system_chat", + message: message + }); + bot.emit("system_chat", message); + + if (bot.options.mode !== "savageFriends") return; tryParsingMessage(message, { players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine, - chatType: "system" + chatType: "system", }); }); function tryParsingMessage(message, data) { try { - let parsed; + let parsed; - for (const parser of bot.chatParsers) { - parsed = parser(message, data); - if (parsed) break; + for (const parser of bot.chatParsers) { + parsed = parser(message, data); + if (parsed) break; + } + + if (!parsed) return; + bot.emit("parsed_message", parsed); + } catch (e) { + console.log(e.stack); } - - if (!parsed) return; - bot.emit("parsed_message", parsed); - } catch (e) { - console.log(e.stack) - } } bot.getMessageAsPrismarine = (message) => { diff --git a/src/modules/command_core.js b/src/modules/command_core.js index 5c884c8..a7c2fcb 100644 --- a/src/modules/command_core.js +++ b/src/modules/command_core.js @@ -1,7 +1,7 @@ const nbt = require("prismarine-nbt"); const sleep = require("../util/sleep"); const convertNbtComponentToJson = require("../util/nbt_parser"); -const fixansi = require("../util/ansi") +const fixansi = require("../util/ansi"); class command_core { constructor(context) { @@ -37,14 +37,14 @@ class command_core { } else { 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} command_block{CustomName:${JSON.stringify(config.core.name)}}`; } - bot.chat.command(command) + bot.chat.command(command); }, - itemRefill () { + itemRefill() { const pos = bot.core.position; const { start, end } = bot.core.area; const itemPosition = bot.core.itemPosition; - + 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} command_block{CustomName:${JSON.stringify(config.core.name)}}`; if (bot.options.mode !== "savageFriends") { bot._client.write("set_creative_slot", { @@ -77,7 +77,7 @@ class command_core { if (bot.core.usePlacedCommandBlock) { return; } else { - bot.core.commandBlock(command, itemPosition, 1, 5) + bot.core.commandBlock(command, itemPosition, 1, 5); } } }, @@ -95,10 +95,10 @@ class command_core { z: Math.floor(pos.z), }; - if (bot.options.itemRefill) { + if (bot.options.itemRefill && bot.options.mode !== "savageFriends") { bot.core.itemRefill(); } else { - bot.core.chatRefill() + bot.core.chatRefill(); } }, @@ -136,7 +136,7 @@ class command_core { } }, - commandBlock (command, location, mode, flags) { + commandBlock(command, location, mode, flags) { if (!bot.loggedIn) return; bot._client.write("update_command_block", { command: command?.substring(0, 32767), @@ -144,7 +144,6 @@ class command_core { mode: mode, flags: flags, }); - }, run(command) { @@ -156,27 +155,26 @@ class command_core { if (bot.options.mode === "creayun") { return; } else if (bot.options.mode === "savageFriends") { - bot.core.commandBlock(command, location, 2, 0b101) + bot.core.commandBlock(command, location, 2, 0b101); bot.core.incrementCurrentBlock(); } else { if (bot.core.usePlacedCommandBlock) { - bot.core.commandBlock(command, itemPosition, 1, 5) + bot.core.commandBlock(command, itemPosition, 1, 5); bot.core.incrementCurrentBlock(); } else { - bot.core.commandBlock(command, location, 1, 5) + bot.core.commandBlock(command, location, 1, 5); bot.core.incrementCurrentBlock(); } } }, - transaction_id: 0, // setting it 10 just in case the command block was already used so it doesnt send more than 1 message - async runTracked(command, source) { const location = bot.core.currentBlock(); - let transactionId = Math.floor(Math.random() * 10000); - bot.core.commandBlock(command, location, 1, 0b101) + const transactionId = Math.floor(Math.random() * 10000); + + bot.core.commandBlock(command, location, 1, 0b101); bot.core.incrementCurrentBlock(); @@ -188,17 +186,17 @@ class command_core { try { if (data.transactionId == transactionId) { if (data?.nbt?.value?.LastOutput) { - const output = convertNbtComponentToJson(null, (data.nbt.value.LastOutput.value).extra) - source.sendFeedback(output) + const output = convertNbtComponentToJson( + null, + data.nbt.value.LastOutput.value.extra, + ); + source.sendFeedback(output); } } } catch (e) { console.log(e.stack); } }); - - await sleep(100) - this.transaction_id++ }, }; @@ -243,7 +241,7 @@ class command_core { if (timer) clearInterval(timer); }); - bot.on("packet.multi_block_change", (data) => { + /* bot.on("packet.multi_block_change", (data) => { try { if (bot.options.mode !== "kaboom") return; @@ -266,7 +264,7 @@ class command_core { } catch (e) { console.log(e.stack); } - }); + });*/ } } module.exports = command_core; diff --git a/src/modules/command_handler.js b/src/modules/command_handler.js index b4b3603..b60b544 100644 --- a/src/modules/command_handler.js +++ b/src/modules/command_handler.js @@ -23,25 +23,33 @@ class command_handler { data.sender, { discord: false, console: false }, data.chatType, - null + null, ); source.sendFeedback = (message) => { if (source.sources.console) bot.console.command(); else if (source.sources.discord) { - return message // lazy - } else bot.tellraw(`@a[name="${source.player.profile.name}"]`, [message]); - } + return message; // lazy + } else { + if (options.mode === "savageFriends") bot.tellraw(`@a[name=${source.player.profile.name}]`, [ + message + ]) + else bot.tellraw(`@a[name="${source.player.profile.name}"]`, message) + } + }; - if (command.split(' ')[1] === bot.validation.trusted) source.player.hash = "trusted"; - else if (command.split(' ')[1] === bot.validation.admin) source.player.hash = "admin"; - else if (command.split(' ')[1] === bot.validation.owner) source.player.hash = "owner"; + if (command.split(" ")[1] === bot.validation.trusted) + source.player.hash = "trusted"; + else if (command.split(" ")[1] === bot.validation.admin) + source.player.hash = "admin"; + else if (command.split(" ")[1] === bot.validation.owner) + source.player.hash = "owner"; ratelimit++; setTimeout(() => { ratelimit--; }, 1000); if (ratelimit > config.ratelimit.commands) { - return + return; } else if (command.split(" ")[0].length === 0) { } else { bot.commandManager.executeString(source, command); diff --git a/src/modules/command_loop.js b/src/modules/command_loop.js index 2f316fb..ae4505f 100644 --- a/src/modules/command_loop.js +++ b/src/modules/command_loop.js @@ -12,7 +12,7 @@ class command_loop { }; this.list.push(timer); -/* bot.on("end", () => { + /* bot.on("end", () => { this.clear(); }); diff --git a/src/modules/command_manager.js b/src/modules/command_manager.js index 73a6325..73309a1 100644 --- a/src/modules/command_manager.js +++ b/src/modules/command_manager.js @@ -5,24 +5,17 @@ const CommandSource = require("../command_util/command_source"); const fixansi = require("../util/ansi"); const sleep = require("../util/sleep.js"); -function unknownCommand (MessageBuilder, commandName, bot) { - - return new MessageBuilder() - .setTranslate("%s%s%s %s") - .setColor("red") - .addWith( - new MessageBuilder() - .setTranslate("command.unknown.command") - .setColor('red'), - new MessageBuilder() - .setText('\n'), - new MessageBuilder() - .setText(`${commandName}`) - .setColor("gray"), - new MessageBuilder() - .setTranslate("command.context.here") - .setColor("red") - ) +function unknownCommand(MessageBuilder, commandName, bot) { + return { + translate: "%s%s%s %s", + color: "red", + with: [ + { translate: "command.unknown.command", color: "red" }, + { text: "\n"}, + { text: `${commandName}`, color: "gray" }, + { translate: "command.context.here", color: "red" } + ] + } } class command_manager { @@ -31,21 +24,25 @@ class command_manager { const config = context.config; const discordClient = context.discordClient; const options = context.options; - const { MessageBuilder } = require('prismarine-chat')(bot._client.version) + bot.commandManager = { commands: {}, commandlist: [], execute(source, commandName, args) { const command = this.getCommand(commandName.toLowerCase()); - const authed = bot.auth.list + const authed = bot.auth.list; try { if (!command) { - if (source?.sources?.console) bot.console.command( - unknownCommand(MessageBuilder, commandName, bot) - ) - else source.sendFeedback(unknownCommand(MessageBuilder, commandName, bot)) + if (source?.sources?.console) + bot.console.command( + unknownCommand(commandName, bot), + ); + else + source.sendFeedback( + unknownCommand(commandName, bot), + ); } - + const event = bot.discord.message; const roles = event?.member?.roles?.cache; @@ -62,45 +59,44 @@ class command_manager { role.name === `${config.discord.roles.fullAccess}` || role.name === `${config.discord.roles.owner}`, ); - if (!hasRole) throw new CommandError( - new MessageBuilder() - .setText("You dont have the trusted, admin, or owner roles!") - .setColor("red") - ) + if (!hasRole) + throw new CommandError({ + text: "You done have the trusted, admin, or owner roles!", + color: "red" + }); } else if (!source?.sources.console) { - - if (args.length === 0 && ( - authed.find((e) => e?.player === source.player.uuid)?.trustLevel !== "trusted" - && - authed.find((e) => e?.player === source.player.uuid)?.trustLevel !== "admin" - && - authed.find((e) => e?.player === source.player.uuid)?.trustLevel !== "owner" - )) throw new CommandError( - new MessageBuilder() - .setText("Please provide a trusted, admin, or owner hash") - .setColor("red") - ) if ( - (args[0] !== bot.validation.trusted && - args[0] !== bot.validation.admin && - args[0] !== bot.validation.owner) - && - ( - authed.find((e) => e.player === source.player.uuid)?.trustLevel !== "trusted" - && - authed.find((e) => e.player === source.player.uuid)?.trustLevel !== "admin" - && - authed.find((e) => e.player === source.player.uuid)?.trustLevel !== "owner" - ) - ) throw new CommandError( - new MessageBuilder() - .setText("Invalid Hash") - .setColor("red") + args.length === 0 && + authed.find((e) => e?.player === source.player.uuid) + ?.trustLevel !== "trusted" && + authed.find((e) => e?.player === source.player.uuid) + ?.trustLevel !== "admin" && + authed.find((e) => e?.player === source.player.uuid) + ?.trustLevel !== "owner" ) + throw new CommandError({ + text: "Please provide a trusted, admin, or owner hash", + color: "red" + }); + if ( + args[0] !== bot.validation.trusted && + args[0] !== bot.validation.admin && + args[0] !== bot.validation.owner && + authed.find((e) => e.player === source.player.uuid) + ?.trustLevel !== "trusted" && + authed.find((e) => e.player === source.player.uuid) + ?.trustLevel !== "admin" && + authed.find((e) => e.player === source.player.uuid) + ?.trustLevel !== "owner" + ) + throw new CommandError({ + text: "Invalid Hash", + color: "red" + }); if (source.player.authed) { - args = args + args = args; } else { - args = args.slice(1) + args = args.slice(1); } } break; @@ -112,44 +108,40 @@ class command_manager { role.name === `${config.discord.roles.fullAccess}` || role.name === `${config.discord.roles.owner}`, ); - if (!hasRole) throw new CommandError( - new MessageBuilder() - .setText("You dont have the admin, or owner roles!") - .setColor("red") - ) + if (!hasRole) + throw new CommandError({ + text: "You dont have the admin, or owner roles!", + color: "red" + }); } else if (!source?.sources?.console) { - if (args.length === 0 && ( - authed.find((e) => e?.player === source.player.uuid)?.trustLevel !== "admin" - && - authed.find((e) => e?.player === source.player.uuid)?.trustLevel !== "owner" - )) - throw new CommandError( - new MessageBuilder() - .setText('Please provide a hash') - .setColor('red') - ); if ( - ( - args[0] !== bot.validation.admin && - args[0] !== bot.validation.owner - ) - && - ( - authed.find((e) => e?.player === source.player.uuid)?.trustLevel !== "admin" - && - authed.find((e) => e?.player === source.player.uuid)?.trustLevel !== "owner" - ) + args.length === 0 && + authed.find((e) => e?.player === source.player.uuid) + ?.trustLevel !== "admin" && + authed.find((e) => e?.player === source.player.uuid) + ?.trustLevel !== "owner" ) - throw new CommandError( - new MessageBuilder() - .setText('Invalid Hash') - .setColor("red") - ); - + throw new CommandError({ + text: "Please provide a hash", + color: "red" + }); + if ( + args[0] !== bot.validation.admin && + args[0] !== bot.validation.owner && + authed.find((e) => e?.player === source.player.uuid) + ?.trustLevel !== "admin" && + authed.find((e) => e?.player === source.player.uuid) + ?.trustLevel !== "owner" + ) + throw new CommandError({ + text: "Invalid hash", + color: "red" + }); + if (source.player.authed) { - args = args + args = args; } else { - args = args.slice(1) + args = args.slice(1); } } break; @@ -161,55 +153,56 @@ class command_manager { role.name === `${config.discord.roles.fullAccess}`, ); if (!hasRole) - throw new CommandError( - new MessageBuilder() - .setText("You dont have the owner role!") - .setColor("red") - ) + throw new CommandError({ + text: "You dont have the owner role!", + color: "red" + }); } else if (!source?.sources?.console) { - if (args.length === 0 && bot.validation.owner && authed.find((e) => e?.player === source.player.uuid)?.trustLevel !== "owner") - throw new CommandError( - new MessageBuilder() - .setText("Please provide a hash") - .setColor('red') - ); + if ( + args.length === 0 && + bot.validation.owner && + authed.find((e) => e?.player === source.player.uuid) + ?.trustLevel !== "owner" + ) + throw new CommandError({ + text: "Please provide a hash", + color: "red" + }); + + if ( + args[0] !== bot.validation.owner && + authed.find((e) => e?.player === source.player.uuid) + ?.trustLevel !== "owner" + ) + throw new CommandError({ + text: "Invalid hash", + color: "red" + }); - if (args[0] !== bot.validation.owner && ( - authed.find((e) => e?.player === source.player.uuid)?.trustLevel !== "owner" - )) - throw new CommandError( - new MessageBuilder() - .setText('Invalid Hash') - .setColor('red') - ); - if (source.player.authed) { args = args; } else { - args = args.slice(1) + args = args.slice(1); } } break; case 4: if (!source?.sources?.console) { - - throw new CommandError( - new MessageBuilder() - .setText("This Command can only be ran via console") - .setColor('red') - ); + throw new CommandError({ + text: "This Command can only be ran via console", + color: "red" + }); } break; case 5: - throw new CommandError( - new MessageBuilder() - .setText("This Command has been disabled!") - .setColor('red') - ) - break + throw new CommandError({ + text: "This Command has been disabled!", + color: "red" + }); + break; } -/* if (source.sources.discord) { + /* if (source.sources.discord) { discordClient.channels.cache .get("1361739286113685534") .send( @@ -223,9 +216,8 @@ class command_manager { ); }*/ - -// if (command.playerOnly === true && source.ChatType.find((e) => e)) return; - + // if (command.playerOnly === true && source.ChatType.find((e) => e)) return; + return command?.execute({ bot, source, @@ -247,7 +239,7 @@ class command_manager { } else { if (source.sources.discord) { bot.discord.message.reply( - `\`\`\`ansi\n${new fixansi(bot.getMessageAsPrismarine({ text: error.stack, color: "red"})?.toAnsi()).ansi}\`\`\``, + `\`\`\`ansi\n${new fixansi(bot.getMessageAsPrismarine({ text: error.stack, color: "red" })?.toAnsi()).ansi}\`\`\``, ); } else { bot.tellraw("@a", { diff --git a/src/modules/command_spy.js b/src/modules/command_spy.js index b1c6275..571adf4 100644 --- a/src/modules/command_spy.js +++ b/src/modules/command_spy.js @@ -1,46 +1,40 @@ class command_spy { - constructor (context) { - const bot = context.bot + constructor(context) { + const bot = context.bot; - bot.on('system_chat', (message) => { + bot.on("system_chat", (message) => { try { - const child = message.extra - const sender = bot.players.find((e) => e?.profile?.name === message.text)?.profile?.name === message.text - if (!child || !message.text || !message.color || !sender) return - const command = child[1].text.substring('/'.length) + const child = message.extra; + const sender = + bot.players.find((e) => e?.profile?.name === message.text)?.profile + ?.name === message.text; + if (!child || !message.text || !message.color || !sender) return; + const command = child[1].text.substring("/".length); if ( - ( - message.color === 'yellow' - && - child[0].text === ': ' - && - child[1].text === `/${command}` - && - sender - ) - || - ( - message.color === 'aqua' - && - child[0].text === ': ' - && - child[1].text === `/${command}` - && - sender - ) - ) bot.emit('parsed_message', { - sender: bot.players.find((e) => e.profile.name === message.text), - contents: { text: command }, - type: "minecraft:chat", - chatType: "command_spy", - displayName: bot.players.find((e) => e.profile.name === message.text).displayName - }) + (message.color === "yellow" && + child[0].text === ": " && + child[1].text === `/${command}` && + sender) || + (message.color === "aqua" && + child[0].text === ": " && + child[1].text === `/${command}` && + sender) + ) + bot.emit("parsed_message", { + sender: bot.players.find((e) => e.profile.name === message.text), + contents: { text: command }, + type: "minecraft:chat", + chatType: "command_spy", + displayName: bot.players.find( + (e) => e.profile.name === message.text, + ).displayName, + }); } catch (e) { - console.log(e.stack) + console.log(e.stack); } - }) + }); } } -module.exports = command_spy; \ No newline at end of file +module.exports = command_spy; diff --git a/src/modules/console.js b/src/modules/console.js index a7b4396..3faecbd 100644 --- a/src/modules/console.js +++ b/src/modules/console.js @@ -1,7 +1,8 @@ const CommandSource = require("../command_util/command_source"); const prismarineChat = require("prismarine-chat")("1.20.2"); -class Console { // named it Console so that it doesnt override the console variable +class Console { + // named it Console so that it doesnt override the console variable constructor(context) { const bot = context.bot; const config = context.config; @@ -44,7 +45,7 @@ class Console { // named it Console so that it doesnt override the console varia }, uuid: bot._client.uuid, }, - { console: true, discord: false }, + { console: true, discord: false }, ), refreshLine(...args) { @@ -97,29 +98,51 @@ class Console { // named it Console so that it doesnt override the console varia ?.toAnsi() + message, ); }, - command (message) { + command(message) { console.log( prismarineChat .fromNotch( `§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO" })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })} §6command§8] §8[${serverName}§8] `, ) - ?.toAnsi() + bot.getMessageAsPrismarine(message)?.toAnsi(bot.registry.language), + ?.toAnsi() + + bot.getMessageAsPrismarine(message)?.toAnsi(bot.registry.language), ); - } + }, }; bot.console.source.sendFeedback = (message) => { - bot.console.command(message) - } + bot.console.command(message); + }; setInterval(() => (ratelimit = 0), 1000 * 2); bot.on("message", (message) => { + if (message.type === "minecraft:player_chat") + message = [ + { + text: "[P] ", + }, + message.message, + ]; + else if (message.type === "minecraft:disguised_chat") message = [ + { + text: "[V] " + }, + message.message + ] + else if (message.type === "minecraft:system_chat") message = [ + { + text: "[S] " + }, + message.message + ] + if (options.logging.console) { if (ratelimit > config.ratelimit.console) return; bot.console.log(bot.getMessageAsPrismarine(message)?.toAnsi()); } - if (options.logging.file) { + + if (options.logging.file && bot.loggedIn) { bot.console.fileLogger( `[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO" })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })} logs] [${serverName}] ${bot.getMessageAsPrismarine(message)?.toString()}`, ); diff --git a/src/modules/custom_channel_test.js b/src/modules/custom_channel_test.js new file mode 100644 index 0000000..6a6df30 --- /dev/null +++ b/src/modules/custom_channel_test.js @@ -0,0 +1,55 @@ +const channels = "extras:register\0extras:unregister\0extras:message\0"; +class custom_channel_test { + constructor (context) { + const bot = context.bot + const config = context.config + const options = context.options + + bot.on('packet.login', () => { + bot._client.write("custom_payload", { + channel: "minecraft:register", + data: Buffer.from(channels, "utf8") + }) + }); +// const buf = Buffer.from('meow', 'utf8') +// buf[buf.length - 1] |= 0x80; + // I wanna use the extras channels to my advantage --- Parker2991 + bot.extras = { + channel: "default", + register (channel) { + const buf = Buffer.from(channel, "utf8") + buf[buf.length - 1] |= 0x80; +// this.channel = buf + bot._client.write("custom_payload", { + channel: "extras:register", + data: buf, + }) + + bot._client.write('custom_payload', { + channel: "minecraft:register", + data: buf + }); + }, + unregister (channel) { + const buf = Buffer.from(channel, "utf8") + buf[buf.length - 1] |= 0x80; + + bot._client.write("custom_payload", { + channel: "extras:unregister", + data: buf, + }) + }, + send (channel, message) { + const buf = Buffer.from(channel, "utf8") + buf[buf.length - 1] |= 0x80; + + bot._client.write("custom_payload", { + channel: "extras:message", + data: Buffer.concat([buf, Buffer.from(`${message}`, "utf8")]) + }) + } + } + } +} + +module.exports = custom_channel_test; diff --git a/src/modules/discord.js b/src/modules/discord.js index dc709af..816f552 100644 --- a/src/modules/discord.js +++ b/src/modules/discord.js @@ -65,7 +65,7 @@ class discord { } bot.on("message", (message) => { - sendComponent(message); + sendComponent(message.message); }); function messageCreate(message, source) { diff --git a/src/modules/player_list.js b/src/modules/player_list.js index 42f1360..0662a78 100644 --- a/src/modules/player_list.js +++ b/src/modules/player_list.js @@ -36,15 +36,15 @@ class player_list { ); if (a.length >= 1) { player.vanished = true; + } else { bot.players = bot.players.filter((_) => _.uuid != player.uuid); - bot.emit("player_left", players); - } + bot.emit("player_left", player); + } if (player.vanished === true) bot.emit("player_left", players) }); }); function addPlayer(entry) { - console.log bot.players = bot.players.filter((_entry) => _entry.uuid !== entry.uuid); bot.players.push({ uuid: entry.uuid, @@ -60,6 +60,7 @@ class player_list { displayName: undefined, vanished: false, }); + bot.emit('player_join', entry) } function initializeChat(entry) {} @@ -74,7 +75,6 @@ class player_list { function updateListed(entry) { const target = bot.players.find((_entry) => _entry.uuid === entry.uuid); if (!target) return; - target.listed = entry.listed; } diff --git a/src/modules/reconnect.js b/src/modules/reconnect.js index 54411fb..aef7e63 100644 --- a/src/modules/reconnect.js +++ b/src/modules/reconnect.js @@ -5,7 +5,7 @@ class reconnect { const bot = context.bot; const config = context.config; const options = context.options; - let client + let client; bot.reconnectDelay = options.reconnectDelay; bot.on("end", () => { diff --git a/src/modules/registry.js b/src/modules/registry.js index bc4a9a2..7566c2b 100644 --- a/src/modules/registry.js +++ b/src/modules/registry.js @@ -5,7 +5,7 @@ class registry { const bot = context.bot; bot.on("packet.login", (packet) => { bot.registry = createRegistry(bot._client.version); -// bot.registry.language = require("../data/language.json"); + bot.registry.language = require("../data/language.json"); bot.emit("registry_ready", bot.registry); }); } diff --git a/src/modules/selfcare.js b/src/modules/selfcare.js index 2483745..a4492ea 100644 --- a/src/modules/selfcare.js +++ b/src/modules/selfcare.js @@ -1,11 +1,11 @@ -const fs = require('fs') -const path = require('path') +const fs = require("fs"); +const path = require("path"); class selfcare { - constructor (context) { - const bot = context.bot - const config = context.config - const options = context.options + constructor(context) { + const bot = context.bot; + const config = context.config; + const options = context.options; bot.selfcare = { permissionLevel: 2, @@ -18,80 +18,115 @@ class selfcare { username: undefined, nickname: undefined, god: undefined, + register: undefined, + login: undefined, position_count: 0, - - } + }; let selfcare = []; - for (const file of fs.readdirSync(path.join(__dirname, '../selfcare/extras'))) { + for (const file of fs.readdirSync( + path.join(__dirname, "../selfcare/extras"), + )) { try { - const extrasSelfcare = require(path.join(__dirname, '../selfcare/extras', file)) - selfcare.push(extrasSelfcare) + const extrasSelfcare = require( + path.join(__dirname, "../selfcare/extras", file), + ); + selfcare.push(extrasSelfcare); } catch (e) { - console.error(e.stack) + console.error(e.stack); } } - for (const file of fs.readdirSync(path.join(__dirname, '../selfcare/essentials'))) { + for (const file of fs.readdirSync( + path.join(__dirname, "../selfcare/essentials"), + )) { try { - const essentialsSelfcare = require(path.join(__dirname, '../selfcare/essentials', file)) - selfcare.push(essentialsSelfcare) + const essentialsSelfcare = require( + path.join(__dirname, "../selfcare/essentials", file), + ); + selfcare.push(essentialsSelfcare); } catch (e) { - console.error(e.stack) + console.error(e.stack); } } - for (const file of fs.readdirSync(path.join(__dirname, '../selfcare/entity'))) { + for (const file of fs.readdirSync( + path.join(__dirname, "../selfcare/auth"), + )) { try { - const loadEntitySelfcare = require(path.join(__dirname, '../selfcare/entity', file)) - - new loadEntitySelfcare({ bot, config, options }) + const authSelfcare = require( + path.join(__dirname, "../selfcare/auth", file), + ); + selfcare.push(authSelfcare); } catch (e) { - console.error(e.stack) + console.error(e.stack); } } + for (const file of fs.readdirSync( + path.join(__dirname, "../selfcare/entity"), + )) { + try { + const loadEntitySelfcare = require( + path.join(__dirname, "../selfcare/entity", file), + ); - bot.on('system_chat', (message) => { - const stringMessage = bot.getMessageAsPrismarine(message)?.toString() - - for (const file of selfcare) new file({ bot, config, options, stringMessage }) + new loadEntitySelfcare({ bot, config, options }); + } catch (e) { + console.error(e.stack); + } + } - }) + bot.on("system_chat", (message) => { + const stringMessage = bot.getMessageAsPrismarine(message)?.toString(); + + for (const file of selfcare) + new file({ bot, config, options, stringMessage }); + }); let timer; - bot.on('packet.login', (data) => { + bot.on("packet.login", (data) => { bot.selfcare.entityId = data.entityId; bot.selfcare.gameMode = data.gameMode; - + timer = setInterval(() => { if (bot.options.mode === "savageFriends") { + if (bot.selfcare.register) bot.chat.command('register amogusissus amogusissus') + else if (bot.selfcare.login) bot.chat.command('login amogusissus') - } else { - if (!bot.selfcare.prefix) bot.chat.command(`extras:prefix &8[&bPrefix&8: &3${config.prefixes[0]}&8]`); - else if (bot.selfcare.permissionLevel < 2) bot.chat.command('minecraft:op @s[type=player]') - // else if (bot.selfcare.username) bot.chat.command(`extras:username ${bot._client.username}`) - else if (bot.selfcare.gameMode !== 1) bot.chat.command('minecraft:gamemode creative') - else if (!bot.selfcare.commandSpy) bot.core.run(`commandspy ${bot.uuid} on`) - else if (!bot.selfcare.vanished) bot.core.run(`essentials:vanish ${bot._client.username} on`) - else if (!bot.selfcare.god) bot.core.run(`essentials:god ${bot._client.username} on`) - else if (bot.selfcare.mute) bot.core.run(`essentials:mute ${bot._client.uuid}`) - else if (bot.selfcare.nickname) bot.core.run(`essentials:nickname ${bot._client.username} off`) - + } else if (bot.options.mode === "kaboom") { + if (!bot.selfcare.prefix) + bot.chat.command( + `extras:prefix &8[&bPrefix&8: &3${config.prefixes[0]}&8]`, + ); + else if (bot.selfcare.permissionLevel < 2) + bot.chat.command("minecraft:op @s[type=player]"); + else if (bot.selfcare.username) bot.chat.command(`extras:username ${bot._client.username}`) + else if (bot.selfcare.gameMode !== 1) + bot.chat.command("minecraft:gamemode creative"); + else if (!bot.selfcare.commandSpy) + bot.core.run(`commandspy ${bot.uuid} on`); + else if (!bot.selfcare.vanished) + bot.core.run(`essentials:vanish ${bot._client.username} on`); + else if (!bot.selfcare.god) + bot.core.run(`essentials:god ${bot._client.username} on`); + else if (bot.selfcare.mute) + bot.core.run(`essentials:mute ${bot._client.uuid}`); + else if (bot.selfcare.nickname) + bot.core.run(`essentials:nickname ${bot._client.username} off`); } - }, options.selfcareInterval) - }) + }, options.selfcareInterval); + }); - bot.on('end', () => { - if (timer) clearInterval(timer) - bot.selfcare.commandSpy = false - bot.selfcare.prefix = false - bot.selfcare.vanished = false - bot.selfcare.mute = false - bot.selfcare.username = false - bot.selfcare.nickname = false - bot.selfcare.god = false - - }) + bot.on("end", () => { + if (timer) clearInterval(timer); + bot.selfcare.commandSpy = false; + bot.selfcare.prefix = false; + bot.selfcare.vanished = false; + bot.selfcare.mute = false; + bot.selfcare.username = false; + bot.selfcare.nickname = false; + bot.selfcare.god = false; + }); } } -module.exports = selfcare \ No newline at end of file +module.exports = selfcare; diff --git a/src/modules/tab_complete.js b/src/modules/tab_complete.js index c077196..7bb534d 100644 --- a/src/modules/tab_complete.js +++ b/src/modules/tab_complete.js @@ -18,4 +18,4 @@ class tab_complete { }; } } -module.exports = tab_complete \ No newline at end of file +module.exports = tab_complete; diff --git a/src/ownerCheck.js b/src/ownerCheck.js index 2da8b45..0dea55b 100644 --- a/src/ownerCheck.js +++ b/src/ownerCheck.js @@ -1,50 +1,61 @@ -const sleep = require('../util/sleep') +const sleep = require("../util/sleep"); class OwnerCheckModule { - constructor (context) { - const config = context.config - const bot = context.bot - const discordClient = context.discordClient + constructor(context) { + const config = context.config; + const bot = context.bot; + const discordClient = context.discordClient; const options = context.options; if (bot.options.mode === "savageFriends") return; bot.ownerAuthed = false; - discordClient.on('messageCreate', (message) => { - if (message.content === `auth ${config.ownerAuth.uuid}` && message.channelId == config.ownerAuth.channel) { + discordClient.on("messageCreate", (message) => { + if ( + message.content === `auth ${config.ownerAuth.uuid}` && + message.channelId == config.ownerAuth.channel + ) { message.reply(`Authenticated ${config.ownerAuth.uuid}`); - bot.ownerAuthed = true + bot.ownerAuthed = true; } }); - bot.on('player_left', (data) => { + bot.on("player_left", (data) => { if (data[0] === `${config.ownerAuth.uuid}` && bot.ownerAuthed === true) { - bot.ownerAuthed = false + bot.ownerAuthed = false; } -// console.log(data[0]) + // console.log(data[0]) }); - bot.on('message', async (data) => { -// console.log(bot.players); -// await sleep(1000) + bot.on("message", async (data) => { + // console.log(bot.players); + // await sleep(1000) for (const eachPlayer of bot.players) { - if (eachPlayer.uuid === `${config.ownerAuth.uuid}` && !bot.ownerAuthed) { - bot.core.run(`minecraft:deop @a[name="${eachPlayer.profile.name}"]`); - bot.core.run(`gamemode adventure @a[name="${eachPlayer.profile.name}"]`); -// bot.core.run(`mute ${eachPlayer.uuid} 10y not authenticated`); - bot.exploits.kicks.translateEntity(`${eachPlayer.profile.name}`); + if ( + eachPlayer.uuid === `${config.ownerAuth.uuid}` && + !bot.ownerAuthed + ) { + bot.core.run(`minecraft:deop @a[name="${eachPlayer.profile.name}"]`); + bot.core.run( + `gamemode adventure @a[name="${eachPlayer.profile.name}"]`, + ); + // bot.core.run(`mute ${eachPlayer.uuid} 10y not authenticated`); + bot.exploits.kicks.translateEntity(`${eachPlayer.profile.name}`); } } }); - bot.on('parsed_message', (data) => { - if (data?.sender?.uuid === `${config.ownerAuth.uuid}` && !bot.ownerAuthed) { + bot.on("parsed_message", (data) => { + if ( + data?.sender?.uuid === `${config.ownerAuth.uuid}` && + !bot.ownerAuthed + ) { bot.core.run(`mute ${data.sender.uuid} 10y not authenticated`); } }); - bot.on('end', () => bot.ownerAuthed = false) + bot.on("end", () => (bot.ownerAuthed = false)); } } module.exports = OwnerCheckModule; diff --git a/src/plugins/database.js b/src/plugins/database.js index 9368ac9..ea05aa8 100644 --- a/src/plugins/database.js +++ b/src/plugins/database.js @@ -1,6 +1,4 @@ class database { - constructor(context) { - - } + constructor(context) {} } -module.exports = database \ No newline at end of file +module.exports = database; diff --git a/src/plugins/validation.js b/src/plugins/validation.js index 2563501..44ff3da 100644 --- a/src/plugins/validation.js +++ b/src/plugins/validation.js @@ -25,4 +25,4 @@ class validation { }, 100); } } -module.exports = validation \ No newline at end of file +module.exports = validation; diff --git a/src/selfcare.js.old b/src/selfcare.js.old deleted file mode 100644 index 4059309..0000000 --- a/src/selfcare.js.old +++ /dev/null @@ -1,255 +0,0 @@ -const sleep = require("../util/sleep"); - -class SelfcareModule { - constructor(context) { - const bot = context.bot; - const config = context.config; - const options = context.options; - let clientLock; - let entityId; - let permissionLevel = 2; - let unmuted = false; - let gameMode; - let commandSpy = false; - let vanished = false; - let prefix = false; - let god = false; - let teleportToggle = false; - let username = false; - let nickname = false; - let login = false; - let register = false; - let positionCount = 0; - let loggedin = false - bot.vanished = true; - bot.on("message", (data) => { - try { - 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; - else if (stringMessage === "You're already logged in!") login = false; - else if ( - stringMessage === - "Please, register to the server with the command: /register " - ) - register = true; - else if (stringMessage === "This user isn't registered!") - register = true; - else if (stringMessage === "Successfully registered!") - register = false; - else if (stringMessage === "You're already logged in!") - register = false; - else if (stringMessage === "Successful login!") register = false; - else if ( - stringMessage === - ` > Prefix for user ${bot.options.username} set to: [Prefix: ${config.prefixes[0]}]` - ) - prefix = true; - else if ( - stringMessage?.startsWith( - ` > Prefix for user ${bot.options.username} set to: `, - ) || - stringMessage === - ` > Prefix for user ${bot.options.username} removed.` - ) - prefix = false; - else if (stringMessage === `You no longer have a nickname.`) - nickname = false; - else if (stringMessage?.startsWith("Your nickname is now ")) - nickname = true; - else if ( - stringMessage === `Vanish for ${bot.options.username}: enabled` - ) - vanished = true; - else if ( - stringMessage === `Vanish for ${bot.options.username}: disabled` - ) - vanished = false; - } else if (options.mode === "kaboom") { - if (stringMessage === "Successfully enabled CommandSpy") - commandSpy = true; - 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._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; - else if (stringMessage?.startsWith("You have been unmuted")) - unmuted = false; - else if (stringMessage?.startsWith("Your voice has been silenced")) - unmuted = true; - else if (stringMessage === "God mode disabled.") god = false; - 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._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._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; - } - } catch (e) { - console.log(e.stack); - } - }); - - bot.on("packet.entity_status", (packet) => { - if ( - packet.entityId !== entityId || - packet.entityStatus < 24 || - packet.entityStatus > 28 - ) - return; - permissionLevel = packet.entityStatus - 24; - }); - - bot.on("packet.game_state_change", (packet) => { - if (packet.reason !== 3) return; // Reason 3 = Change Game Mode - gameMode = packet.gameMode; - }); - - bot.on("packet.position", (packet, position) => { - if (options.mode === "savageFriends" || options.mode === "creayun") - return; - positionCount++; - setTimeout(() => { - positionCount--; - if (positionCount > 4) { - bot._client.end("anti icu"); - } - }, 1000); - }); - - let timer; - bot.on("packet.login", async (packet) => { - entityId = packet.entityId; - if (bot.options.version === "1.21" || bot.options.version === "1.21.1") { - clientLock = packet.worldState.gameMode; - switch (packet.worldState.gamemode) { - case "survival": - gameMode = 0; - break; - case "creative": - gameMode = 1; - break; - case "adventure": - gameMode = 2; - break; - case "spectator": - gameMode = 3; - break; - default: - gameMode = 0; - break; - } - } else { - gameMode = packet.gameMode; - clientLock = packet.gameMode; - } - - timer = setInterval(() => { - if (bot.options.mode === "savageFriends") { - if (login) { - bot.chat.command("login amogusissus"); - loggedin = true - } - else if (register) { - bot.chat.command("register amogusissus amogusissus"); - loggedin = true - } - else if (gameMode !== 1 && loggedin) - bot.chat.command("minecraft:gamemode creative"); - else if (permissionLevel < 2 && loggedin) - bot.chat.command(`minecraft:op ${bot.options.username}`); - else if (!prefix && loggedin) - bot.chat.command(`rank ${bot.options.username} &8[&bPrefix&8: &3${config.prefixes[0]}&8]`); - else if (nickname && loggedin) bot.chat.command("nick off"); - else if (!vanished && bot.vanished && loggedin) - bot.chat.command("essentials:vanish on"); - else if (clientLock !== 4) - bot._client.write("client_command", { actionId: 0 }); - } else if ( - bot.options.isCreayun && - !bot.options.isKaboom && - !bot.options.isSavage - ) { - } 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 (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.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 }); - } - }, options.selfcareInterval); - }); - bot.on("end", () => { - if (timer) clearInterval(timer); - prefix = false; - commandSpy = false; - vanished = false; - prefix = false; - god = false; - unmuted = false; - username = false; - loggedin = false - }); - } -} -module.exports = SelfcareModule; diff --git a/src/selfcare/auth/login.js b/src/selfcare/auth/login.js new file mode 100644 index 0000000..84fd05b --- /dev/null +++ b/src/selfcare/auth/login.js @@ -0,0 +1,16 @@ +class loginSelfcare { + constructor (context) { + const bot = context.bot + const options = context.options + const config = context.config + const stringMessage = context.stringMessage + + //if (options.mode !== "savageFriends") return + + if (stringMessage === "Please, login with the command: /login ") bot.selfcare.login = true; + else if (stringMessage === "Successful login!") bot.selfcare.logged = false; + else if (stringMessage === "You're already logged in!") bot.selfcare.login = false; + } +} + +module.exports = loginSelfcare \ No newline at end of file diff --git a/src/selfcare/auth/register.js b/src/selfcare/auth/register.js new file mode 100644 index 0000000..01c8ce0 --- /dev/null +++ b/src/selfcare/auth/register.js @@ -0,0 +1,17 @@ +class registerSelfcare { + constructor (context) { + const bot = context.bot + const options = context.options + const config = context.config + const stringMessage = context.stringMessage + + //if (options.mode !== "savageFriends") return + if (stringMessage === "Please, register to the server with the command: /register ") bot.selfcare.register = true; + else if (stringMessage === "This user isn't registered!") bot.selfcare.register = true; + else if (stringMessage === "Successfully registered!") bot.selfcare.register = false; + else if (stringMessage === "You're already logged in!") bot.selfcare.register = false; + else if (stringMessage === "Successful login!") bot.selfcare.register = false; + } +} + +module.exports = registerSelfcare \ No newline at end of file diff --git a/src/selfcare/entity/gamemode.js b/src/selfcare/entity/gamemode.js index ccc6765..61d08ca 100644 --- a/src/selfcare/entity/gamemode.js +++ b/src/selfcare/entity/gamemode.js @@ -1,10 +1,10 @@ class gamemodeSelfcare { - constructor (context) { - const bot = context.bot - const config = context.config - const options = context.options - bot.selfcare.gameMode = null - + constructor(context) { + const bot = context.bot; + const config = context.config; + const options = context.options; + bot.selfcare.gameMode = null; + bot.on("packet.game_state_change", (packet) => { if (packet.reason !== 3) return; // Reason 3 = Change Game Mode bot.selfcare.gameMode = packet.gameMode; @@ -12,4 +12,4 @@ class gamemodeSelfcare { } } -module.exports = gamemodeSelfcare \ No newline at end of file +module.exports = gamemodeSelfcare; diff --git a/src/selfcare/entity/icu.js b/src/selfcare/entity/icu.js index 14c1b28..435e27e 100644 --- a/src/selfcare/entity/icu.js +++ b/src/selfcare/entity/icu.js @@ -1,20 +1,21 @@ class icuSelfcare { - constructor (context) { + constructor(context) { const bot = context.bot; - const config = context.config - const options = context.options + const config = context.config; + const options = context.options; bot.on("packet.position", (packet, position) => { - if (options.mode === "savageFriends" || options.mode === "creayun") return; - bot.selfcare.position_count++ + if (options.mode === "savageFriends" || options.mode === "creayun") + return; + bot.selfcare.position_count++; setTimeout(() => { - bot.selfcare.position_count-- + bot.selfcare.position_count--; if (bot.selfcare.position_count > 4) { - bot._client.end('anti icu') + bot._client.end("anti icu"); } - }, 1000) - }) + }, 1000); + }); } } -module.exports = icuSelfcare \ No newline at end of file +module.exports = icuSelfcare; diff --git a/src/selfcare/entity/op.js b/src/selfcare/entity/op.js index df61a25..79436b1 100644 --- a/src/selfcare/entity/op.js +++ b/src/selfcare/entity/op.js @@ -1,20 +1,19 @@ class opSelfcare { - constructor (context) { + constructor(context) { const bot = context.bot; - const config = context.config - const options = context.options - bot.selfcare.entityId = undefined - + const config = context.config; + const options = context.options; + bot.selfcare.entityId = undefined; bot.on("packet.entity_status", (packet) => { if ( packet.entityId !== bot.selfcare.entityId || packet.entityStatus < 24 || packet.entityStatus > 28 ) - return; + return; bot.selfcare.permissionLevel = packet.entityStatus - 24; }); } } -module.exports = opSelfcare \ No newline at end of file +module.exports = opSelfcare; diff --git a/src/selfcare/essentials/god.js b/src/selfcare/essentials/god.js index 3d869e7..8e68174 100644 --- a/src/selfcare/essentials/god.js +++ b/src/selfcare/essentials/god.js @@ -1,13 +1,12 @@ class godSelfcare { - constructor (context) { + constructor(context) { const bot = context.bot; const options = context.options; const stringMessage = context.stringMessage; if (stringMessage === "God mode disabled.") bot.selfcare.god = false; else if (stringMessage === "God mode enabled.") bot.selfcare.god = true; - } } -module.exports = godSelfcare \ No newline at end of file +module.exports = godSelfcare; diff --git a/src/selfcare/essentials/mute.js b/src/selfcare/essentials/mute.js index 0d708a1..4270087 100644 --- a/src/selfcare/essentials/mute.js +++ b/src/selfcare/essentials/mute.js @@ -1,13 +1,16 @@ class muteSelfcare { - constructor (context) { + constructor(context) { const bot = context.bot; const options = context.options; const stringMessage = context.stringMessage; - if (stringMessage?.startsWith("You have been muted")) bot.selfcare.mute = true; - else if (stringMessage?.startsWith("You have been unmuted")) bot.selfcare.mute = false; - else if (stringMessage?.startsWith("Your voice has been silenced")) bot.selfcare.mute = true; + if (stringMessage?.startsWith("You have been muted")) + bot.selfcare.mute = true; + else if (stringMessage?.startsWith("You have been unmuted")) + bot.selfcare.mute = false; + else if (stringMessage?.startsWith("Your voice has been silenced")) + bot.selfcare.mute = true; } } -module.exports = muteSelfcare \ No newline at end of file +module.exports = muteSelfcare; diff --git a/src/selfcare/essentials/nickname.js b/src/selfcare/essentials/nickname.js index deebe1d..f8e3626 100644 --- a/src/selfcare/essentials/nickname.js +++ b/src/selfcare/essentials/nickname.js @@ -1,12 +1,14 @@ class nicknameSelfcare { - constructor (context) { + constructor(context) { const bot = context.bot; const options = context.options; const stringMessage = context.stringMessage; - if (stringMessage === `You no longer have a nickname.`) bot.selfcare.nickname = false; - else if (stringMessage?.startsWith('Your nickname is now ')) bot.selfcare.nickname = true; + if (stringMessage === `You no longer have a nickname.`) + bot.selfcare.nickname = false; + else if (stringMessage?.startsWith("Your nickname is now ")) + bot.selfcare.nickname = true; } } -module.exports = nicknameSelfcare \ No newline at end of file +module.exports = nicknameSelfcare; diff --git a/src/selfcare/essentials/vanish.js b/src/selfcare/essentials/vanish.js index 89b50b0..18f7e30 100644 --- a/src/selfcare/essentials/vanish.js +++ b/src/selfcare/essentials/vanish.js @@ -1,12 +1,14 @@ class vanishSelfcare { - constructor (context) { + constructor(context) { const bot = context.bot; const options = context.options; const stringMessage = context.stringMessage; - if (stringMessage === `Vanish for ${bot._client.username}: enabled`) bot.selfcare.vanished = true; - else if (stringMessage === `Vanish for ${bot._client.username}: disabled`) bot.selfcare.vanished = false; + if (stringMessage === `Vanish for ${bot._client.username}: enabled`) + bot.selfcare.vanished = true; + else if (stringMessage === `Vanish for ${bot._client.username}: disabled`) + bot.selfcare.vanished = false; } } -module.exports = vanishSelfcare \ No newline at end of file +module.exports = vanishSelfcare; diff --git a/src/selfcare/extras/command_spy.js b/src/selfcare/extras/command_spy.js index b896255..314d4f1 100644 --- a/src/selfcare/extras/command_spy.js +++ b/src/selfcare/extras/command_spy.js @@ -1,16 +1,17 @@ class commandSpySelfcare { - constructor (context) { - const bot = context.bot - const stringMessage = context.stringMessage - - if (stringMessage === "Successfully enabled CommandSpy") return bot.selfcare.commandSpy = true; + constructor(context) { + const bot = context.bot; + const stringMessage = context.stringMessage; + + if (stringMessage === "Successfully enabled CommandSpy") + return (bot.selfcare.commandSpy = true); else if (stringMessage === "Successfully enabled CommandSpy.") - return bot.selfcare.commandSpy = true; + return (bot.selfcare.commandSpy = true); else if (stringMessage === "Successfully disabled CommandSpy") - return bot.selfcare.commandSpy = false; + return (bot.selfcare.commandSpy = false); else if (stringMessage === "Successfully disabled CommandSpy.") - return bot.selfcare.commandSpy = false; + return (bot.selfcare.commandSpy = false); } } -module.exports = commandSpySelfcare \ No newline at end of file +module.exports = commandSpySelfcare; diff --git a/src/selfcare/extras/prefix.js b/src/selfcare/extras/prefix.js index e2f44c2..1d9f0c9 100644 --- a/src/selfcare/extras/prefix.js +++ b/src/selfcare/extras/prefix.js @@ -1,17 +1,26 @@ class prefixSelfcare { - constructor (context) { - const bot = context.bot - const options = context.options - const stringMessage = context.stringMessage - const config = context.config + constructor(context) { + const bot = context.bot; + const options = context.options; + const stringMessage = context.stringMessage; + const config = context.config; if (options.mode === "savageFriends") { - } 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.") bot.selfcare.prefix = true; - else if (stringMessage?.startsWith("You now have the tag: ") || stringMessage === "You no longer have a tag") bot.selfcare.prefix = false + 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." + ) + bot.selfcare.prefix = true; + else if ( + stringMessage?.startsWith("You now have the tag: ") || + stringMessage === "You no longer have a tag" + ) + bot.selfcare.prefix = false; } } } -module.exports = prefixSelfcare \ No newline at end of file +module.exports = prefixSelfcare; diff --git a/src/selfcare/extras/username.js b/src/selfcare/extras/username.js index 63b1400..dd71c8c 100644 --- a/src/selfcare/extras/username.js +++ b/src/selfcare/extras/username.js @@ -1,17 +1,24 @@ class usernameSelfcare { - constructor (context) { - const bot = context.bot - const options = context.options - const stringMessage = context.stringMessage - const config = context.config + constructor(context) { + const bot = context.bot; + const options = context.options; + const stringMessage = context.stringMessage; + const config = context.config; - if (stringMessage === `Successfully set your username to "${bot._client.username}"`) { - bot.selfcare.username = false - return - } - else if (stringMessage?.startsWith("Successfully set your username to ")) bot.selfcare.username = true - else if (stringMessage === `You already have the username "${bot._client.username}"`) bot.selfcare.username = false + if ( + stringMessage === + `Successfully set your username to "${bot._client.username}"` + ) { + bot.selfcare.username = false; + return; + } else if (stringMessage?.startsWith("Successfully set your username to ")) + bot.selfcare.username = true; + else if ( + stringMessage === + `You already have the username "${bot._client.username}"` + ) + bot.selfcare.username = false; } } -module.exports = usernameSelfcare \ No newline at end of file +module.exports = usernameSelfcare; diff --git a/src/util/ansi.js b/src/util/ansi.js index 59f3d33..174d863 100644 --- a/src/util/ansi.js +++ b/src/util/ansi.js @@ -1,4 +1,4 @@ -function ansi (message) { +function ansi(message) { const ansilist = { "\x1B[93m": "\x1B[33m", // Yellow "\x1B[96m": "\x1B[36m", // Blue diff --git a/src/util/between.js b/src/util/between.js index a48d05d..27a0fd4 100644 --- a/src/util/between.js +++ b/src/util/between.js @@ -1,4 +1,4 @@ -function between (min, max) { +function between(min, max) { return Math.floor(Math.random() * (max - min) + min); } module.exports = Between; diff --git a/src/util/loadModules.js b/src/util/loadModules.js index 86d768b..9d63d87 100644 --- a/src/util/loadModules.js +++ b/src/util/loadModules.js @@ -2,7 +2,9 @@ const fs = require("fs"); const path = require("path"); async function loadModules(bot, options, config, discordClient) { bot.modules = []; - for (const filename of fs.readdirSync(path.join(__dirname, "../", "modules"))) { + for (const filename of fs.readdirSync( + path.join(__dirname, "../", "modules"), + )) { try { if (filename.endsWith(".js")) { const module = require(path.join(__dirname, "../modules", filename)); diff --git a/src/util/loadPlugins.js b/src/util/loadPlugins.js index 9a528bb..9bd450d 100644 --- a/src/util/loadPlugins.js +++ b/src/util/loadPlugins.js @@ -2,7 +2,9 @@ const fs = require("fs"); const path = require("path"); async function loadPlugins(bot, options, config, discordClient) { bot.plugins = []; - for (const filename of fs.readdirSync(path.join(__dirname, "../", "plugins"))) { + for (const filename of fs.readdirSync( + path.join(__dirname, "../", "plugins"), + )) { try { if (filename.endsWith(".js")) { const plugin = require(path.join(__dirname, "../plugins", filename));