@ezzi/base 1.0.0 → 1.0.1
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.
- package/dist/bootstrap.js +2 -2
- package/dist/creators/commands/command.d.ts +1 -1
- package/dist/error.d.ts +5 -1
- package/dist/error.js +27 -28
- package/package.json +1 -1
package/dist/bootstrap.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/bootstrap.ts
|
|
2
2
|
import { EzziApp } from "./app.js";
|
|
3
3
|
import { createClient } from "./client.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Errors } from "./error.js";
|
|
5
5
|
import { loadModules } from "./modules.js";
|
|
6
6
|
async function bootstrap(options) {
|
|
7
7
|
const token = options.token ?? options.env?.BOT_TOKEN ?? process.env?.BOT_TOKEN;
|
|
8
8
|
if (!token)
|
|
9
|
-
throw
|
|
9
|
+
throw Errors.tokenNotProvided();
|
|
10
10
|
const app = EzziApp.getInstance();
|
|
11
11
|
if (options.errorHandler) {
|
|
12
12
|
app.setErrorHandler(options.errorHandler);
|
|
@@ -130,7 +130,7 @@ declare class GroupCommandModule<Type, Contexts extends readonly InteractionCont
|
|
|
130
130
|
constructor(command: Command<Type, Contexts, Return>, data: SubCommandGroupModuleData<Contexts, Return, ModuleReturn>);
|
|
131
131
|
subcommand(data: SubCommandModuleData<Contexts, ModuleReturn>): this;
|
|
132
132
|
}
|
|
133
|
-
export declare class Command<Type, Contexts extends readonly InteractionContextType[]
|
|
133
|
+
export declare class Command<Type, Contexts extends readonly InteractionContextType[], Return = unknown> {
|
|
134
134
|
readonly modules: CommandModule[];
|
|
135
135
|
readonly data: AppCommandData<Type, Contexts, Return>;
|
|
136
136
|
constructor(data: AppCommandData<Type, Contexts, Return>);
|
package/dist/error.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Client } from "discord.js";
|
|
2
2
|
export declare class EzziError extends Error {
|
|
3
|
-
|
|
3
|
+
readonly code: string;
|
|
4
|
+
constructor(code: string, message: string);
|
|
5
|
+
}
|
|
6
|
+
export declare class Errors {
|
|
7
|
+
static tokenNotProvided(): EzziError;
|
|
4
8
|
}
|
|
5
9
|
export declare class RunBlockError {
|
|
6
10
|
}
|
package/dist/error.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// src/error.ts
|
|
2
2
|
import {
|
|
3
3
|
codeBlock,
|
|
4
|
-
|
|
5
|
-
REST,
|
|
6
|
-
Routes,
|
|
4
|
+
WebhookClient,
|
|
7
5
|
TextDisplayBuilder,
|
|
8
6
|
time
|
|
9
7
|
} from "discord.js";
|
|
@@ -11,8 +9,16 @@ import console from "node:console";
|
|
|
11
9
|
import { styleText } from "node:util";
|
|
12
10
|
|
|
13
11
|
class EzziError extends Error {
|
|
14
|
-
|
|
12
|
+
code;
|
|
13
|
+
constructor(code, message) {
|
|
15
14
|
super(message);
|
|
15
|
+
this.code = code;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class Errors {
|
|
20
|
+
static tokenNotProvided() {
|
|
21
|
+
return new EzziError("TOKEN_NOT_PROVIDED", "The application token was not provided!");
|
|
16
22
|
}
|
|
17
23
|
}
|
|
18
24
|
|
|
@@ -38,32 +44,24 @@ async function baseErrorHandler(error, client) {
|
|
|
38
44
|
const url = process.env.WEBHOOK_LOGS_URL;
|
|
39
45
|
if (!url)
|
|
40
46
|
return;
|
|
41
|
-
const
|
|
42
|
-
if (!data)
|
|
43
|
-
return;
|
|
44
|
-
const rest = new REST;
|
|
45
|
-
if (process.env.BOT_TOKEN)
|
|
46
|
-
rest.setToken(process.env.BOT_TOKEN);
|
|
47
|
+
const username = client?.user?.username;
|
|
47
48
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
codeBlock("ansi", text.join(`
|
|
49
|
+
new WebhookClient({ url }).send({
|
|
50
|
+
flags: "IsComponentsV2",
|
|
51
|
+
withComponents: true,
|
|
52
|
+
components: [
|
|
53
|
+
new TextDisplayBuilder({
|
|
54
|
+
content: [
|
|
55
|
+
codeBlock("ansi", text.join(`
|
|
56
56
|
`)),
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
time(new Date, "R")
|
|
58
|
+
].join(`
|
|
59
59
|
`)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
}).catch(console.error);
|
|
60
|
+
})
|
|
61
|
+
],
|
|
62
|
+
avatarURL: client?.user?.displayAvatarURL({ size: 512 }),
|
|
63
|
+
username: username ? `${username} logs` : "Logs"
|
|
64
|
+
});
|
|
67
65
|
} catch {
|
|
68
66
|
console.log();
|
|
69
67
|
console.error("ENV VAR → %s Invalid webhook url", styleText(["bold", "underline"], "WEBHOOK_LOGS_URL"));
|
|
@@ -74,5 +72,6 @@ async function baseErrorHandler(error, client) {
|
|
|
74
72
|
export {
|
|
75
73
|
baseErrorHandler,
|
|
76
74
|
RunBlockError,
|
|
77
|
-
EzziError
|
|
75
|
+
EzziError,
|
|
76
|
+
Errors
|
|
78
77
|
};
|