mirror of
https://code.chipmunk.land/Parker2991/NitoriBot/
synced 2026-11-29 13:45:38 -05:00
reverted back to how i handled errored before the custom errors and moved tellraw check to chat.js where the bot.tellraw function is called
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const CommandError = require('./errors/CommandError');
|
||||
const CommandError = require('./CommandError');
|
||||
const translations = require('../data/translations.json');
|
||||
|
||||
class CommandArguments {
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
class UnknownCommand extends Error {
|
||||
constructor(commandName) {
|
||||
super(commandName);
|
||||
this.name = "UnknownCommand";
|
||||
this._message = {
|
||||
translate: "%s%s%s %s",
|
||||
color: "red",
|
||||
with: [
|
||||
{ translate: "command.unknown.command", color: "red" },
|
||||
{ text: "\n"},
|
||||
{ text: `${commandName}`, color: "gray" },
|
||||
{ translate: "command.context.here", color: "red" }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = UnknownCommand;
|
||||
@@ -1,4 +1,4 @@
|
||||
const CommandError = require("../../commandUtil/errors/CommandError");
|
||||
const CommandError = require("../../commandUtil/CommandError");
|
||||
const CommandContext = require("../../commandUtil/CommandContext");
|
||||
const trustLevel = require("../../commandUtil/CommandTrustLevel");
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const CommandError = require("../../commandUtil/errors/CommandError");
|
||||
const CommandError = require("../../commandUtil/CommandError");
|
||||
const CommandContext = require("../../commandUtil/CommandContext");
|
||||
const trustLevel = require("../../commandUtil/CommandTrustLevel");
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const os = require("os");
|
||||
const CommandError = require("../../commandUtil/errors/CommandError");
|
||||
const CommandError = require("../../commandUtil/CommandError");
|
||||
const botInfo = require("../../data/info.json");
|
||||
const { execSync } = require("child_process");
|
||||
const CommandContext = require("../../commandUtil/CommandContext");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const CommandError = require("../../commandUtil/errors/CommandError");
|
||||
const CommandError = require("../../commandUtil/CommandError");
|
||||
const CommandContext = require("../../commandUtil/CommandContext");
|
||||
const trustLevel = require("../../commandUtil/CommandTrustLevel");
|
||||
|
||||
|
||||
@@ -111,19 +111,12 @@
|
||||
"fnfboyfriendbot.command_manager.validation.invalid_role": "Invalid Role",
|
||||
"fnfboyfriendbot.command_manager.trust_level.console_only": "This command can only be ran via console!",
|
||||
|
||||
"fnfboyfriendbot.error.assertion": "An Assertion Error has occurred, hover over this for more info",
|
||||
"fnfboyfriendbot.error.error": "An Error has occured, hover over this for more info",
|
||||
"fnfboyfriendbot.error.range": "An Range Error has occurred, hover over this for more info",
|
||||
"fnfboyfriendbot.error.reference": "An Reference Error has occured, hover over this for more info",
|
||||
"fnfboyfriendbot.error.syntax": "An Syntax Error has occurred, hover over this for more info",
|
||||
"fnfboyfriendbot.error.type_error": "An Type Error has occurred, hover over this for more info",
|
||||
|
||||
"fnfboyfriendbot.https_requesting.status.forbidden": "",
|
||||
"fnfboyfriendbot.https_requesting.": "",
|
||||
|
||||
"fnfboyfriendbot.json.parse_invalid": "invalid json component to parse",
|
||||
"fnfboyfriendbot.json.stringify.invalid": "invalid json component to stringify",
|
||||
"fnfboyfriendbot.json.stringify.too_long": "stringified json exceeds the max command block character limit",
|
||||
"fnfboyfriendbot.json.too_long": "Stringified JSON exceeds the max command block character limit",
|
||||
|
||||
"fnfboyfriendbot.reconnect.stop_logging": "stopped logging disconnect messages for now"
|
||||
}
|
||||
+12
-2
@@ -5,7 +5,6 @@ const creayun = require("../chatParsers/creayun");
|
||||
const chipmunkmod = require("../chatParsers/chipmunkmod");
|
||||
const vanilla = require('../chatParsers/vanilla/vanilla');
|
||||
const me = require('../chatParsers/vanilla/me')
|
||||
const { stringify } = require('../util/json');
|
||||
|
||||
function parseNbt (chatTypes, type, sender, target, message) {
|
||||
const chatType = chatTypes[type]
|
||||
@@ -183,7 +182,18 @@ class chat {
|
||||
};
|
||||
|
||||
bot.tellraw = (selector, message) => {
|
||||
bot.core.run(`minecraft:tellraw ${selector} ` + stringify(message));
|
||||
const command = "minecraft:tellraw";
|
||||
const commandLength = 32767 - selector.length;
|
||||
const messageLength = JSON.stringify(message).length
|
||||
const finalLength = commandLength - messageLength
|
||||
// here we check to see if the output surpasses the max command block character limit which is 32767
|
||||
if (messageLength > finalLength)
|
||||
bot.core.run(`${command} ${selector} ` + JSON.stringify({
|
||||
translate: "fnfboyfriendbot.json.too_long",
|
||||
fallback: bot.translations["fnfboyfriendbot.json.too_long"],
|
||||
color: "red"
|
||||
}))
|
||||
else bot.core.run(`${command} ${selector} ` + JSON.stringify(message));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ class commandHandler {
|
||||
const options = context.options;
|
||||
|
||||
bot.on("parsed_message", (data) => {
|
||||
//try {
|
||||
try {
|
||||
if (data.type !== "minecraft:chat" && data.type !== "extras:command_spy") return;
|
||||
const prefixes = config.prefixes;
|
||||
prefixes.map((prefix) => {
|
||||
@@ -30,7 +30,7 @@ class commandHandler {
|
||||
source.sendFeedback = (message) => {
|
||||
if (options.mode === "savageFriends") bot.tellraw(`@a`, [
|
||||
message
|
||||
])//[I;
|
||||
])
|
||||
else bot.tellraw(`@p[nbt={UUID:[I;${source.player.entityUuid}]}]`, message)
|
||||
}
|
||||
ratelimit++;
|
||||
@@ -44,9 +44,9 @@ class commandHandler {
|
||||
bot.commandManager.executeString(source, command);
|
||||
}
|
||||
});
|
||||
//} catch (e) {
|
||||
//console.log(e.stack);
|
||||
//}
|
||||
} catch (e) {
|
||||
console.log(e.stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const CommandError = require("../commandUtil/errors/CommandError");
|
||||
const UnknownCommand = require('../commandUtil/errors/UnknownCommand')
|
||||
const CommandError = require("../commandUtil/CommandError");
|
||||
const CommandSource = require("../commandUtil/CommandSource");
|
||||
const CommandArguments = require('../commandUtil/CommandArguments')
|
||||
const fixansi = require("../util/ansi");
|
||||
@@ -24,17 +23,18 @@ class commandManager {
|
||||
try {
|
||||
const authFind = bot.auth.list.find((e) => e.player === source.player.uuid)
|
||||
if (!command) {
|
||||
throw new UnknownCommand(commandName)
|
||||
throw new CommandError({
|
||||
translate: "%s%s%s %s",
|
||||
color: "red",
|
||||
with: [
|
||||
{ translate: "command.unknown.command", color: "red" },
|
||||
{ text: "\n" },
|
||||
{ text: `${commandName}`, color: "gray" },
|
||||
{ translate: "command.context.here", color: "red" }
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
process.emit('error', source, error)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', (error) => {
|
||||
process.emit('error', source, error)
|
||||
}) // unhandledRejection and uncaughtException emit here so the emitted error can use source.sendFeedback for async
|
||||
|
||||
if (authFind) {
|
||||
source.player.validateBypass = true
|
||||
if (authFind.trustLevel === "trusted") source.player.trustLevel = 1;
|
||||
@@ -100,7 +100,21 @@ class commandManager {
|
||||
discordClient,
|
||||
});
|
||||
} catch (error) {
|
||||
process.emit('error', source, error)
|
||||
if (error instanceof CommandError) {
|
||||
source.sendFeedback(error._message);
|
||||
} else {
|
||||
bot.console.error(error.stack)
|
||||
source.sendFeedback(
|
||||
{
|
||||
translate: "command.failed",
|
||||
color: "red",
|
||||
hoverEvent: {
|
||||
action: "show_text",
|
||||
contents: String(error.stack),
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
class errors {
|
||||
constructor (context) {
|
||||
const bot = context.bot;
|
||||
process.on('error', (source, error) => {
|
||||
const errorName = error.name;
|
||||
switch (errorName) {
|
||||
case "CommandError":
|
||||
source.sendFeedback(error._message)
|
||||
break;
|
||||
case "UnknownCommand":
|
||||
source.sendFeedback(error._message)
|
||||
break
|
||||
case "Error":
|
||||
source.sendFeedback({
|
||||
translate: "fnfboyfriendbot.error.error",
|
||||
fallback: bot.translations["fnfboyfriendbot.error.error"],
|
||||
color: "red",
|
||||
hover_event: {
|
||||
action: "show_text",
|
||||
value: String(error.stack)
|
||||
}
|
||||
})
|
||||
break;
|
||||
case "TypeError":
|
||||
source.sendFeedback({
|
||||
translate: "fnfboyfriendbot.error.type_error",
|
||||
fallback: bot.translations["fnfboyfriendbot.error.type_error"],
|
||||
color: "red",
|
||||
hover_event: {
|
||||
action: "show_text",
|
||||
value: String(error.stack)
|
||||
}
|
||||
})
|
||||
break;
|
||||
case "RangeError":
|
||||
source.sendFeedback({
|
||||
translate: "fnfboyfriendbot.error.range",
|
||||
fallback: bot.translations["fnfboyfriendbot.error.range"],
|
||||
color: "red",
|
||||
hover_event: {
|
||||
action: "show_text",
|
||||
value: String(error.stack)
|
||||
}
|
||||
})
|
||||
break;
|
||||
case "ReferenceError":
|
||||
source.sendFeedback({
|
||||
translate: "fnfboyfriendbot.error.reference",
|
||||
fallback: bot.translations["fnfboyfriendbot.error.reference"],
|
||||
color: "red",
|
||||
hover_event: {
|
||||
action: "show_text",
|
||||
value: String(error.stack)
|
||||
}
|
||||
})
|
||||
break;
|
||||
case "AssertionError":
|
||||
source.sendFeedback({
|
||||
translate: "fnfboyfriendbot.error.assertion",
|
||||
fallback: bot.translations["fnfboyfriendbot.error.assertion"],
|
||||
color: "red",
|
||||
hover_event: {
|
||||
action: "show_text",
|
||||
value: String(error.stack)
|
||||
}
|
||||
})
|
||||
break;
|
||||
case "SyntaxError":
|
||||
source.sendFeedback({
|
||||
translate: "fnfboyfriendbot.error.syntax",
|
||||
fallback: bot.translations["fnfboyfriendbot.error.syntax"],
|
||||
color: "red",
|
||||
hover_event: {
|
||||
action: "show_text",
|
||||
value: String(error.stack)
|
||||
}
|
||||
})
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = errors;
|
||||
@@ -1,34 +0,0 @@
|
||||
const translations = require('../data/translations.json');
|
||||
|
||||
class json {
|
||||
static parse (json) {
|
||||
try {
|
||||
return JSON.parse(json)
|
||||
} catch {
|
||||
return {
|
||||
translate: "fnfboyfriendbot.json.parse_invalid",
|
||||
fallback: translations["fnfboyfriendbot.json.parse_invalid"],
|
||||
color: "red"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static stringify (json) {
|
||||
try {
|
||||
const stringify = JSON.stringify(json);
|
||||
if (stringify.length > 32681) return JSON.stringify({
|
||||
translate: "fnfboyfriendbot.json.stringify.too_long",
|
||||
fallback: translations["fnfboyfriendbot.json.stringify.too_long"],
|
||||
color: "red",
|
||||
})
|
||||
else return stringify;
|
||||
} catch {
|
||||
return JSON.stringify({
|
||||
translate: "fnfboyfriendbot.json.stringify.invalid",
|
||||
fallback: translations["fnfboyfriendbot.json.stringify.invalid"],
|
||||
color: "red"
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = json
|
||||
Reference in New Issue
Block a user