Files
NitoriBot/src/modules/command_handler.js
T

47 lines
1.3 KiB
JavaScript
Raw Normal View History

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;
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)
?.toMotd();
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);
const source = new CommandSource(
data.sender,
{ discord: false, console: false },
true,
);
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;