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) => {
|
2025-09-12 12:54:08 -05:00
|
|
|
try {
|
|
|
|
|
if (data.type !== "minecraft:chat" && data.type !== "extras:command_spy") return;
|
2025-05-07 07:27:41 -04:00
|
|
|
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-09-12 12:54:08 -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-09-12 12:54:08 -05:00
|
|
|
data.trustLevel,
|
|
|
|
|
data.validateBypass
|
2025-05-07 07:27:41 -04:00
|
|
|
);
|
2025-08-12 12:01:11 -05:00
|
|
|
|
|
|
|
|
source.sendFeedback = (message) => {
|
2025-08-28 09:25:11 -05:00
|
|
|
if (options.mode === "savageFriends") bot.tellraw(`@a[name=${source.player.profile.name}]`, [
|
2025-08-22 11:52:57 -05:00
|
|
|
message
|
2025-08-28 09:25:11 -05:00
|
|
|
])
|
|
|
|
|
else bot.tellraw(`@a[name="${source.player.profile.name}"]`, message)
|
|
|
|
|
}
|
2025-08-12 12:01:11 -05:00
|
|
|
|
2025-05-07 07:27:41 -04:00
|
|
|
ratelimit++;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
ratelimit--;
|
|
|
|
|
}, 1000);
|
|
|
|
|
if (ratelimit > config.ratelimit.commands) {
|
2025-08-22 11:52:57 -05:00
|
|
|
return;
|
2025-05-07 07:27:41 -04:00
|
|
|
} 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-28 09:25:11 -05:00
|
|
|
module.exports = command_handler;
|