mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-12-02 07:05:39 -05:00
rewrote the trust levels
This commit is contained in:
+8
-4
@@ -16,7 +16,7 @@ function tryParse(json) {
|
||||
function parse (chatTypes, type, sender, target, message) {
|
||||
const chatType = chatTypes[type]
|
||||
const parsed = convertNbtComponentToJson(null, chatType.value.value.chat)
|
||||
const json = { translate: parsed.translation_key, with: [] }
|
||||
let json = { translate: parsed.translation_key, with: [] }
|
||||
|
||||
for (const parameter of parsed.parameters) {
|
||||
|
||||
@@ -29,6 +29,8 @@ function parse (chatTypes, type, sender, target, message) {
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 4) json = message
|
||||
|
||||
return json
|
||||
}
|
||||
|
||||
@@ -68,6 +70,8 @@ class chat {
|
||||
type: "minecraft:disguised_chat",
|
||||
message: parsed
|
||||
})
|
||||
|
||||
tryParsingMessage(parsed, { senderName: sender, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine, chatType: "minecraft:diguised_chat" })
|
||||
});
|
||||
|
||||
bot.on("packet.player_chat", (packet, data) => {
|
||||
@@ -81,7 +85,7 @@ class chat {
|
||||
senderUuid: packet.senderUuid,
|
||||
players: bot.players,
|
||||
getMessageAsPrismarine: bot.getMessageAsPrismarine,
|
||||
chatType: "player",
|
||||
chatType: "minecraft:player_chat"
|
||||
});
|
||||
});
|
||||
|
||||
@@ -106,11 +110,11 @@ class chat {
|
||||
});
|
||||
bot.emit("system_chat", message);
|
||||
|
||||
if (bot.options.mode !== "savageFriends") return;
|
||||
//if (bot.options.mode !== "savageFriends") return;
|
||||
tryParsingMessage(message, {
|
||||
players: bot.players,
|
||||
getMessageAsPrismarine: bot.getMessageAsPrismarine,
|
||||
chatType: "system",
|
||||
chatType: "minecraft:system_chat",
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
const nbt = require("prismarine-nbt");
|
||||
const sleep = require("../util/sleep");
|
||||
const convertNbtComponentToJson = require("../util/nbt_parser");
|
||||
const fixansi = require("../util/ansi");
|
||||
|
||||
class command_core {
|
||||
constructor(context) {
|
||||
@@ -9,6 +8,7 @@ class command_core {
|
||||
const config = context.config;
|
||||
const options = context.options;
|
||||
const Item = require("prismarine-item")(bot.options.version);
|
||||
|
||||
let command;
|
||||
|
||||
bot.core = {
|
||||
@@ -95,6 +95,8 @@ class command_core {
|
||||
z: Math.floor(pos.z),
|
||||
};
|
||||
|
||||
bot.core.commandBlocks = [];
|
||||
|
||||
if (bot.options.itemRefill && bot.options.mode !== "savageFriends") {
|
||||
bot.core.itemRefill();
|
||||
} else {
|
||||
@@ -240,31 +242,6 @@ class command_core {
|
||||
bot.on("end", () => {
|
||||
if (timer) clearInterval(timer);
|
||||
});
|
||||
|
||||
/* bot.on("packet.multi_block_change", (data) => {
|
||||
try {
|
||||
if (bot.options.mode !== "kaboom") return;
|
||||
|
||||
let broken = true;
|
||||
|
||||
if (
|
||||
data.chunkCoordinates.x === Math.floor(bot.core.position.x / 16) &&
|
||||
data.chunkCoordinates.y === Math.floor(bot.core.position.y / 16) &&
|
||||
data.chunkCoordinates.z === Math.floor(bot.core.position.z / 16)
|
||||
) {
|
||||
for (const state of data.records) {
|
||||
if (state >= 7906 && state >= 7917) broken = false;
|
||||
if (state >= 12527 && state >= 12538) broken = false;
|
||||
if (state >= 12515 && state >= 12526) broken = false;
|
||||
else broken = true;
|
||||
}
|
||||
|
||||
if (broken === true) bot.core.move(bot.position);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
});*/
|
||||
}
|
||||
}
|
||||
module.exports = command_core;
|
||||
|
||||
@@ -8,8 +8,8 @@ class command_handler {
|
||||
const options = context.options;
|
||||
|
||||
bot.on("parsed_message", (data) => {
|
||||
try {
|
||||
if (data.type !== "minecraft:chat") return;
|
||||
try {
|
||||
if (data.type !== "minecraft:chat" && data.type !== "extras:command_spy") return;
|
||||
const prefixes = config.prefixes;
|
||||
prefixes.map((prefix) => {
|
||||
const plainMessage = bot
|
||||
@@ -18,12 +18,13 @@ class command_handler {
|
||||
|
||||
if (!plainMessage?.startsWith(prefix)) return;
|
||||
const command = plainMessage.substring(prefix.length);
|
||||
|
||||
|
||||
const source = new CommandSource(
|
||||
data.sender,
|
||||
{ discord: false, console: false },
|
||||
data.chatType,
|
||||
null,
|
||||
data.trustLevel,
|
||||
data.validateBypass
|
||||
);
|
||||
|
||||
source.sendFeedback = (message) => {
|
||||
@@ -33,13 +34,6 @@ class command_handler {
|
||||
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";
|
||||
else source.player.trustLevel = "public"
|
||||
ratelimit++;
|
||||
setTimeout(() => {
|
||||
ratelimit--;
|
||||
@@ -55,40 +49,6 @@ class command_handler {
|
||||
console.log(e.stack);
|
||||
}
|
||||
});
|
||||
|
||||
bot.on('packet.custom_payload', (packet) => {
|
||||
if (packet.channel === "extras:message") {
|
||||
try {
|
||||
const decoded = packet.data.toString('ascii');
|
||||
const prefixes = config.prefixes
|
||||
const string = decoded.substring(20)
|
||||
const channel = packet.data.toString('ascii').split('\x05')[0]
|
||||
if (channel === config.skibot.channel) return
|
||||
const parsed = JSON.parse(string)
|
||||
const args = parsed.message
|
||||
const uuid = parsed.player
|
||||
prefixes.map((prefix) => {
|
||||
if (!args?.startsWith(prefix)) return;
|
||||
const command = args.substring(prefix.length)
|
||||
const sender = bot.players.find((e) => e.uuid === uuid)
|
||||
|
||||
const source = new CommandSource(
|
||||
sender,
|
||||
{ discord: false, console: false },
|
||||
'extras:message',
|
||||
null,
|
||||
)
|
||||
console.log(source.player.profile.name)
|
||||
source.sendFeedback = (message) => {
|
||||
bot.tellraw(`@a[name="${source.player.profile.name}"]`, message)
|
||||
}
|
||||
bot.commandManager.executeString(source, command)
|
||||
})
|
||||
} catch (e) {
|
||||
bot.console.error(e.toString())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
module.exports = command_handler;
|
||||
+48
-194
@@ -4,6 +4,7 @@ const CommandError = require("../command_util/command_error.js");
|
||||
const CommandSource = require("../command_util/command_source");
|
||||
const fixansi = require("../util/ansi");
|
||||
const sleep = require("../util/sleep.js");
|
||||
const trustLevels = require('../command_util/command_trust_level.js')
|
||||
|
||||
function unknownCommand(commandName, bot) {
|
||||
return {
|
||||
@@ -30,210 +31,62 @@ class command_manager {
|
||||
commandlist: [],
|
||||
execute(source, commandName, args) {
|
||||
const command = this.getCommand(commandName.toLowerCase());
|
||||
const authed = bot.auth.list;
|
||||
try {
|
||||
const authFind = bot.auth.list.find((e) => e.player === source.player.uuid)
|
||||
if (!command) {
|
||||
if (source?.sources?.console)
|
||||
bot.console.command(
|
||||
unknownCommand(commandName, bot),
|
||||
);
|
||||
else
|
||||
source.sendFeedback(
|
||||
unknownCommand(commandName, bot),
|
||||
);
|
||||
source.sendFeedback(
|
||||
unknownCommand(commandName, bot),
|
||||
);
|
||||
}
|
||||
|
||||
const event = bot.discord.message;
|
||||
const roles = event?.member?.roles?.cache;
|
||||
if (authFind) {
|
||||
source.player.validateBypass = true
|
||||
if (authFind.trustLevel === "trusted") source.player.trustLevel = 1;
|
||||
else if (authFind.trustLevel === "admin") source.player.trustLevel = 2;
|
||||
else if (authFind.trustLevel === "owner") source.player.trustLevel = 3;
|
||||
}
|
||||
|
||||
switch (command?.data?.trustLevel) {
|
||||
case 0:
|
||||
// do nothing since trust level 0 is public
|
||||
break;
|
||||
case 1:
|
||||
if (source?.sources?.discord) {
|
||||
const hasRole = roles?.some(
|
||||
(role) =>
|
||||
role.name === `${config.discord.roles.trusted}` ||
|
||||
role.name === `${config.discord.roles.admin}` ||
|
||||
role.name === `${config.discord.roles.fullAccess}` ||
|
||||
role.name === `${config.discord.roles.owner}`,
|
||||
);
|
||||
if (!hasRole)
|
||||
throw new CommandError({
|
||||
text: "You done have the trusted, admin, or owner roles!",
|
||||
color: "red"
|
||||
});
|
||||
} else if (!source?.sources.console) {
|
||||
if (source.ChatType === "extras:message")
|
||||
throw new CommandError({
|
||||
text: "Trusted Commands can not be ran from extras:message",
|
||||
color: "red"
|
||||
})
|
||||
if (
|
||||
args.length === 0 &&
|
||||
authed.find((e) => e?.player === source.player.uuid)
|
||||
?.trustLevel !== "trusted" &&
|
||||
authed.find((e) => e?.player === source.player.uuid)
|
||||
?.trustLevel !== "admin" &&
|
||||
authed.find((e) => e?.player === source.player.uuid)
|
||||
?.trustLevel !== "owner"
|
||||
)
|
||||
throw new CommandError({
|
||||
text: "Please provide a trusted, admin, or owner hash",
|
||||
color: "red"
|
||||
});
|
||||
if (
|
||||
args[0] !== bot.validation.trusted &&
|
||||
args[0] !== bot.validation.admin &&
|
||||
args[0] !== bot.validation.owner &&
|
||||
authed.find((e) => e.player === source.player.uuid)
|
||||
?.trustLevel !== "trusted" &&
|
||||
authed.find((e) => e.player === source.player.uuid)
|
||||
?.trustLevel !== "admin" &&
|
||||
authed.find((e) => e.player === source.player.uuid)
|
||||
?.trustLevel !== "owner"
|
||||
)
|
||||
throw new CommandError({
|
||||
text: "Invalid Hash",
|
||||
color: "red"
|
||||
});
|
||||
if (source.player.authed) {
|
||||
args = args;
|
||||
} else {
|
||||
args = args.slice(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (source?.sources?.discord) {
|
||||
const hasRole = roles?.some(
|
||||
(role) =>
|
||||
role.name === `${config.discord.roles.admin}` ||
|
||||
role.name === `${config.discord.roles.fullAccess}` ||
|
||||
role.name === `${config.discord.roles.owner}`,
|
||||
);
|
||||
if (!hasRole)
|
||||
throw new CommandError({
|
||||
text: "You dont have the admin, or owner roles!",
|
||||
color: "red"
|
||||
});
|
||||
} else if (!source?.sources?.console) {
|
||||
if (source.ChatType === "extras:message")
|
||||
throw new CommandError({
|
||||
text: "Admin Commands can not be ran from extras:message",
|
||||
color: "red"
|
||||
})
|
||||
if (
|
||||
args.length === 0 &&
|
||||
authed.find((e) => e?.player === source.player.uuid)
|
||||
?.trustLevel !== "admin" &&
|
||||
authed.find((e) => e?.player === source.player.uuid)
|
||||
?.trustLevel !== "owner"
|
||||
)
|
||||
throw new CommandError({
|
||||
text: "Please provide a hash",
|
||||
color: "red"
|
||||
});
|
||||
if (
|
||||
args[0] !== bot.validation.admin &&
|
||||
args[0] !== bot.validation.owner &&
|
||||
authed.find((e) => e?.player === source.player.uuid)
|
||||
?.trustLevel !== "admin" &&
|
||||
authed.find((e) => e?.player === source.player.uuid)
|
||||
?.trustLevel !== "owner"
|
||||
)
|
||||
throw new CommandError({
|
||||
text: "Invalid hash",
|
||||
color: "red"
|
||||
});
|
||||
|
||||
if (source.player.authed) {
|
||||
args = args;
|
||||
} else {
|
||||
args = args.slice(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if (source?.sources?.discord) {
|
||||
const hasRole = roles?.some(
|
||||
(role) =>
|
||||
role.name === `${config.discord.roles.owner}` ||
|
||||
role.name === `${config.discord.roles.fullAccess}`,
|
||||
);
|
||||
if (!hasRole)
|
||||
throw new CommandError({
|
||||
text: "You dont have the owner role!",
|
||||
color: "red"
|
||||
});
|
||||
} else if (!source?.sources?.console) {
|
||||
if (source.ChatType === "extras:message")
|
||||
throw new CommandError({
|
||||
text: "Owner Commands can not be ran from extras:message",
|
||||
color: "red"
|
||||
})
|
||||
|
||||
if (
|
||||
args.length === 0 &&
|
||||
bot.validation.owner &&
|
||||
authed.find((e) => e?.player === source.player.uuid)
|
||||
?.trustLevel !== "owner"
|
||||
)
|
||||
throw new CommandError({
|
||||
text: "Please provide a hash",
|
||||
color: "red"
|
||||
});
|
||||
|
||||
if (
|
||||
args[0] !== bot.validation.owner &&
|
||||
authed.find((e) => e?.player === source.player.uuid)
|
||||
?.trustLevel !== "owner"
|
||||
)
|
||||
throw new CommandError({
|
||||
text: "Invalid hash",
|
||||
color: "red"
|
||||
});
|
||||
|
||||
if (source.player.authed) {
|
||||
args = args;
|
||||
} else {
|
||||
args = args.slice(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (!source?.sources?.console) {
|
||||
if (command.data.trustLevel !== 0) {
|
||||
if (!source.player.validateBypass && !source.sources.console && !source.sources.discord) {
|
||||
if (args[0] === bot.validation.trusted)
|
||||
source.player.trustLevel = 1
|
||||
else if (args[0] === bot.validation.admin)
|
||||
source.player.trustLevel = 2
|
||||
else if (args[0] === bot.validation.owner)
|
||||
source.player.trustLevel = 3
|
||||
args = args.slice(1)
|
||||
if (source.player.trustLevel < command?.data?.trustLevel && !source.sources.console) {
|
||||
throw new CommandError({
|
||||
text: "This Command can only be ran via console",
|
||||
text: "Invalid Hash",
|
||||
color: "red"
|
||||
});
|
||||
})
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
throw new CommandError({
|
||||
text: "This Command has been disabled!",
|
||||
color: "red"
|
||||
});
|
||||
break;
|
||||
} if (source.sources.discord) {
|
||||
const event = bot.discord.message;
|
||||
const roles = event?.member?.roles?.cache;
|
||||
const hashRole = roles?.some((role) => {
|
||||
if (role.name === `${config.discord.roles.trusted}`) source.player.trustLevel = 1;
|
||||
else if (role.name === `${config.discord.roles.admin}`) source.player.trustLevel = 2;
|
||||
else if (role.name === `${config.discord.roles.owner}`) source.player.trustLevel = 3;
|
||||
})
|
||||
|
||||
if (source.player.trustLevel < command?.data?.trustLevel)
|
||||
throw new CommandError({
|
||||
text: "Invalid Role",
|
||||
color: "red"
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/* if (source.sources.discord) {
|
||||
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`,
|
||||
);
|
||||
} 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}`,
|
||||
);
|
||||
}*/
|
||||
|
||||
// if (command.playerOnly === true && source.ChatType.find((e) => e)) return;
|
||||
|
||||
if (
|
||||
command?.data.playerChat
|
||||
&&
|
||||
source.ChatType !== "minecraft:player_chat"
|
||||
&&
|
||||
!source.sources.console
|
||||
&&
|
||||
!source.sources.discord
|
||||
) return
|
||||
return command?.execute({
|
||||
bot,
|
||||
source,
|
||||
@@ -241,6 +94,7 @@ class command_manager {
|
||||
config,
|
||||
discordClient,
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
if (error instanceof CommandError) {
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ class command_spy {
|
||||
) bot.emit("parsed_message", {
|
||||
sender: bot.players.find((e) => e.profile.name === message.text),
|
||||
contents: { text: command },
|
||||
type: "minecraft:chat",
|
||||
chatType: "command_spy",
|
||||
type: "extras:command_spy",
|
||||
displayName: bot.players.find(
|
||||
(e) => e.profile.name === message.text,
|
||||
).displayName,
|
||||
|
||||
@@ -38,6 +38,10 @@ class Console {
|
||||
});
|
||||
});
|
||||
},
|
||||
/*
|
||||
data.trustLevel,
|
||||
data.validateBypass
|
||||
*/
|
||||
source: new CommandSource(
|
||||
{
|
||||
profile: {
|
||||
@@ -46,6 +50,11 @@ class Console {
|
||||
uuid: bot._client.uuid,
|
||||
},
|
||||
{ console: true, discord: false },
|
||||
"minecraft:chat",
|
||||
{
|
||||
trustLevel: 4,
|
||||
validateBypass: true
|
||||
}
|
||||
),
|
||||
|
||||
refreshLine(...args) {
|
||||
|
||||
Reference in New Issue
Block a user