@ezzi/base 1.0.0 → 1.0.2

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 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 { EzziError } from "./error.js";
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 new EzziError("The application token was not provided!");
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[] = readonly [typeof InteractionContextType.Guild], Return = unknown> {
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
- constructor(message: string);
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
- parseWebhookURL,
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
- constructor(message) {
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 data = parseWebhookURL(url);
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
- const username = client?.user?.username;
49
- rest.post(Routes.webhook(data.id, data.token), {
50
- body: {
51
- flags: ["IsComponentsV2"],
52
- components: [
53
- new TextDisplayBuilder({
54
- content: [
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
- time(new Date, "R")
58
- ].join(`
57
+ time(new Date, "R")
58
+ ].join(`
59
59
  `)
60
- })
61
- ],
62
- withComponents: true,
63
- avatarURL: client?.user?.displayAvatarURL({ size: 512 }),
64
- username: username ? `${username} logs` : "Logs"
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezzi/base",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Library with structures and functions for creating modern Discord applications.",
5
5
  "license": "MIT",
6
6
  "type": "module",