@constatic/base 0.1.0 → 0.1.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 CHANGED
@@ -1,12 +1,12 @@
1
1
  // src/bootstrap.ts
2
2
  import { ConstaticApp } from "./app.js";
3
3
  import { createClient } from "./client.js";
4
- import { ConstaticError } 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 ConstaticError("The application token was not provided!");
9
+ throw Errors.tokenNotProvided();
10
10
  const app = ConstaticApp.getInstance();
11
11
  if (options.errorHandler) {
12
12
  app.setErrorHandler(options.errorHandler);
package/dist/error.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import { Client } from "discord.js";
2
2
  export declare class ConstaticError 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(): ConstaticError;
4
8
  }
5
9
  export declare class RunBlockError {
6
10
  }
package/dist/error.js CHANGED
@@ -1,11 +1,19 @@
1
1
  // src/error.ts
2
- import { codeBlock, TextDisplayBuilder, time, parseWebhookURL, REST, Routes } from "discord.js";
2
+ import { codeBlock, TextDisplayBuilder, time, WebhookClient } from "discord.js";
3
3
  import console from "node:console";
4
4
  import { styleText } from "node:util";
5
5
 
6
6
  class ConstaticError extends Error {
7
- constructor(message) {
7
+ code;
8
+ constructor(code, message) {
8
9
  super(message);
10
+ this.code = code;
11
+ }
12
+ }
13
+
14
+ class Errors {
15
+ static tokenNotProvided() {
16
+ return new ConstaticError("TOKEN_NOT_PROVIDED", "The application token was not provided!");
9
17
  }
10
18
  }
11
19
 
@@ -31,32 +39,24 @@ async function baseErrorHandler(error, client) {
31
39
  const url = process.env.WEBHOOK_LOGS_URL;
32
40
  if (!url)
33
41
  return;
34
- const data = parseWebhookURL(url);
35
- if (!data)
36
- return;
37
- const rest = new REST;
38
- if (process.env.BOT_TOKEN)
39
- rest.setToken(process.env.BOT_TOKEN);
42
+ const username = client?.user?.username;
40
43
  try {
41
- const username = client?.user?.username;
42
- rest.post(Routes.webhook(data.id, data.token), {
43
- body: {
44
- flags: ["IsComponentsV2"],
45
- components: [
46
- new TextDisplayBuilder({
47
- content: [
48
- codeBlock("ansi", text.join(`
44
+ new WebhookClient({ url }).send({
45
+ flags: "IsComponentsV2",
46
+ withComponents: true,
47
+ components: [
48
+ new TextDisplayBuilder({
49
+ content: [
50
+ codeBlock("ansi", text.join(`
49
51
  `)),
50
- time(new Date, "R")
51
- ].join(`
52
+ time(new Date, "R")
53
+ ].join(`
52
54
  `)
53
- })
54
- ],
55
- withComponents: true,
56
- avatarURL: client?.user?.displayAvatarURL({ size: 512 }),
57
- username: username ? `${username} logs` : "Logs"
58
- }
59
- }).catch(console.error);
55
+ })
56
+ ],
57
+ avatarURL: client?.user?.displayAvatarURL({ size: 512 }),
58
+ username: username ? `${username} logs` : "Logs"
59
+ });
60
60
  } catch {
61
61
  console.log();
62
62
  console.error("ENV VAR → %s Invalid webhook url", styleText(["bold", "underline"], "WEBHOOK_LOGS_URL"));
@@ -67,5 +67,6 @@ async function baseErrorHandler(error, client) {
67
67
  export {
68
68
  baseErrorHandler,
69
69
  RunBlockError,
70
+ Errors,
70
71
  ConstaticError
71
72
  };
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var version = "0.0.10";
2
+ var version = "0.1.1";
3
3
  export {
4
4
  version
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constatic/base",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Library with structures and functions for creating modern Discord applications.",
5
5
  "license": "MIT",
6
6
  "type": "module",