2025-05-07 07:27:41 -04:00
|
|
|
const CommandSource = require("../command_util/command_source");
|
2025-01-15 11:32:27 -05:00
|
|
|
|
2025-08-12 10:39:50 -05:00
|
|
|
class command_handler {
|
2025-05-07 07:27:41 -04:00
|
|
|
constructor(context) {
|
|
|
|
|
let ratelimit = 0;
|
|
|
|
|
const bot = context.bot;
|
|
|
|
|
const config = context.config;
|
|
|
|
|
const options = context.options;
|
v7.0.5, build: 2200. debloated the bot, implemented some v8 features, converted the config to js, made the disconnect, error, and kick_disconnect packets emit as clientDisconnect, fixed mem leaks, made vanish and command spy selfcare use core, removed filter, customchat, command suggestions and boot modules
2025-04-02 16:52:01 -04:00
|
|
|
|
2025-05-07 07:27:41 -04:00
|
|
|
bot.on("parsed_message", (data) => {
|
|
|
|
|
try {
|
|
|
|
|
if (data.type !== "minecraft:chat") return;
|
|
|
|
|
const prefixes = config.prefixes;
|
|
|
|
|
prefixes.map((prefix) => {
|
|
|
|
|
const plainMessage = bot
|
|
|
|
|
.getMessageAsPrismarine(data.contents)
|
2025-08-14 10:13:54 -05:00
|
|
|
?.toString();
|
2025-03-14 08:01:58 -04:00
|
|
|
|
2025-05-07 07:27:41 -04:00
|
|
|
if (!plainMessage?.startsWith(prefix)) return;
|
|
|
|
|
const command = plainMessage.substring(prefix.length);
|
2025-08-12 12:01:11 -05:00
|
|
|
|
2025-05-07 07:27:41 -04:00
|
|
|
const source = new CommandSource(
|
|
|
|
|
data.sender,
|
|
|
|
|
{ discord: false, console: false },
|
2025-08-14 10:13:54 -05:00
|
|
|
data.chatType,
|
2025-08-12 12:01:11 -05:00
|
|
|
null
|
2025-05-07 07:27:41 -04:00
|
|
|
);
|
2025-08-12 12:01:11 -05:00
|
|
|
|
|
|
|
|
source.sendFeedback = (message) => {
|
|
|
|
|
if (source.sources.console) bot.console.command(message);
|
|
|
|
|
else if (source.sources.discord) {
|
|
|
|
|
// i dont know what to do for discord yet
|
|
|
|
|
} 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";
|
2025-05-07 07:27:41 -04:00
|
|
|
ratelimit++;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
ratelimit--;
|
|
|
|
|
}, 1000);
|
|
|
|
|
if (ratelimit > config.ratelimit.commands) {
|
|
|
|
|
bot.tellraw("@a", {
|
|
|
|
|
text: "You are using commands too fast!",
|
|
|
|
|
color: "dark_red",
|
|
|
|
|
});
|
|
|
|
|
} else if (command.split(" ")[0].length === 0) {
|
|
|
|
|
} else {
|
|
|
|
|
bot.commandManager.executeString(source, command);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log(e.stack);
|
2024-10-23 10:33:14 -04:00
|
|
|
}
|
2025-05-07 07:27:41 -04:00
|
|
|
});
|
|
|
|
|
}
|
2024-10-23 10:33:14 -04:00
|
|
|
}
|
2025-08-12 10:39:50 -05:00
|
|
|
module.exports = command_handler;
|