From 27a6b07845068cc71014ac55cac5d448b3fa21d6 Mon Sep 17 00:00:00 2001 From: Parker2991 Date: Tue, 6 Jan 2026 22:24:50 -0600 Subject: [PATCH] add the missing command folders --- bot/FNFBoyfriendBot.ts | 6 ++- bot/bot.ts | 4 +- bot/command/CommandContext.ts | 12 ++++++ bot/command/CommandError.ts | 18 +++++++++ bot/command/CommandSource.ts | 10 +++++ bot/command/source.ts | 20 ---------- bot/commands/admin/.gitkeep | 0 bot/commands/console/.gitkeep | 0 bot/commands/owner/.gitkeep | 0 bot/commands/public/test.ts | 48 ++++++++++++++++++++++ bot/commands/trusted/.gitkeep | 0 bot/modules/chat.ts | 4 ++ bot/modules/commandHandler.ts | 9 +++-- bot/modules/commandManager.ts | 75 +++++++++++++++++++++++++++++++++++ bot/modules/console.ts | 2 +- bot/modules/memUsage.ts | 3 +- bot/modules/reconnect.ts | 20 ---------- bot/modules/sign.ts | 17 ++++++++ bot/resources/version.json | 2 +- bot/util/loadCommands.ts | 39 ++++++++++++++++++ tsconfig.json | 1 + 21 files changed, 242 insertions(+), 48 deletions(-) create mode 100644 bot/command/CommandContext.ts create mode 100644 bot/command/CommandError.ts create mode 100644 bot/command/CommandSource.ts delete mode 100644 bot/command/source.ts create mode 100644 bot/commands/admin/.gitkeep create mode 100644 bot/commands/console/.gitkeep create mode 100644 bot/commands/owner/.gitkeep create mode 100644 bot/commands/public/test.ts create mode 100644 bot/commands/trusted/.gitkeep create mode 100644 bot/modules/sign.ts create mode 100644 bot/util/loadCommands.ts diff --git a/bot/FNFBoyfriendBot.ts b/bot/FNFBoyfriendBot.ts index 374e62f..0cd76f3 100644 --- a/bot/FNFBoyfriendBot.ts +++ b/bot/FNFBoyfriendBot.ts @@ -13,11 +13,13 @@ import { position } from './modules/position'; import { core } from './modules/core'; import { reconnect } from './modules/reconnect'; import { commandManager } from './modules/commandManager'; +import { sign } from './modules/sign'; export default class FNFBoyfriendBot extends EventEmitter { public _client: any public bots: any; public chat: any; + public commandManager: any; public core: any; public console: any; public entityId: number; @@ -45,6 +47,7 @@ export default class FNFBoyfriendBot extends EventEmitter { this.options = options; new chat({ bot: this, config }); + new commandManager({ bot: this, config }) new Console({ bot: this, config }); new players({ bot: this, config }); new registry({ bot: this, config }); @@ -54,6 +57,7 @@ export default class FNFBoyfriendBot extends EventEmitter { new reconnect({ bot: this, config }); new position({ bot: this, config }); new core({ bot: this, config }); - new commandHandler({ bot: this, config }) + new commandHandler({ bot: this, config }); + new sign({ bot: this, config }) } } diff --git a/bot/bot.ts b/bot/bot.ts index 58ff059..b74afaa 100644 --- a/bot/bot.ts +++ b/bot/bot.ts @@ -18,7 +18,9 @@ export class createBot extends FNFBoyfriendBot { client?.on("end", (reason: any) => { bot.emit("end", reason); - }) + }); + + // client.on("error", (error: any) => console.error(error)) }) const client = mc.createClient(options) diff --git a/bot/command/CommandContext.ts b/bot/command/CommandContext.ts new file mode 100644 index 0000000..5e56f2a --- /dev/null +++ b/bot/command/CommandContext.ts @@ -0,0 +1,12 @@ +export class CommandContext { + public data: any + constructor (aliases: any, description: any, usages: any) { + this.data = {}; + + this.data.aliases = aliases; + + this.data.description = description; + + this.data.usages = usages; + } +} \ No newline at end of file diff --git a/bot/command/CommandError.ts b/bot/command/CommandError.ts new file mode 100644 index 0000000..f689373 --- /dev/null +++ b/bot/command/CommandError.ts @@ -0,0 +1,18 @@ +// ported from FNFBoyfriendBot v8.0.0 + +const ChatMessage = require("prismarine-chat")("1.21.8"); +const stringify = (message: any) => new ChatMessage(message)?.toString(); + +export class CommandError extends Error { + public _message: any; + + constructor(message: any) { + super(stringify(message)) + this.name = "CommandError"; + this._message = message; + } + + get message() { + return stringify(this._message); + } +} diff --git a/bot/command/CommandSource.ts b/bot/command/CommandSource.ts new file mode 100644 index 0000000..7d797fb --- /dev/null +++ b/bot/command/CommandSource.ts @@ -0,0 +1,10 @@ +export class CommandSource { + public player: any; + + public prefix: any; + + constructor (player: any, prefix: any) { + this.player = player; + this.prefix = prefix; + } +} \ No newline at end of file diff --git a/bot/command/source.ts b/bot/command/source.ts deleted file mode 100644 index 3772b0d..0000000 --- a/bot/command/source.ts +++ /dev/null @@ -1,20 +0,0 @@ -export class source { - public player: any; - public uuid: any; - public prefix: any; - - constructor (player: any, uuid: any, prefix: any) { - - } -} - -/* - constructor(player, sources, ChatType) { - this.player = player; - this.sources = sources; - this.ChatType = ChatType; - this.player.trustLevel = 0; - } -} -module.exports = CommandSource; -*/ \ No newline at end of file diff --git a/bot/commands/admin/.gitkeep b/bot/commands/admin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/bot/commands/console/.gitkeep b/bot/commands/console/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/bot/commands/owner/.gitkeep b/bot/commands/owner/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/bot/commands/public/test.ts b/bot/commands/public/test.ts new file mode 100644 index 0000000..d220de9 --- /dev/null +++ b/bot/commands/public/test.ts @@ -0,0 +1,48 @@ +import { CommandContext } from '../../command/CommandContext'; + +export default class test extends CommandContext { + constructor() { + super( + ['te'], + "testing stuff", + [] + ) + } + + execute (context: any) { + const bot = context.bot; + const config = context.config; + const args = context.arguments; + const Item = require("prismarine-item")(bot.options.version); + //console.log(Item) + let position = { x: bot.position.x, y: bot.position.y - 1, z: bot.position.z } + + console.log(Item.toNotch( new Item( bot.registry.itemsByName.oak_sign.id, 1, 0, ), ),) + bot._client.write('set_creative_slot', { + slot: 36, + item: Item.toNotch( + new Item( + bot.registry.itemsByName.oak_sign.id, + 1, + 0, + ), + ), + }); + + bot._client.write('block_dig', { + status: 0, + location: position, + face: 0 + }); + + bot._client.write('block_place', { + hand: 0, + location: position, + direction: 0, + cursorX: 0.1, + cursorY: 0, + cursorZ: 0.1, + insideBlock: false + }); + } +} diff --git a/bot/commands/trusted/.gitkeep b/bot/commands/trusted/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/bot/modules/chat.ts b/bot/modules/chat.ts index ce5429d..5b511c5 100644 --- a/bot/modules/chat.ts +++ b/bot/modules/chat.ts @@ -182,5 +182,9 @@ export class chat { bot.chat.message(message); } } + + bot.tellraw = (selector: any, message: any) => { + bot.core.run(`minecraft:tellraw ${selector} ` + JSON.stringify(message)) + } } } \ No newline at end of file diff --git a/bot/modules/commandHandler.ts b/bot/modules/commandHandler.ts index 3b3c400..2504e30 100644 --- a/bot/modules/commandHandler.ts +++ b/bot/modules/commandHandler.ts @@ -1,4 +1,4 @@ -import { source } from '../command/source'; +import { CommandSource } from '../command/CommandSource'; export class commandHandler { constructor (context: any) { @@ -11,12 +11,15 @@ export class commandHandler { const prefixes = config.prefixes; const message = packet.contents; const plainMessage = bot.getMessageAsPrismarine(message)?.toString(); + const player = packet.player for (const prefix of prefixes) { if (!plainMessage.startsWith(prefix)) return; const command = plainMessage.substring(prefix.length); - const getPrefix = plainMessage.split(command)[0]; - bot.core.run(command) + if (command.length == 0) return; + const getPrefix = plainMessage.split(command)[0] + const source = new CommandSource(player, prefix) + bot.commandManager.executeString(source, command) } } catch (e) { if (e instanceof Error) bot.console.info(e.stack) diff --git a/bot/modules/commandManager.ts b/bot/modules/commandManager.ts index c13e2b8..1d9b45d 100644 --- a/bot/modules/commandManager.ts +++ b/bot/modules/commandManager.ts @@ -1,8 +1,83 @@ +import { loadCommands } from '../util/loadCommands'; +import { CommandError } from '../command/CommandError'; + export class commandManager { constructor (context: any) { const bot = context.bot; const config = context.config; const options = bot.options; + bot.commandManager = { + commands: {}, + + list: [], + + execute (source: any, commandName: any, args: any) { + const command = this.getCommand(commandName.toLowerCase()); + + try { + if (!command) throw new CommandError({ + 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" } + ] + }) + + return command?.execute({ bot, config, arguments: args }) + } catch (e) { + if (e instanceof CommandError) bot.tellraw("@a", e._message); + else { + bot.console.info(e); + bot.tellraw("@a", + { + translate: "command.failed", + color: "red", + hoverEvent: { + action: "show_text", + contents: String(e), + }, + } + ) + } + } + }, + + executeString (source: any, command: any) { + const [commandName, ...args] = command.split(" "); + + return this.execute(source, commandName, args); + }, + + register (command: any, filename: any, folderName: any) { + const commandName = filename.split('.js')[0]; + command.data.name = commandName; + + if (folderName === "public") command.data.trustLevel = [0, "public"]; + if (folderName === "trusted") command.data.trustLevel = [0, "trusted"]; + if (folderName === "admin") command.data.trustLevel = [0, "admin"]; + if (folderName === "owner") command.data.trustLevel = [0, "owner"]; + if (folderName === "console") command.data.trustLevel = [0, "console"]; + else command.data.trustLevel = [5, "unknown"]; + this.commands[command.data.name] = command; + + if (command.data.aliases) { + command.data.aliases.map((aliases: any) => this.commands[aliases] = command) + } + }, + + getCommand(name: any) { + return this.commands[name]; + }, + + getCommands() { + return Object.values(this.commands); + }, + } + + loadCommands(bot, config); } } \ No newline at end of file diff --git a/bot/modules/console.ts b/bot/modules/console.ts index 1fe8226..255c27d 100644 --- a/bot/modules/console.ts +++ b/bot/modules/console.ts @@ -17,7 +17,7 @@ export class Console { rl.on("line", (args: any) => { console.log(args) - if (options.serverName !== this.server && this.server !== "all") return; + //if (options.serverName !== this.server && this.server !== "all") return; if (args.startsWith(config.console.prefix)) { diff --git a/bot/modules/memUsage.ts b/bot/modules/memUsage.ts index 570bdc6..45a46c5 100644 --- a/bot/modules/memUsage.ts +++ b/bot/modules/memUsage.ts @@ -5,7 +5,8 @@ export class memUsage { constructor (context: any) { const bot = context.bot; const config = context.config; - + if (!config.debug.memoryUsage) return; + setInterval(() => { let mbDivide = 1048576; bot.console.info(`[Heap Memory] ${Math.floor(process.memoryUsage().heapUsed / mbDivide)} MB / ${Math.floor(process.memoryUsage().heapTotal / mbDivide)} MB`); diff --git a/bot/modules/reconnect.ts b/bot/modules/reconnect.ts index 82067bc..471dee5 100644 --- a/bot/modules/reconnect.ts +++ b/bot/modules/reconnect.ts @@ -17,23 +17,3 @@ export class reconnect { }) } } - -/* - bot.on("end", () => { - setTimeout(() => { - if (options.usernameGen) { - client = - options.client ?? - mc.createClient(options, (options.username = usernameGen())); - } else { - client = options.client ?? mc.createClient(options); - } - bot._client = client; - bot.emit("init_client", bot._client); - }, bot.reconnectDelay); - }); - } -} -module.exports = reconnect; - -*/ \ No newline at end of file diff --git a/bot/modules/sign.ts b/bot/modules/sign.ts new file mode 100644 index 0000000..30dd44a --- /dev/null +++ b/bot/modules/sign.ts @@ -0,0 +1,17 @@ +const convertNbtToComponent = require('../util/convertNbtComponentToJson'); + +export class sign { + constructor (context: any) { + const bot = context.bot; + const options = bot.options; + + bot.on('packet.tile_entity_data', (packet: any) => { + const front = convertNbtToComponent(null, packet.nbtData.value.front_text); + const back = convertNbtToComponent(null, packet.nbtData.value.back_text); + console.log(front); + console.log(back); + }); + + bot.on("packet.error", (error: any) => console.error(error)) + } +}; diff --git a/bot/resources/version.json b/bot/resources/version.json index 78e9434..81ac732 100644 --- a/bot/resources/version.json +++ b/bot/resources/version.json @@ -1,5 +1,5 @@ { - "build": "5000", + "build": "5010", "codename": "ยง5Madoka", "version": "v9.0.0-alpha" } \ No newline at end of file diff --git a/bot/util/loadCommands.ts b/bot/util/loadCommands.ts new file mode 100644 index 0000000..cdd8d5a --- /dev/null +++ b/bot/util/loadCommands.ts @@ -0,0 +1,39 @@ +import fs from 'fs'; +import path from 'path'; + +export async function loadCommands (bot: any, config: any) { + const foldersPath = path.join(__dirname, "../commands"); + const commandFolders = fs.readdirSync(foldersPath); + for (const folder of commandFolders) { + const commandsPath = path.join(foldersPath, folder); + const commandFiles = fs.readdirSync(commandsPath); + for (const filename of commandFiles) { + try { + const filePath = path.join(commandsPath, filename); + + if (filename.endsWith(".js")) { + const folderName = path.basename(path.dirname(filePath)); + const commands = await import(filePath); + const command = new commands.default(); + bot.commandManager.register(command, filename, folderName); + bot.commandManager.list.push(command); + //console.log(command) + //console.log(new commands.default()) + //const command = new commands.default(); + //console.log(command) + // bot.commandManager.register(command, filename, folderName); +// console.log(command.default) + // console.log(path.basename(path.dirname(filePath))); +// console.log(path.dirname(commandFolders)) + // console.log(path.dirname(filename).split(filePath)) + // console.log(path.dirname(filename)) +// console.log(filename); + // path.dirname(filename).split(path.sep).pop() +// console.log(commandsPath) + } + } catch (error) { + console.error("Failed to load command", filename, ":", error); + } + } + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 234a1cf..7405015 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "declarationMap": false, "noUncheckedIndexedAccess": true, "strict": true, + "resolveJsonModule": true, // "jsx": "react-jsx", "verbatimModuleSyntax": false, "isolatedModules": false,