zumito-framework 1.8.4 → 1.8.5

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.
Files changed (29) hide show
  1. package/dist/ZumitoFramework.d.ts +9 -9
  2. package/dist/ZumitoFramework.js +22 -41
  3. package/dist/definitions/CommandLoadOptions.d.ts +1 -1
  4. package/dist/definitions/Module.d.ts +1 -5
  5. package/dist/definitions/Module.js +0 -23
  6. package/dist/definitions/commands/CommandArguments.d.ts +2 -2
  7. package/dist/definitions/commands/CommandArguments.js +4 -1
  8. package/dist/definitions/commands/CommandBinds.d.ts +1 -1
  9. package/dist/definitions/commands/CommandParameters.d.ts +3 -3
  10. package/dist/definitions/parameters/ModuleParameters.d.ts +1 -1
  11. package/dist/definitions/settings/FrameworkSettings.d.ts +1 -1
  12. package/dist/definitions/settings/InteractionHandlerSettings.d.ts +1 -1
  13. package/dist/index.d.ts +1 -2
  14. package/dist/index.js +1 -2
  15. package/dist/modules/core/baseModule/events/discord/MessageCreate.d.ts +1 -1
  16. package/dist/modules/core/baseModule/events/discord/MessageCreate.js +11 -12
  17. package/dist/services/MongoService.d.ts +10 -0
  18. package/dist/services/MongoService.js +25 -0
  19. package/dist/services/handlers/ErrorHandler.d.ts +5 -5
  20. package/dist/services/handlers/InteractionHandler.js +3 -2
  21. package/dist/services/managers/ModuleManager.js +1 -4
  22. package/dist/services/utilities/GuildDataGetter.d.ts +1 -1
  23. package/dist/services/utilities/GuildDataGetter.js +13 -20
  24. package/dist/services/utilities/TextFormatter.d.ts +1 -1
  25. package/package.json +4 -5
  26. package/dist/definitions/DatabaseModel.d.ts +0 -70
  27. package/dist/definitions/DatabaseModel.js +0 -14
  28. package/dist/modules/core/baseModule/models/Guild.d.ts +0 -27
  29. package/dist/modules/core/baseModule/models/Guild.js +0 -32
@@ -1,5 +1,4 @@
1
1
  import { Client, GuildMember, TextChannel } from 'discord.js';
2
- import { DatabaseModel } from './definitions/DatabaseModel.js';
3
2
  import { EventEmitter } from "tseep";
4
3
  import { FrameworkEvent } from './definitions/FrameworkEvent.js';
5
4
  import { FrameworkSettings } from './definitions/settings/FrameworkSettings.js';
@@ -9,6 +8,8 @@ import { EventManager } from './services/managers/EventManager.js';
9
8
  import { CommandManager } from './services/managers/CommandManager.js';
10
9
  import { ModuleManager } from './services/managers/ModuleManager.js';
11
10
  import { Route } from './definitions/Route.js';
11
+ import { Db } from 'mongodb';
12
+ import { MongoService } from './services/MongoService.js';
12
13
  /**
13
14
  * @class ZumitoFramework
14
15
  * @description The main class of the framework.
@@ -67,18 +68,17 @@ export declare class ZumitoFramework {
67
68
  translations: TranslationManager;
68
69
  routes: Route[];
69
70
  /**
70
- * The database models loaded in the framework.
71
- * @type {Array<DatabaseModel>}
71
+ * The MongoDB service instance.
72
+ * @type {MongoService}
72
73
  * @private
73
74
  */
74
- models: Array<DatabaseModel>;
75
+ mongoService: MongoService;
75
76
  /**
76
- * The zumito-db database schema instance.
77
- * @type {zumitoDb.Schema}
77
+ * The MongoDB database instance (shortcut).
78
+ * @type {Db}
78
79
  * @private
79
- * @see {@link https://www.npmjs.com/package/zumito-db}
80
80
  */
81
- database: any;
81
+ database: Db;
82
82
  /**
83
83
  * The ExpressJS app instance.
84
84
  * @type {express.Application}
@@ -162,7 +162,7 @@ export declare class ZumitoFramework {
162
162
  *
163
163
  * @deprecated
164
164
  */
165
- getGuildSettings(guildId: string): Promise<unknown>;
165
+ getGuildSettings(guildId: string): Promise<import("mongodb").WithId<import("bson").Document>>;
166
166
  /**
167
167
  * @deprecated
168
168
  */
@@ -6,7 +6,6 @@ import { EventEmitter } from "tseep";
6
6
  import { StatusManager } from './services/managers/StatusManager.js';
7
7
  import { TranslationManager } from './services/managers/TranslationManager.js';
8
8
  import { betterLogging } from 'better-logging';
9
- import zumitoDb from 'zumito-db';
10
9
  import cookieParser from 'cookie-parser';
11
10
  import cors from 'cors';
12
11
  import express from 'express';
@@ -17,12 +16,12 @@ import { CommandManager } from './services/managers/CommandManager.js';
17
16
  import { ModuleManager } from './services/managers/ModuleManager.js';
18
17
  import { ServiceContainer } from './services/ServiceContainer.js';
19
18
  import { GuildDataGetter } from './services/utilities/GuildDataGetter.js';
20
- import { RecursiveObjectMerger } from './services/utilities/RecursiveObjectMerger.js';
21
19
  import { MemberPermissionChecker } from './services/utilities/MemberPermissionChecker.js';
22
20
  import { CommandParser } from './services/CommandParser.js';
23
21
  import { SlashCommandRefresher } from './services/SlashCommandRefresher.js';
24
22
  import { ErrorHandler } from './services/handlers/ErrorHandler.js';
25
23
  import { ErrorType } from './definitions/ErrorType.js';
24
+ import { MongoService } from './services/MongoService.js';
26
25
  // import better-logging
27
26
  betterLogging(console);
28
27
  /**
@@ -83,16 +82,15 @@ export class ZumitoFramework {
83
82
  translations;
84
83
  routes = [];
85
84
  /**
86
- * The database models loaded in the framework.
87
- * @type {Array<DatabaseModel>}
85
+ * The MongoDB service instance.
86
+ * @type {MongoService}
88
87
  * @private
89
88
  */
90
- models;
89
+ mongoService;
91
90
  /**
92
- * The zumito-db database schema instance.
93
- * @type {zumitoDb.Schema}
91
+ * The MongoDB database instance (shortcut).
92
+ * @type {Db}
94
93
  * @private
95
- * @see {@link https://www.npmjs.com/package/zumito-db}
96
94
  */
97
95
  database;
98
96
  /**
@@ -137,7 +135,6 @@ export class ZumitoFramework {
137
135
  this.commands = new CommandManager(this);
138
136
  this.events = new Map();
139
137
  this.translations = new TranslationManager();
140
- this.models = [];
141
138
  this.eventManager = new EventManager();
142
139
  ServiceContainer.addService(TranslationManager, [], true, this.translations);
143
140
  ServiceContainer.addService(CommandManager, [], true, this.commands);
@@ -175,24 +172,24 @@ export class ZumitoFramework {
175
172
  }
176
173
  }
177
174
  async initializeDatabase() {
178
- const folders = ['db', 'db/tingodb'];
179
- for (const folder of folders) {
180
- if (!fs.existsSync(folder)) {
181
- fs.mkdirSync(folder);
182
- }
175
+ const mongoUri = this.settings?.mongoQueryString || process.env.MONGO_URI;
176
+ if (!mongoUri) {
177
+ console.error('[🗄️🔴] MongoDB connection string not provided.');
178
+ process.exit(1);
183
179
  }
184
- this.database = new zumitoDb.Schema(this.settings?.database?.type || 'tingodb', this.settings?.database || {});
185
- await new Promise((resolve, reject) => {
186
- this.database.on('connected', resolve);
187
- this.database.on('error', reject);
188
- })
189
- .then(() => {
190
- console.log('[🗄️🟢] Database connection successful!');
191
- })
192
- .catch((err) => {
193
- console.error('[🗄️🔴] Database connection error:', err.message);
180
+ // Extract dbName from URI or fallback
181
+ const match = mongoUri.match(/\/([^/?]+)(\?|$)/);
182
+ const dbName = match ? match[1] : 'zumito';
183
+ this.mongoService = new MongoService(mongoUri, dbName);
184
+ try {
185
+ await this.mongoService.connect();
186
+ this.database = this.mongoService.db;
187
+ console.log('[🗄️🟢] MongoDB connection successful!');
188
+ }
189
+ catch (err) {
190
+ console.error('[🗄️🔴] MongoDB connection error:', err.message);
194
191
  process.exit(1);
195
- });
192
+ }
196
193
  }
197
194
  /**
198
195
  * Initializes and starts the API server using ExpressJS.
@@ -292,22 +289,6 @@ export class ZumitoFramework {
292
289
  else if (this.settings.srcMode == 'monoBundle') {
293
290
  await this.registerModule(process.cwd(), 'src');
294
291
  }
295
- // Define models
296
- const schemas = {};
297
- this.models.forEach((model) => {
298
- if (!schemas[model.name]) {
299
- schemas[model.name] = model.getModel(this.database);
300
- }
301
- else {
302
- schemas[model.name] = RecursiveObjectMerger.merge(schemas[model.name], model.getModel(this.database));
303
- }
304
- });
305
- Object.keys(schemas).forEach((schemaName) => {
306
- this.database.define(schemaName, schemas[schemaName]);
307
- });
308
- this.models.forEach((model) => {
309
- model.define(this.database.models[model.name], this.database.models);
310
- });
311
292
  }
312
293
  async registerModule(modulesFolder, moduleName, module) {
313
294
  if (!module) {
@@ -1,4 +1,4 @@
1
- export declare type CommandLoadOptions = {
1
+ export type CommandLoadOptions = {
2
2
  whitelist?: string[];
3
3
  blacklist?: string[];
4
4
  renames?: {
@@ -1,10 +1,9 @@
1
1
  import { ZumitoFramework } from '../ZumitoFramework.js';
2
2
  import { Command } from './commands/Command.js';
3
3
  import { FrameworkEvent } from './FrameworkEvent.js';
4
- import { DatabaseModel } from './DatabaseModel.js';
5
4
  import { CommandManager } from '../services/managers/CommandManager.js';
6
5
  import { ModuleParameters } from './parameters/ModuleParameters.js';
7
- export declare type ModuleRequeriments = {
6
+ export type ModuleRequeriments = {
8
7
  modules: Array<string>;
9
8
  services: Array<string>;
10
9
  custom: Array<() => Promise<boolean>>;
@@ -15,7 +14,6 @@ export declare abstract class Module {
15
14
  protected framework: ZumitoFramework;
16
15
  protected commands: CommandManager;
17
16
  protected events: Map<string, FrameworkEvent>;
18
- protected models: Array<DatabaseModel>;
19
17
  static requeriments: ModuleRequeriments;
20
18
  protected commandManager: CommandManager;
21
19
  constructor(path: any, parameters?: ModuleParameters);
@@ -28,8 +26,6 @@ export declare abstract class Module {
28
26
  parseEventArgs(args: any[]): any;
29
27
  getEvents(): Map<string, FrameworkEvent>;
30
28
  registerTranslations(subpath?: string): Promise<void>;
31
- registerModels(): Promise<void>;
32
- getModels(): Array<DatabaseModel>;
33
29
  registerRoutes(): Promise<void>;
34
30
  registerRoutesFolder(folder: string): Promise<void>;
35
31
  }
@@ -10,7 +10,6 @@ export class Module {
10
10
  framework;
11
11
  commands;
12
12
  events = new Map();
13
- models = [];
14
13
  static requeriments;
15
14
  commandManager;
16
15
  constructor(path, parameters) {
@@ -23,7 +22,6 @@ export class Module {
23
22
  await this.registerCommands();
24
23
  await this.registerEvents();
25
24
  await this.registerTranslations();
26
- await this.registerModels();
27
25
  await this.registerRoutes();
28
26
  }
29
27
  async registerCommands() {
@@ -111,27 +109,6 @@ export class Module {
111
109
  return;
112
110
  this.framework.translations.registerTranslationsFromFolder(path.join(this.path, 'translations', subpath), '', process.env.DEBUG ? true : false);
113
111
  }
114
- async registerModels() {
115
- if (!fs.existsSync(path.join(this.path, 'models')))
116
- return;
117
- const files = fs.readdirSync(path.join(this.path, 'models'));
118
- for (const file of files) {
119
- if (file.endsWith('.d.ts'))
120
- continue;
121
- if (file.endsWith('.ts') || file.endsWith('.js')) {
122
- let model = await import('file://' + `${this.path}/models/${file}`).catch((e) => {
123
- console.error(`[🔄🔴 ] Error loading ${file.slice(0, -3)} model on module ${this.constructor.name}`);
124
- console.error(e + '\n' + e.name + '\n' + e.stack);
125
- });
126
- model = Object.values(model)[0];
127
- model = new model();
128
- this.models.push(model);
129
- }
130
- }
131
- }
132
- getModels() {
133
- return this.models;
134
- }
135
112
  async registerRoutes() {
136
113
  const folderPath = path.join(this.path, 'routes');
137
114
  if (fs.existsSync(folderPath)) {
@@ -1,8 +1,8 @@
1
- import { CommandInteraction } from 'discord.js';
1
+ import { Interaction } from 'discord.js';
2
2
  export declare class CommandArguments {
3
3
  args: any;
4
4
  constructor(args?: {});
5
5
  get(key: any): any;
6
6
  add(key: any, value: any): void;
7
- static parseFromInteraction(interaction: CommandInteraction): CommandArguments;
7
+ static parseFromInteraction(interaction: Interaction): CommandArguments;
8
8
  }
@@ -10,6 +10,9 @@ export class CommandArguments {
10
10
  this.args[key] = value;
11
11
  }
12
12
  static parseFromInteraction(interaction) {
13
- return new CommandArguments(interaction.options);
13
+ if ('options' in interaction) {
14
+ return new CommandArguments(interaction.options);
15
+ }
16
+ return new CommandArguments();
14
17
  }
15
18
  }
@@ -1,6 +1,6 @@
1
1
  import { ModalSubmitParameters } from '../../definitions/parameters/ModalSubmitParameters.js';
2
2
  import { SelectMenuParameters } from '../parameters/SelectMenuParameters.js';
3
- export declare type CommandBinds = {
3
+ export type CommandBinds = {
4
4
  selectMenu?: (params: SelectMenuParameters) => Promise<void>;
5
5
  modalSubmit?: (params: ModalSubmitParameters) => Promise<void>;
6
6
  };
@@ -27,12 +27,12 @@ export interface BaseCommandParameters {
27
27
  guildSettings?: any;
28
28
  trans: (key: string, params?: any) => string;
29
29
  }
30
- export declare type SlashCommandParameters = BaseCommandParameters & {
30
+ export type SlashCommandParameters = BaseCommandParameters & {
31
31
  interaction: CommandInteraction;
32
32
  message?: null;
33
33
  };
34
- export declare type PrefixCommandParameters = BaseCommandParameters & {
34
+ export type PrefixCommandParameters = BaseCommandParameters & {
35
35
  message: Message;
36
36
  interaction?: null;
37
37
  };
38
- export declare type CommandParameters = PrefixCommandParameters | SlashCommandParameters;
38
+ export type CommandParameters = PrefixCommandParameters | SlashCommandParameters;
@@ -1,4 +1,4 @@
1
- export declare type ModuleParameters = {
1
+ export type ModuleParameters = {
2
2
  commandWhitelist?: string[];
3
3
  commandBlacklist?: string[];
4
4
  commandRenames?: {
@@ -1,7 +1,7 @@
1
1
  import { ModuleParameters } from "../parameters/ModuleParameters";
2
2
  import { StatusManagerOptions } from "../StatusManagerOptions";
3
3
  export interface FrameworkSettings {
4
- database: any;
4
+ mongoQueryString: string;
5
5
  logLevel?: number;
6
6
  debug?: boolean;
7
7
  discordClientOptions: {
@@ -1,3 +1,3 @@
1
- export declare type InteractionHandlerSettings = {
1
+ export type InteractionHandlerSettings = {
2
2
  disabledHandlers?: ('command' | 'selectMenu' | 'button' | 'modal')[];
3
3
  };
package/dist/index.d.ts CHANGED
@@ -9,7 +9,6 @@ import { CommandChoiceDefinition } from './definitions/commands/CommandChoiceDef
9
9
  import { CommandParameters } from './definitions/commands/CommandParameters.js';
10
10
  import { CommandType } from './definitions/commands/CommandType.js';
11
11
  import { DatabaseConfigLoader } from './services/utilities/DatabaseConfigLoader.js';
12
- import { DatabaseModel } from './definitions/DatabaseModel.js';
13
12
  import { EmojiFallback } from './services/EmojiFallback.js';
14
13
  import { FrameworkEvent } from './definitions/FrameworkEvent.js';
15
14
  import { FrameworkSettings } from './definitions/FrameworkSettings.js';
@@ -34,4 +33,4 @@ import { InviteUrlGenerator } from './services/utilities/InviteUrlGenerator.js';
34
33
  export { ModalSubmitParameters } from './definitions/parameters/ModalSubmitParameters.js';
35
34
  export { CommandBinds } from './definitions/commands/CommandBinds.js';
36
35
  export { Injectable } from './definitions/decorators/Injectable.decorator.js';
37
- export { ZumitoFramework, FrameworkSettings, Command, Module, CommandParameters, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, SelectMenuParameters, CommandType, CommandArgDefinition, CommandChoiceDefinition, ButtonPressed, ButtonPressedParams, TextFormatter, EmojiFallback, DatabaseConfigLoader, DatabaseModel, PresenceDataRule, RuledPresenceData, StatusManagerOptions, discord, EventParameters, ServiceContainer, GuildDataGetter, SlashCommandRefresher, CommandParser, ErrorHandler, ErrorType, Route, RouteMethod, InteractionHandler, CommandManager, InviteUrlGenerator };
36
+ export { ZumitoFramework, FrameworkSettings, Command, Module, CommandParameters, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, SelectMenuParameters, CommandType, CommandArgDefinition, CommandChoiceDefinition, ButtonPressed, ButtonPressedParams, TextFormatter, EmojiFallback, DatabaseConfigLoader, PresenceDataRule, RuledPresenceData, StatusManagerOptions, discord, EventParameters, ServiceContainer, GuildDataGetter, SlashCommandRefresher, CommandParser, ErrorHandler, ErrorType, Route, RouteMethod, InteractionHandler, CommandManager, InviteUrlGenerator };
package/dist/index.js CHANGED
@@ -4,7 +4,6 @@ import { Command } from './definitions/commands/Command.js';
4
4
  import { CommandArguments } from './definitions/commands/CommandArguments.js';
5
5
  import { CommandType } from './definitions/commands/CommandType.js';
6
6
  import { DatabaseConfigLoader } from './services/utilities/DatabaseConfigLoader.js';
7
- import { DatabaseModel } from './definitions/DatabaseModel.js';
8
7
  import { EmojiFallback } from './services/EmojiFallback.js';
9
8
  import { FrameworkEvent } from './definitions/FrameworkEvent.js';
10
9
  import { Module } from './definitions/Module.js';
@@ -34,4 +33,4 @@ ServiceContainer.addService(SlashCommandRefresher, [ZumitoFramework.name]);
34
33
  ServiceContainer.addService(InteractionHandler, []);
35
34
  ServiceContainer.addService(InviteUrlGenerator, []);
36
35
  ServiceContainer.addService(ErrorHandler, ['ZumitoFramework']);
37
- export { ZumitoFramework, Command, Module, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, CommandType, ButtonPressed, TextFormatter, EmojiFallback, DatabaseConfigLoader, DatabaseModel, discord, ServiceContainer, GuildDataGetter, SlashCommandRefresher, CommandParser, ErrorHandler, ErrorType, Route, RouteMethod, InteractionHandler, CommandManager, InviteUrlGenerator };
36
+ export { ZumitoFramework, Command, Module, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, CommandType, ButtonPressed, TextFormatter, EmojiFallback, DatabaseConfigLoader, discord, ServiceContainer, GuildDataGetter, SlashCommandRefresher, CommandParser, ErrorHandler, ErrorType, Route, RouteMethod, InteractionHandler, CommandManager, InviteUrlGenerator };
@@ -10,6 +10,6 @@ export declare class MessageCreate extends FrameworkEvent {
10
10
  framework: ZumitoFramework;
11
11
  guildDataGetter: GuildDataGetter;
12
12
  constructor();
13
- execute({ message, framework }: EventParameters): Promise<import("discord.js").Message<boolean>>;
13
+ execute({ message }: EventParameters): Promise<import("discord.js").OmitPartialGroupDMChannel<import("discord.js").Message<boolean>>>;
14
14
  autocorrect(str: string, words: string[]): any;
15
15
  }
@@ -20,26 +20,25 @@ export class MessageCreate extends FrameworkEvent {
20
20
  this.framework = ServiceContainer.getService(ZumitoFramework);
21
21
  this.guildDataGetter = ServiceContainer.getService(GuildDataGetter);
22
22
  }
23
- async execute({ message, framework }) {
23
+ async execute({ message }) {
24
24
  const channel = message.channel;
25
- const prefix = framework.settings.defaultPrefix;
25
+ const prefix = this.framework.settings.defaultPrefix;
26
26
  const args = CommandParser.splitCommandLine(message.content.slice(prefix.length));
27
27
  const command = args.shift().toLowerCase();
28
28
  let commandInstance;
29
29
  if (message.content.startsWith(prefix)) {
30
- debugger;
31
- if (!framework.commands.getAll().has(command)) {
32
- const commandNames = Array.from(framework.commands.getAll().keys());
30
+ if (!this.framework.commands.getAll().has(command)) {
31
+ const commandNames = Array.from(this.framework.commands.getAll().keys());
33
32
  const correctedCommand = this.autocorrect(command, commandNames);
34
- if (framework.commands.getAll().has(correctedCommand)) {
35
- commandInstance = framework.commands.get(correctedCommand);
33
+ if (this.framework.commands.getAll().has(correctedCommand)) {
34
+ commandInstance = this.framework.commands.get(correctedCommand);
36
35
  }
37
36
  else {
38
37
  return; // Command not found
39
38
  }
40
39
  }
41
40
  else {
42
- const tmpCmd = framework.commands.get(command);
41
+ const tmpCmd = this.framework.commands.get(command);
43
42
  if (tmpCmd && !tmpCmd.parent) {
44
43
  commandInstance = tmpCmd;
45
44
  }
@@ -103,15 +102,15 @@ export class MessageCreate extends FrameworkEvent {
103
102
  await commandInstance.execute({
104
103
  message,
105
104
  args: parsedArgs,
106
- client: framework.client,
107
- framework: framework,
105
+ client: this.framework.client,
106
+ framework: this.framework,
108
107
  guildSettings: guildSettings,
109
108
  trans: (key, params) => {
110
109
  if (key.startsWith('$')) {
111
- return framework.translations.get(key.replace('$', ''), guildSettings.lang, params);
110
+ return this.framework.translations.get(key.replace('$', ''), guildSettings.lang, params);
112
111
  }
113
112
  else {
114
- return framework.translations.get('command.' + commandInstance.name + '.' + key, guildSettings.lang, params);
113
+ return this.framework.translations.get('command.' + commandInstance.name + '.' + key, guildSettings.lang, params);
115
114
  }
116
115
  },
117
116
  }).catch((error) => {
@@ -0,0 +1,10 @@
1
+ import { MongoClient, Db } from 'mongodb';
2
+ export declare class MongoService {
3
+ private uri;
4
+ private dbName;
5
+ client: MongoClient;
6
+ db: Db;
7
+ constructor(uri: string, dbName: string);
8
+ connect(): Promise<Db>;
9
+ disconnect(): Promise<void>;
10
+ }
@@ -0,0 +1,25 @@
1
+ import { MongoClient } from 'mongodb';
2
+ export class MongoService {
3
+ uri;
4
+ dbName;
5
+ client;
6
+ db;
7
+ constructor(uri, dbName) {
8
+ this.uri = uri;
9
+ this.dbName = dbName;
10
+ }
11
+ async connect() {
12
+ if (!this.uri) {
13
+ throw new Error('MongoDB connection string not provided.');
14
+ }
15
+ this.client = new MongoClient(this.uri);
16
+ await this.client.connect();
17
+ this.db = this.client.db(this.dbName);
18
+ return this.db;
19
+ }
20
+ async disconnect() {
21
+ if (this.client) {
22
+ await this.client.close();
23
+ }
24
+ }
25
+ }
@@ -1,23 +1,23 @@
1
1
  import { ErrorType } from "../../definitions/ErrorType";
2
2
  import { Command } from "../../definitions/commands/Command";
3
3
  import { ZumitoFramework } from "../../ZumitoFramework";
4
- declare type BaseErrorOptions = {
4
+ type BaseErrorOptions = {
5
5
  exit?: boolean;
6
6
  type: ErrorType;
7
7
  };
8
- declare type CommandErrorOptions = BaseErrorOptions & {
8
+ type CommandErrorOptions = BaseErrorOptions & {
9
9
  type: ErrorType.CommandInstance | ErrorType.CommandLoad | ErrorType.CommandRun;
10
10
  command: Command;
11
11
  };
12
- declare type ApiErrorOptions = BaseErrorOptions & {
12
+ type ApiErrorOptions = BaseErrorOptions & {
13
13
  type: ErrorType.Api;
14
14
  endpoint: string;
15
15
  method: string;
16
16
  };
17
- declare type OtherErrorOptions = BaseErrorOptions & {
17
+ type OtherErrorOptions = BaseErrorOptions & {
18
18
  type: ErrorType.Other;
19
19
  };
20
- declare type ErrorOptions = CommandErrorOptions | ApiErrorOptions | OtherErrorOptions;
20
+ type ErrorOptions = CommandErrorOptions | ApiErrorOptions | OtherErrorOptions;
21
21
  export declare class ErrorHandler {
22
22
  framework: ZumitoFramework;
23
23
  constructor(framework: ZumitoFramework);
@@ -47,7 +47,8 @@ export class InteractionHandler {
47
47
  }
48
48
  }
49
49
  async handleCommandInteraction(interaction, guildSettings) {
50
- const subcommandName = interaction.options.getSubcommand(false);
50
+ const options = interaction.options;
51
+ const subcommandName = options.getSubcommand(false);
51
52
  const commandName = interaction.commandName;
52
53
  let commandInstance;
53
54
  if (subcommandName) {
@@ -61,7 +62,7 @@ export class InteractionHandler {
61
62
  const framework = ServiceContainer.getService(ZumitoFramework);
62
63
  const args = new Map();
63
64
  commandInstance.args.forEach((arg) => {
64
- const option = (interaction).options.get(arg.name);
65
+ const option = options.get(arg.name);
65
66
  if (option) {
66
67
  switch (arg.type) {
67
68
  case 'user':
@@ -48,10 +48,7 @@ export class ModuleManager {
48
48
  }
49
49
  // Register module events
50
50
  this.framework.events = new Map([...this.framework.events, ...module.getEvents()]);
51
- // Register models
52
- module.getModels().forEach((model) => {
53
- this.framework.models.push(model);
54
- });
51
+ // Register models (eliminado, migración a MongoDB)
55
52
  /*
56
53
 
57
54
  // Register module routes
@@ -25,5 +25,5 @@ export declare class GuildDataGetter {
25
25
  * // returns the guild settings
26
26
  * getGuildSettings(interaction.guildId);
27
27
  */
28
- getGuildSettings(guildId: string): Promise<unknown>;
28
+ getGuildSettings(guildId: string): Promise<import("mongodb").WithId<import("bson").Document>>;
29
29
  }
@@ -1,3 +1,4 @@
1
+ import { ObjectId } from "mongodb";
1
2
  export class GuildDataGetter {
2
3
  framework;
3
4
  constructor(framework) {
@@ -27,25 +28,17 @@ export class GuildDataGetter {
27
28
  * getGuildSettings(interaction.guildId);
28
29
  */
29
30
  async getGuildSettings(guildId) {
30
- const Guild = this.framework.database.models.Guild;
31
- return await new Promise((resolve, reject) => {
32
- Guild.findOne({ where: { guild_id: guildId } }, (err, guild) => {
33
- if (err)
34
- reject(err);
35
- if (guild == null) {
36
- guild = new Guild({
37
- guild_id: guildId,
38
- });
39
- guild.save((err) => {
40
- if (err)
41
- reject(err);
42
- resolve(guild);
43
- });
44
- }
45
- else {
46
- resolve(guild);
47
- }
48
- });
49
- });
31
+ const collection = this.framework.database.collection('guilds');
32
+ let guild = await collection.findOne({ guild_id: guildId });
33
+ guild = {
34
+ _id: new ObjectId(),
35
+ guild_id: guildId,
36
+ lang: 'en',
37
+ prefix: 'z-',
38
+ public: false,
39
+ deleteCommands: false
40
+ };
41
+ await collection.insertOne(guild);
42
+ return guild;
50
43
  }
51
44
  }
@@ -1,4 +1,4 @@
1
- declare type TimestampFormat = 'T' | 't' | 'd' | 'D' | 'f' | 'F' | 'R';
1
+ type TimestampFormat = 'T' | 't' | 'd' | 'D' | 'f' | 'F' | 'R';
2
2
  export declare class TextFormatter {
3
3
  static getUser(userId: string): string;
4
4
  static getChannel(channelId: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zumito-framework",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
4
4
  "description": "Discord.js bot framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "build-watch": "tsc -w",
15
15
  "lint": "eslint .",
16
16
  "publish-npm": "npm publish",
17
- "docs": "typedoc --out docs src"
17
+ "docs": "npx typedoc --out docs src"
18
18
  },
19
19
  "author": "ZumitoTeam",
20
20
  "license": "ISC",
@@ -28,7 +28,7 @@
28
28
  "chokidar": "^3.5.3",
29
29
  "cookie-parser": "^1.4.6",
30
30
  "cors": "^2.8.5",
31
- "discord.js": "^14.9.0",
31
+ "discord.js": "^14.21.0",
32
32
  "error-stack-parser": "^2.1.4",
33
33
  "express": "^4.18.1",
34
34
  "leven": "^4.0.0",
@@ -48,8 +48,7 @@
48
48
  "eslint-plugin-check-file": "^2.2.0",
49
49
  "eslint-plugin-prettier": "^4.2.1",
50
50
  "prettier": "^2.8.3",
51
- "typedoc": "^0.23.14",
52
- "typescript": "^4.8.3"
51
+ "typescript": "^5.8.3"
53
52
  },
54
53
  "type": "module",
55
54
  "exports": {
@@ -1,70 +0,0 @@
1
- import { ZumitoFramework } from '../ZumitoFramework.js';
2
- /**
3
- * @name DatabaseModel
4
- * @description Base class for all database models.
5
- * @see {@link https://docs.zumito.ga/docs/custom/create-database-model}
6
- */
7
- export declare abstract class DatabaseModel {
8
- readonly name: string;
9
- framework: ZumitoFramework;
10
- constructor(framework: ZumitoFramework);
11
- /**
12
- * @name getModel
13
- * @description This method should return the model that will be used by the framework.
14
- * @returns {any}
15
- * @example
16
- * ```ts
17
- * getModel(schema) {
18
- * return {
19
- * name: { type: schema.String, required: true },
20
- * age: { type: schema.Number, required: true },
21
- * email: { type: schema.String, limit: 155, unique: true },
22
- * approved: { type: schema.Boolean, default: false, index: true }
23
- * joinedAt: { type: schema.Date, default: Date.now },
24
- * };
25
- * ```
26
- * @see {@link https://docs.zumito.ga/docs/custom/create-database-model#model}
27
- */
28
- abstract getModel(schema: any): any;
29
- /**
30
- * @name define
31
- * @description This method is called after all models are loaded. Here you can define relationships, validations, hooks, methods, etc.
32
- * @param {any} model The model that was returned by the {@link DatabaseModel.getModel} method.
33
- * @param {any} schema The schema of the database.
34
- * @example
35
- * Example of defining a relationship:
36
- * ```ts
37
- * define(model, models) {
38
- * model.hasMany(models.SocialMediaUrl, {as: 'socialMediaUrl', foreignKey: 'userId'});
39
- * }
40
- * ```
41
- * @example
42
- * Example of defining a validation:
43
- * ```ts
44
- * define(model) {
45
- * model.validatesPresenceOf('name', 'email')
46
- * model.validatesUniquenessOf('email', {message: 'email is not unique'});
47
- * model.validatesInclusionOf('gender', {in: ['male', 'female']});
48
- * model.validatesNumericalityOf('age', {int: true});
49
- * ```
50
- * @example
51
- * Example of defining a hook:
52
- * ```ts
53
- * define(model) {
54
- * model.afterUpdate = function (next) {
55
- * this.updated = new Date();
56
- * this.save();
57
- * next();
58
- * };
59
- * ```
60
- * @example
61
- * Example of defining a method:
62
- * ```ts
63
- * define(model) {
64
- * model.prototype.getNameAndAge = function () {
65
- * return this.name + ', ' + this.age;
66
- * };
67
- * ```
68
- */
69
- abstract define(model: any, models: any): void;
70
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * @name DatabaseModel
3
- * @description Base class for all database models.
4
- * @see {@link https://docs.zumito.ga/docs/custom/create-database-model}
5
- */
6
- export class DatabaseModel {
7
- // set name to the name of the class capitalized first letter
8
- name = this.constructor.name.charAt(0).toUpperCase() +
9
- this.constructor.name.slice(1);
10
- framework;
11
- constructor(framework) {
12
- this.framework = framework;
13
- }
14
- }
@@ -1,27 +0,0 @@
1
- import { DatabaseModel } from '../../../../definitions/DatabaseModel.js';
2
- export declare class Guild extends DatabaseModel {
3
- getModel(schema: any): {
4
- guild_id: {
5
- type: any;
6
- required: boolean;
7
- unique: boolean;
8
- };
9
- lang: {
10
- type: any;
11
- default: string;
12
- };
13
- prefix: {
14
- type: any;
15
- default: string;
16
- };
17
- public: {
18
- type: any;
19
- default: boolean;
20
- };
21
- deleteCommands: {
22
- type: any;
23
- default: boolean;
24
- };
25
- };
26
- define(model: any, models: any): void;
27
- }
@@ -1,32 +0,0 @@
1
- import { DatabaseModel } from '../../../../definitions/DatabaseModel.js';
2
- export class Guild extends DatabaseModel {
3
- getModel(schema) {
4
- return {
5
- guild_id: {
6
- type: schema.String,
7
- required: true,
8
- unique: true,
9
- },
10
- lang: {
11
- type: schema.String,
12
- default: 'en',
13
- },
14
- prefix: {
15
- type: schema.String,
16
- default: 'z-',
17
- },
18
- public: {
19
- type: schema.Boolean,
20
- default: false,
21
- },
22
- deleteCommands: {
23
- type: schema.Boolean,
24
- default: false,
25
- },
26
- };
27
- }
28
- define(model, models) {
29
- model.validatesUniquenessOf('guild_id');
30
- model.validatesInclusionOf('lang', { in: ['en', 'es'] });
31
- }
32
- }