zumito-framework 1.7.2 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,11 +15,19 @@ export class SlashCommandRefresher {
|
|
|
15
15
|
const commands = Array.from(this.framework.commands.getAll().values())
|
|
16
16
|
.filter((command) => (command.type == CommandType.slash ||
|
|
17
17
|
command.type == CommandType.separated ||
|
|
18
|
-
command.type == CommandType.any)
|
|
19
|
-
|
|
18
|
+
command.type == CommandType.any) &&
|
|
19
|
+
!command.parent)
|
|
20
20
|
.map(command => this.mapCommand(command));
|
|
21
|
-
const
|
|
22
|
-
|
|
21
|
+
const uniqueCommands = [];
|
|
22
|
+
const names = new Set();
|
|
23
|
+
for (const cmd of commands) {
|
|
24
|
+
if (!names.has(cmd.name)) {
|
|
25
|
+
uniqueCommands.push(cmd);
|
|
26
|
+
names.add(cmd.name);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const data = await rest.put(Routes.applicationCommands(this.framework.settings.discordClientOptions.clientId), { body: uniqueCommands });
|
|
30
|
+
console.debug(`Successfully reloaded ${data.length} of ${uniqueCommands.length} application (/) commands.`);
|
|
23
31
|
}
|
|
24
32
|
mapCommand(command, commandBuilder) {
|
|
25
33
|
const slashCommand = commandBuilder || new SlashCommandBuilder();
|
|
@@ -77,9 +85,9 @@ export class SlashCommandRefresher {
|
|
|
77
85
|
Array.from(this.framework.commands.getAll().values())
|
|
78
86
|
.filter((subcommand) => (subcommand.type == CommandType.slash ||
|
|
79
87
|
subcommand.type == CommandType.separated ||
|
|
80
|
-
subcommand.type == CommandType.any)
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
subcommand.type == CommandType.any) &&
|
|
89
|
+
subcommand.parent &&
|
|
90
|
+
subcommand.parent == command.name)
|
|
83
91
|
.forEach(subcommand => {
|
|
84
92
|
if (!commandBuilder) {
|
|
85
93
|
slashCommand.addSubcommand((subcommandSlashBuilder) => {
|
|
@@ -24,6 +24,6 @@ export declare class ErrorHandler {
|
|
|
24
24
|
handleError(error: any, options: ErrorOptions): void;
|
|
25
25
|
handleCommandError(error: Error, options: CommandErrorOptions): void;
|
|
26
26
|
handleShapeShiftErrors(error: any): void;
|
|
27
|
-
printErrorStack(error:
|
|
27
|
+
printErrorStack(error: any): void;
|
|
28
28
|
}
|
|
29
29
|
export {};
|
|
@@ -11,26 +11,26 @@ export class ErrorHandler {
|
|
|
11
11
|
if (options?.type == ErrorType.CommandInstance || options?.type == ErrorType.CommandLoad || options?.type == ErrorType.CommandRun) {
|
|
12
12
|
this.handleCommandError(error, options);
|
|
13
13
|
}
|
|
14
|
-
else if (error
|
|
14
|
+
else if (error?.constructor?.name == 'CombinedError') {
|
|
15
15
|
this.handleShapeShiftErrors(error);
|
|
16
16
|
}
|
|
17
|
-
else if (error
|
|
17
|
+
else if (error?.constructor?.name == "ExpectedValidationError") {
|
|
18
18
|
console.error(`Validation error: Expected ${error.expected}, but received ${error.given}.`);
|
|
19
19
|
console.line('');
|
|
20
20
|
}
|
|
21
|
-
else if (error
|
|
21
|
+
else if (error?.constructor?.name == "ValidationError") {
|
|
22
22
|
console.error(`Validation error: ${error.validator} received invalid input: ${error.given}`);
|
|
23
23
|
console.line('');
|
|
24
24
|
}
|
|
25
25
|
else if (options?.type == ErrorType.Api) {
|
|
26
26
|
console.group(`[❌] Error in API endpoint ${options.endpoint} (${options.method})`);
|
|
27
27
|
console.line(chalk.red('Error:'));
|
|
28
|
-
console.line(error
|
|
28
|
+
console.line(error?.toString?.() || 'Unknown error');
|
|
29
29
|
console.line('');
|
|
30
30
|
console.groupEnd();
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
|
-
console.error(error
|
|
33
|
+
console.error(error?.toString?.() || 'Unknown error');
|
|
34
34
|
console.line('');
|
|
35
35
|
}
|
|
36
36
|
this.printErrorStack(error);
|
|
@@ -49,19 +49,19 @@ export class ErrorHandler {
|
|
|
49
49
|
console.group(`[❌] Error running command ${options.command.name}`);
|
|
50
50
|
break;
|
|
51
51
|
}
|
|
52
|
-
if (error
|
|
52
|
+
if (error?.constructor?.name == 'CombinedError') {
|
|
53
53
|
console.groupEnd();
|
|
54
54
|
this.handleShapeShiftErrors(error);
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
57
|
console.line(chalk.red('Error:'));
|
|
58
|
-
console.line(error
|
|
58
|
+
console.line(error?.toString?.() || 'Unknown error');
|
|
59
59
|
console.line('');
|
|
60
60
|
console.groupEnd();
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
handleShapeShiftErrors(error) {
|
|
64
|
-
if (error
|
|
64
|
+
if (error?.constructor?.name == 'CombinedError') {
|
|
65
65
|
error.errors.forEach(err => {
|
|
66
66
|
this.handleError(err, {
|
|
67
67
|
type: ErrorType.Other
|
|
@@ -70,7 +70,15 @@ export class ErrorHandler {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
printErrorStack(error) {
|
|
73
|
-
|
|
73
|
+
if (!error || !(error.stack || error.stacktrace))
|
|
74
|
+
return;
|
|
75
|
+
let stackParsedError;
|
|
76
|
+
try {
|
|
77
|
+
stackParsedError = ErrorStackParser.parse(error);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
74
82
|
let functionColor = 'blue';
|
|
75
83
|
const lines = [];
|
|
76
84
|
let codeFragment;
|
|
@@ -126,9 +126,10 @@ export class CommandManager {
|
|
|
126
126
|
async refreshSlashCommands() {
|
|
127
127
|
const rest = new REST({ version: '10' }).setToken(this.framework.settings.discordClientOptions.token);
|
|
128
128
|
const commands = Array.from(this.commands.values())
|
|
129
|
-
.filter((command) => command.type == CommandType.slash ||
|
|
129
|
+
.filter((command) => (command.type == CommandType.slash ||
|
|
130
130
|
command.type == CommandType.separated ||
|
|
131
|
-
command.type == CommandType.any)
|
|
131
|
+
command.type == CommandType.any) &&
|
|
132
|
+
!command.parent)
|
|
132
133
|
.map((command) => {
|
|
133
134
|
const slashCommand = new SlashCommandBuilder()
|
|
134
135
|
.setName(command.name)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zumito-framework",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
4
4
|
"description": "Discord.js bot framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"source-fragment": "^1.1.0",
|
|
38
38
|
"tingodb": "^0.6.1",
|
|
39
39
|
"tseep": "^1.2.2",
|
|
40
|
-
"zumito-db": "^1.0.
|
|
40
|
+
"zumito-db": "^1.0.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^18.19.44",
|