forked from afspiegeling/NitoriBot
add the missing command folders
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export class CommandSource {
|
||||
public player: any;
|
||||
|
||||
public prefix: any;
|
||||
|
||||
constructor (player: any, prefix: any) {
|
||||
this.player = player;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
*/
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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)) {
|
||||
|
||||
|
||||
@@ -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`);
|
||||
|
||||
@@ -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;
|
||||
|
||||
*/
|
||||
@@ -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))
|
||||
}
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"build": "5000",
|
||||
"build": "5010",
|
||||
"codename": "§5Madoka",
|
||||
"version": "v9.0.0-alpha"
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
"declarationMap": false,
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"strict": true,
|
||||
"resolveJsonModule": true,
|
||||
// "jsx": "react-jsx",
|
||||
"verbatimModuleSyntax": false,
|
||||
"isolatedModules": false,
|
||||
|
||||
Reference in New Issue
Block a user