mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-11-29 13:45:38 -05:00
partially switched over to prismarine chats message builder
This commit is contained in:
@@ -2,7 +2,7 @@ class CommandSource {
|
||||
constructor(player, sources, hash) {
|
||||
this.player = player;
|
||||
this.sources = sources;
|
||||
this.hash = hash;
|
||||
this.player.hash = hash;
|
||||
}
|
||||
}
|
||||
module.exports = CommandSource;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
const CommandError = require("../../command_util/command_error");
|
||||
const CommandContext = require("../../command_util/command_context");
|
||||
const CommandTrustLevel = require('../../command_util/command_trust_level')
|
||||
const trustLevel = new CommandTrustLevel()
|
||||
|
||||
class kick extends CommandContext {
|
||||
constructor() {
|
||||
super("kick", [], "kick a player from the server", 2, [
|
||||
super("kick", [], "kick a player from the server", trustLevel.admin, [
|
||||
"invalidstring",
|
||||
"item",
|
||||
"te",
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
const CommandContext = require("../../command_util/command_context");
|
||||
const CommandError = require('../../command_util/command_error')
|
||||
const CommandTrustLevel = require('../../command_util/command_trust_level')
|
||||
const trustLevel = new CommandTrustLevel()
|
||||
|
||||
class console extends CommandContext {
|
||||
constructor() {
|
||||
super("console", ["c"], "runs commands made for the bots console", 4, [
|
||||
super("console", ["c"], "runs commands made for the bots console", trustLevel.console, [
|
||||
"server/srv <all/servername>",
|
||||
"customchat <on/true/enable/off/false/disable>",
|
||||
"say <message>",
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
const CommandContext = require("../../command_util/command_context");
|
||||
const CommandTrustLevel = require('../../command_util/command_trust_level')
|
||||
const trustLevel = new CommandTrustLevel()
|
||||
|
||||
class kill extends CommandContext {
|
||||
constructor() {
|
||||
super("kill", ["suicide", "quit"], "kill the bots process", 3, [""]);
|
||||
super("kill", ["suicide", "quit"], "kill the bots process", trustLevel.owner, [""]);
|
||||
}
|
||||
execute(context) {
|
||||
const bot = context.bot;
|
||||
|
||||
@@ -1,23 +1,33 @@
|
||||
const CommandContext = require("../../command_util/command_context");
|
||||
const CommandTrustLevel = require('../../command_util/command_trust_level')
|
||||
const trustLevel = new CommandTrustLevel()
|
||||
|
||||
class validate extends CommandContext {
|
||||
constructor() {
|
||||
super("validate", ["val"], "validate through the bot", 1, [""]);
|
||||
super("validate", ["val"], "validate through the bot", trustLevel.trusted, [""]);
|
||||
}
|
||||
execute(context) {
|
||||
const bot = context.bot;
|
||||
const args = context.arguments;
|
||||
const source = context.source;
|
||||
const config = context.config;
|
||||
const { MessageBuilder } = require('prismarine-chat')(bot.registry.version)
|
||||
|
||||
if (args[0] === bot.validation.trusted) {
|
||||
bot.chat.message("&2Valid Trusted hash");
|
||||
}
|
||||
if (args[0] === bot.validation.admin) {
|
||||
bot.chat.message("&2Valid Admin hash");
|
||||
}
|
||||
if (args[0] === bot.validation.owner) {
|
||||
bot.chat.message("&2Valid Owner hash");
|
||||
}
|
||||
if (source.player.hash === "trusted") source.sendFeedback(
|
||||
new MessageBuilder()
|
||||
.setText('Valid Trusted Hash')
|
||||
.setColor(config.colors.help.trusted)
|
||||
)
|
||||
else if (source.player.hash === "admin") source.sendFeedback(
|
||||
new MessageBuilder()
|
||||
.setText('Valid Admin Hash')
|
||||
.setColor(config.colors.help.admin)
|
||||
)
|
||||
else if (source.player.hash === "owner") source.sendFeedback(
|
||||
new MessageBuilder()
|
||||
.setText('Valid Owner Hash')
|
||||
.setColor(config.colors.help.owner)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,23 @@ class command_handler {
|
||||
|
||||
if (!plainMessage?.startsWith(prefix)) return;
|
||||
const command = plainMessage.substring(prefix.length);
|
||||
|
||||
const source = new CommandSource(
|
||||
data.sender,
|
||||
{ discord: false, console: false },
|
||||
true,
|
||||
null
|
||||
);
|
||||
|
||||
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";
|
||||
ratelimit++;
|
||||
setTimeout(() => {
|
||||
ratelimit--;
|
||||
|
||||
@@ -5,52 +5,51 @@ const CommandSource = require("../command_util/command_source");
|
||||
const fixansi = require("../util/ansi");
|
||||
const sleep = require("../util/sleep.js");
|
||||
|
||||
function unknownCommand (MessageBuilder, commandName, bot) {
|
||||
return new MessageBuilder()
|
||||
.setTranslate("%s%s%s %s")
|
||||
.setColor("red")
|
||||
.addWith(
|
||||
new MessageBuilder()
|
||||
.setTranslate("command.unknown.command")
|
||||
.setColor('red'),
|
||||
new MessageBuilder()
|
||||
.setText('\n'),
|
||||
new MessageBuilder()
|
||||
.setText(`${commandName}`)
|
||||
.setColor("gray"),
|
||||
new MessageBuilder()
|
||||
.setTranslate("command.context.here")
|
||||
.setColor("red")
|
||||
)
|
||||
}
|
||||
|
||||
class command_manager {
|
||||
constructor(context) {
|
||||
const bot = context.bot;
|
||||
const config = context.config;
|
||||
const discordClient = context.discordClient;
|
||||
const options = context.options;
|
||||
const { MessageBuilder } = require('prismarine-chat')(bot._client.version)
|
||||
|
||||
|
||||
bot.commandManager = {
|
||||
commands: {},
|
||||
commandlist: [],
|
||||
execute(source, commandName, args) {
|
||||
const command = this.getCommand(commandName.toLowerCase());
|
||||
|
||||
try {
|
||||
if (!command) {
|
||||
if (source?.sources?.console) {
|
||||
bot.console.warn(
|
||||
bot
|
||||
.getMessageAsPrismarine({
|
||||
translate: "%s%s%s %s",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ translate: "command.unknown.command", color: "red" },
|
||||
{ text: "\n" },
|
||||
{ text: `${commandName}` },
|
||||
{ translate: "command.context.here", color: "red" },
|
||||
],
|
||||
})
|
||||
?.toAnsi(),
|
||||
);
|
||||
} else {
|
||||
throw new CommandError({
|
||||
translate: "%s%s%s %s",
|
||||
color: "dark_gray",
|
||||
with: [
|
||||
{ translate: "command.unknown.command", color: "red" },
|
||||
{ text: "\n" },
|
||||
{ text: `${commandName}` },
|
||||
{ translate: "command.context.here", color: "red" },
|
||||
],
|
||||
});
|
||||
}
|
||||
if (source?.sources?.console) bot.console.command(
|
||||
unknownCommand(MessageBuilder, commandName, bot)
|
||||
)
|
||||
else source.sendFeedback(unknownCommand(MessageBuilder, commandName, bot))
|
||||
}
|
||||
|
||||
const event = bot.discord.message;
|
||||
const roles = event?.member?.roles?.cache;
|
||||
|
||||
console.log(command)
|
||||
switch (command?.data?.trustLevel) {
|
||||
case 0:
|
||||
// do nothing since trust level 0 is public
|
||||
@@ -64,29 +63,27 @@ class command_manager {
|
||||
role.name === `${config.discord.roles.fullAccess}` ||
|
||||
role.name === `${config.discord.roles.owner}`,
|
||||
);
|
||||
if (!hasRole)
|
||||
throw new CommandError({
|
||||
translate:
|
||||
"You dont have the trusted, admin, or owner role!",
|
||||
color: "dark_red",
|
||||
});
|
||||
if (!hasRole) throw new CommandError(
|
||||
new MessageBuilder()
|
||||
.setText("You dont have the trusted, admin, or owner roles!")
|
||||
.setColor("red")
|
||||
)
|
||||
} else if (!source?.sources.console) {
|
||||
if (args.length === 0)
|
||||
throw new CommandError({
|
||||
text: "Please provide a trusted, admin or owner hash",
|
||||
color: "dark_red",
|
||||
});
|
||||
if (args.length === 0) throw new CommandError(
|
||||
new MessageBuilder()
|
||||
.setText("Please provide a trusted, admin, or owner hash")
|
||||
.setColor("red")
|
||||
)
|
||||
if (
|
||||
args[0] !== bot.validation.trusted &&
|
||||
args[0] !== bot.validation.admin &&
|
||||
args[0] !== bot.validation.owner
|
||||
) throw new CommandError(
|
||||
new MessageBuilder()
|
||||
.setText("Invalid Hash")
|
||||
.setColor("red")
|
||||
)
|
||||
throw new CommandError({
|
||||
translate: "Invalid trusted, admin or owner hash",
|
||||
color: "dark_red",
|
||||
});
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
if (source?.sources?.discord) {
|
||||
@@ -96,25 +93,26 @@ class command_manager {
|
||||
role.name === `${config.discord.roles.fullAccess}` ||
|
||||
role.name === `${config.discord.roles.owner}`,
|
||||
);
|
||||
if (!hasRole)
|
||||
throw new CommandError({
|
||||
translate: "You dont have the admin, or owner role!",
|
||||
color: "dark_red",
|
||||
});
|
||||
if (!hasRole) throw new CommandError(
|
||||
new MessageBuilder()
|
||||
.setText("You dont have the admin, or owner roles!")
|
||||
.setColor("red")
|
||||
)
|
||||
} else if (!source?.sources?.console) {
|
||||
if (args.length === 0)
|
||||
throw new CommandError({
|
||||
text: "Please provide an admin or owner hash",
|
||||
color: "dark_red",
|
||||
});
|
||||
throw new CommandError(
|
||||
new MessageBuilder()
|
||||
.setText('Please provide a hash')
|
||||
.setColor('red')
|
||||
);
|
||||
if (
|
||||
args[0] !== bot.validation.admin &&
|
||||
args[0] !== bot.validation.owner
|
||||
)
|
||||
throw new CommandError({
|
||||
translate: "Invalid admin or owner hash",
|
||||
color: "dark_red",
|
||||
});
|
||||
throw new CommandError(
|
||||
new MessageBuilder()
|
||||
.setText('Invalid Hash')
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
@@ -125,33 +123,43 @@ class command_manager {
|
||||
role.name === `${config.discord.roles.fullAccess}`,
|
||||
);
|
||||
if (!hasRole)
|
||||
throw new CommandError({
|
||||
translate: "You do not have the owner role!",
|
||||
color: "dark_red",
|
||||
});
|
||||
throw new CommandError(
|
||||
new MessageBuilder()
|
||||
.setText("You dont have the owner role!")
|
||||
.setColor("red")
|
||||
)
|
||||
} else if (!source?.sources?.console) {
|
||||
if (args.length === 0 && bot.validation.owner)
|
||||
throw new CommandError({
|
||||
text: "Please provide an owner hash",
|
||||
color: "dark_red",
|
||||
});
|
||||
throw new CommandError(
|
||||
new MessageBuilder()
|
||||
.setText("Please provide a hash")
|
||||
.setColor('red')
|
||||
);
|
||||
|
||||
if (args[0] !== bot.validation.owner)
|
||||
throw new CommandError({
|
||||
translate: "Invalid owner hash",
|
||||
color: "dark_red",
|
||||
});
|
||||
throw new CommandError(
|
||||
new MessageBuilder()
|
||||
.setText('Invalid Hash')
|
||||
.setColor('red')
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (!source?.sources?.console) {
|
||||
throw new CommandError({
|
||||
text: "This command can only be ran via console",
|
||||
color: "dark_red",
|
||||
});
|
||||
|
||||
throw new CommandError(
|
||||
new MessageBuilder()
|
||||
.setText("This Command can only be ran via console")
|
||||
.setColor('red')
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
throw new CommandError({ text: 'This Command has been disabled!', color: 'red' })
|
||||
throw new CommandError(
|
||||
new MessageBuilder()
|
||||
.setText("This Command has been disabled!")
|
||||
.setColor('red')
|
||||
)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -159,13 +167,13 @@ class command_manager {
|
||||
discordClient.channels.cache
|
||||
.get("1361739286113685534")
|
||||
.send(
|
||||
`User: ${source.player.profile.name}, Command: ${command.data.name}, Args: ${args.join(" ")}, Time/Date: ${new Date().toLocaleString("en-us", { TimeZone: "America/Chicago" })}, Source: Discord`,
|
||||
`User: ${source.player.profile.name}, Command: ${command?.data?.name}, Args: ${args.join(" ")}, Time/Date: ${new Date().toLocaleString("en-us", { TimeZone: "America/Chicago" })}, Source: Discord`,
|
||||
);
|
||||
} else if (!source.sources.console) {
|
||||
discordClient.channels.cache
|
||||
.get("1361739286113685534")
|
||||
.send(
|
||||
`User: ${source.player.profile.name}, Command: ${command.data.name}, Args: ${args.join(" ")}, Time/Date: ${new Date().toLocaleString("en-us", { TimeZone: "America/Chicago" })}, Source: Minecraft, Server: ${bot.options.host}:${bot.options.port}`,
|
||||
`User: ${source.player.profile.name}, Command: ${command?.data?.name}, Args: ${args.join(" ")}, Time/Date: ${new Date().toLocaleString("en-us", { TimeZone: "America/Chicago" })}, Source: Minecraft, Server: ${bot.options.host}:${bot.options.port}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -231,8 +239,8 @@ class command_manager {
|
||||
};
|
||||
|
||||
/*
|
||||
command loader ported from my discord bot SkiBot
|
||||
*/
|
||||
command loader ported from my discord bot SkiBot
|
||||
*/
|
||||
let commandlist = [];
|
||||
const foldersPath = path.join(__dirname, "../commands");
|
||||
const commandFolders = fs.readdirSync(foldersPath);
|
||||
|
||||
@@ -97,6 +97,15 @@ class Console { // named it Console so that it doesnt override the console varia
|
||||
?.toAnsi() + message,
|
||||
);
|
||||
},
|
||||
command (message) {
|
||||
console.log(
|
||||
prismarineChat
|
||||
.fromNotch(
|
||||
`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO" })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })} §6command§8] §8[${serverName}§8] `,
|
||||
)
|
||||
?.toAnsi() + prismarineChat.fromNotch(message)?.toAnsi(bot.registry.language),
|
||||
);
|
||||
}
|
||||
};
|
||||
setInterval(() => (ratelimit = 0), 1000 * 2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user