Files
NitoriBot/src/modules/command_handler.js
T

57 lines
1.8 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)
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-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,
null
2025-05-07 07:27:41 -04:00
);
source.sendFeedback = (message) => {
2025-08-18 16:54:25 -05:00
if (source.sources.console) bot.console.command();
else if (source.sources.discord) {
2025-08-18 16:54:25 -05:00
return message // lazy
} 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) {
2025-08-18 16:54:25 -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-12 10:39:50 -05:00
module.exports = command_handler;