zumito-framework 1.9.0 → 1.11.0

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.
@@ -3,5 +3,7 @@ export declare enum ErrorType {
3
3
  CommandLoad = 2,
4
4
  CommandRun = 3,
5
5
  Api = 4,
6
- Other = 5
6
+ Other = 5,
7
+ ModuleLoad = 6,
8
+ RouteLoad = 7
7
9
  }
@@ -5,4 +5,6 @@ export var ErrorType;
5
5
  ErrorType[ErrorType["CommandRun"] = 3] = "CommandRun";
6
6
  ErrorType[ErrorType["Api"] = 4] = "Api";
7
7
  ErrorType[ErrorType["Other"] = 5] = "Other";
8
+ ErrorType[ErrorType["ModuleLoad"] = 6] = "ModuleLoad";
9
+ ErrorType[ErrorType["RouteLoad"] = 7] = "RouteLoad";
8
10
  })(ErrorType || (ErrorType = {}));
@@ -3,6 +3,7 @@ import { Command } from './commands/Command.js';
3
3
  import { FrameworkEvent } from './FrameworkEvent.js';
4
4
  import { CommandManager } from '../services/managers/CommandManager.js';
5
5
  import { ModuleParameters } from './parameters/ModuleParameters.js';
6
+ import { ErrorHandler } from '../services/handlers/ErrorHandler.js';
6
7
  export type ModuleRequeriments = {
7
8
  modules: Array<string>;
8
9
  services: Array<string>;
@@ -16,6 +17,7 @@ export declare abstract class Module {
16
17
  protected events: Map<string, FrameworkEvent>;
17
18
  static requeriments: ModuleRequeriments;
18
19
  protected commandManager: CommandManager;
20
+ protected errorHandler: ErrorHandler;
19
21
  constructor(path: any, parameters?: ModuleParameters);
20
22
  initialize(): Promise<void>;
21
23
  registerCommands(): Promise<void>;
@@ -4,6 +4,8 @@ import path from 'path';
4
4
  import { ButtonInteraction, CommandInteraction, ModalSubmitInteraction, StringSelectMenuInteraction, } from 'discord.js';
5
5
  import { CommandManager } from '../services/managers/CommandManager.js';
6
6
  import { ServiceContainer } from '../services/ServiceContainer.js';
7
+ import { ErrorHandler } from '../services/handlers/ErrorHandler.js';
8
+ import { ErrorType } from './ErrorType.js';
7
9
  export class Module {
8
10
  path;
9
11
  parameters;
@@ -12,11 +14,13 @@ export class Module {
12
14
  events = new Map();
13
15
  static requeriments;
14
16
  commandManager;
17
+ errorHandler;
15
18
  constructor(path, parameters) {
16
19
  this.path = path;
17
20
  this.parameters = parameters;
18
21
  this.framework = ServiceContainer.getService(ZumitoFramework);
19
22
  this.commands = new CommandManager(this.framework);
23
+ this.errorHandler = ServiceContainer.getService(ErrorHandler);
20
24
  }
21
25
  async initialize() {
22
26
  await this.registerCommands();
@@ -125,7 +129,10 @@ export class Module {
125
129
  continue;
126
130
  if (file.endsWith('.js') || file.endsWith('.ts')) {
127
131
  let route = await import('file://' + path.join(folderPath, file)).catch((e) => {
128
- console.error(`[🔄🔴 ] Error loading ${file.slice(0, -3)} route on module ${this.constructor.name}`);
132
+ this.errorHandler.handleError(e, {
133
+ type: ErrorType.RouteLoad,
134
+ moduleName: this.constructor.name,
135
+ });
129
136
  });
130
137
  route = Object.values(route)[0];
131
138
  route = new route();
@@ -1,7 +1,7 @@
1
1
  import { REST } from '@discordjs/rest';
2
2
  import { Routes } from 'discord-api-types/v9';
3
3
  import { CommandType } from "../definitions/commands/CommandType";
4
- import { SlashCommandBuilder } from "discord.js";
4
+ import { InteractionContextType, SlashCommandBuilder } from "discord.js";
5
5
  export class SlashCommandRefresher {
6
6
  framework;
7
7
  constructor(framework) {
@@ -34,6 +34,13 @@ export class SlashCommandRefresher {
34
34
  slashCommand
35
35
  .setName(command.name)
36
36
  .setDescription(this.framework.translations.get('command.' + command.name + '.description', 'en'));
37
+ if (slashCommand instanceof SlashCommandBuilder) {
38
+ slashCommand.setContexts([
39
+ InteractionContextType.BotDM,
40
+ InteractionContextType.Guild,
41
+ InteractionContextType.PrivateChannel,
42
+ ]);
43
+ }
37
44
  if (command.args) {
38
45
  command.args.forEach((arg) => {
39
46
  let method;
@@ -17,7 +17,17 @@ type ApiErrorOptions = BaseErrorOptions & {
17
17
  type OtherErrorOptions = BaseErrorOptions & {
18
18
  type: ErrorType.Other;
19
19
  };
20
- type ErrorOptions = CommandErrorOptions | ApiErrorOptions | OtherErrorOptions;
20
+ type ModuleLoadErrorOptions = BaseErrorOptions & {
21
+ type: ErrorType.ModuleLoad;
22
+ moduleName: string;
23
+ };
24
+ type RouteLoadErrorOptions = BaseErrorOptions & {
25
+ type: ErrorType.RouteLoad;
26
+ path?: string;
27
+ method?: string;
28
+ moduleName?: string;
29
+ };
30
+ type ErrorOptions = CommandErrorOptions | ApiErrorOptions | OtherErrorOptions | ModuleLoadErrorOptions | RouteLoadErrorOptions;
21
31
  export declare class ErrorHandler {
22
32
  framework: ZumitoFramework;
23
33
  constructor(framework: ZumitoFramework);
@@ -29,6 +29,29 @@ export class ErrorHandler {
29
29
  console.line('');
30
30
  console.groupEnd();
31
31
  }
32
+ else if (options?.type == ErrorType.ModuleLoad) {
33
+ console.group(`[❌] Error loading module ${options.moduleName}`);
34
+ console.line(chalk.red('Error:'));
35
+ console.line(error?.toString?.() || 'Unknown error');
36
+ console.line('');
37
+ console.groupEnd();
38
+ }
39
+ else if (options?.type == ErrorType.RouteLoad) {
40
+ console.group(`[❌] Error loading route ${options.path}`);
41
+ console.line(chalk.red('Error:'));
42
+ console.line(error?.toString?.() || 'Unknown error');
43
+ console.line('');
44
+ console.groupEnd();
45
+ if (options?.moduleName) {
46
+ console.line(chalk.blue('Module: ') + options.moduleName);
47
+ }
48
+ if (options?.method) {
49
+ console.line(chalk.blue('Method: ') + options.method);
50
+ }
51
+ if (options?.path) {
52
+ console.line(chalk.blue('Path: ') + options.path);
53
+ }
54
+ }
32
55
  else {
33
56
  console.error(error?.toString?.() || 'Unknown error');
34
57
  console.line('');
@@ -1,7 +1,10 @@
1
1
  import { ZumitoFramework } from "../../ZumitoFramework.js";
2
2
  import { Module } from "../../definitions/Module.js";
3
+ import { ErrorHandler } from "../handlers/ErrorHandler.js";
3
4
  import { ModuleParameters } from "../../definitions/parameters/ModuleParameters.js";
4
5
  export declare class ModuleManager {
6
+ protected framework: ZumitoFramework;
7
+ protected errorHandler: ErrorHandler;
5
8
  protected modules: Map<string, Module>;
6
9
  protected pendingInstancePool: Array<{
7
10
  module: any;
@@ -9,8 +12,7 @@ export declare class ModuleManager {
9
12
  name?: string;
10
13
  options?: ModuleParameters;
11
14
  }>;
12
- protected framework: ZumitoFramework;
13
- constructor(framework: ZumitoFramework);
15
+ constructor(framework?: ZumitoFramework, errorHandler?: ErrorHandler);
14
16
  set(name: string, module: Module): void;
15
17
  get(name: string): Module;
16
18
  getAll(): Map<string, Module>;
@@ -1,14 +1,19 @@
1
+ import { ZumitoFramework } from "../../ZumitoFramework.js";
1
2
  import { Module } from "../../definitions/Module.js";
2
3
  import fs from 'fs';
3
4
  import path from 'path';
5
+ import { ErrorHandler } from "../handlers/ErrorHandler.js";
4
6
  import { ServiceContainer } from "../ServiceContainer.js";
7
+ import { ErrorType } from "../../definitions/ErrorType.js";
5
8
  export class ModuleManager {
9
+ framework;
10
+ errorHandler;
6
11
  modules;
7
12
  pendingInstancePool = [];
8
- framework;
9
- constructor(framework) {
10
- this.modules = new Map();
13
+ constructor(framework = ServiceContainer.getService(ZumitoFramework), errorHandler = ServiceContainer.getService(ErrorHandler)) {
11
14
  this.framework = framework;
15
+ this.errorHandler = errorHandler;
16
+ this.modules = new Map();
12
17
  }
13
18
  set(name, module) {
14
19
  this.modules.set(name, module);
@@ -74,8 +79,10 @@ export class ModuleManager {
74
79
  this.modules.set(name || moduleInstance.constructor.name, moduleInstance);
75
80
  }
76
81
  catch (err) {
77
- console.error(`[📦🔴] Error loading module ${name || moduleInstance?.constructor?.name}: ${err.message}`);
78
- console.error(err.stack);
82
+ this.errorHandler.handleError(err, {
83
+ type: ErrorType.ModuleLoad,
84
+ moduleName: name || moduleInstance?.constructor?.name
85
+ });
79
86
  }
80
87
  }
81
88
  else {
@@ -30,7 +30,6 @@ export class GuildDataGetter {
30
30
  async getGuildSettings(guildId) {
31
31
  const collection = this.framework.database.collection('guilds');
32
32
  let guild = await collection.findOne({ guild_id: guildId });
33
- console.log(guild);
34
33
  if (!guild) {
35
34
  guild = {
36
35
  _id: new ObjectId(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",