zumito-framework 1.1.70 → 1.1.72-dev-update-pull-request-ci.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.
Files changed (76) hide show
  1. package/dist/ZumitoFramework.d.ts +20 -12
  2. package/dist/ZumitoFramework.js +36 -61
  3. package/dist/{types → definitions}/Module.d.ts +6 -8
  4. package/dist/definitions/Module.js +129 -0
  5. package/dist/{types → definitions}/Translation.d.ts +0 -1
  6. package/dist/{types → definitions}/Translation.js +0 -1
  7. package/dist/{types → definitions/commands}/Command.d.ts +1 -1
  8. package/dist/{types → definitions/commands}/CommandParameters.d.ts +1 -1
  9. package/dist/{types → definitions/parameters}/EventParameters.d.ts +1 -1
  10. package/dist/{types/Commands → definitions/parameters}/SelectMenu.d.ts +1 -1
  11. package/dist/{types → definitions/parameters}/SelectMenuParameters.d.ts +1 -1
  12. package/dist/index.d.ts +21 -21
  13. package/dist/index.js +13 -13
  14. package/dist/{baseModule/events/discord/interactionCreate.d.ts → modules/core/baseModule/events/discord/InteractionCreate.d.ts} +3 -3
  15. package/dist/{baseModule/events/discord/interactionCreate.js → modules/core/baseModule/events/discord/InteractionCreate.js} +28 -21
  16. package/dist/{baseModule/events/discord/messageCreate.d.ts → modules/core/baseModule/events/discord/MessageCreate.d.ts} +3 -3
  17. package/dist/{baseModule/events/discord/messageCreate.js → modules/core/baseModule/events/discord/MessageCreate.js} +8 -10
  18. package/dist/{baseModule → modules/core/baseModule}/models/Guild.d.ts +1 -1
  19. package/dist/{baseModule → modules/core/baseModule}/models/Guild.js +1 -1
  20. package/dist/services/CommandManager.d.ts +40 -0
  21. package/dist/services/CommandManager.js +160 -0
  22. package/dist/services/EventManager.d.ts +8 -0
  23. package/dist/services/EventManager.js +27 -0
  24. package/dist/services/InteractionIdGenerator.d.ts +13 -0
  25. package/dist/services/InteractionIdGenerator.js +40 -0
  26. package/dist/services/ModuleManager.d.ts +17 -0
  27. package/dist/services/ModuleManager.js +78 -0
  28. package/dist/{managers → services}/StatusManager.d.ts +1 -1
  29. package/dist/services/TranslationManager.d.ts +34 -0
  30. package/dist/services/TranslationManager.js +122 -0
  31. package/package.json +9 -4
  32. package/dist/TranslationManager.d.ts +0 -15
  33. package/dist/TranslationManager.js +0 -41
  34. package/dist/baseModule/BaseModule.d.ts +0 -6
  35. package/dist/baseModule/BaseModule.js +0 -16
  36. package/dist/baseModule/index.d.ts +0 -7
  37. package/dist/baseModule/index.js +0 -19
  38. package/dist/types/Commands.d.ts +0 -23
  39. package/dist/types/Commands.js +0 -26
  40. package/dist/types/Module.js +0 -211
  41. /package/dist/{types → definitions}/DatabaseModel.d.ts +0 -0
  42. /package/dist/{types → definitions}/DatabaseModel.js +0 -0
  43. /package/dist/{types → definitions}/FrameworkEvent.d.ts +0 -0
  44. /package/dist/{types → definitions}/FrameworkEvent.js +0 -0
  45. /package/dist/{types → definitions}/FrameworkSettings.d.ts +0 -0
  46. /package/dist/{types → definitions}/FrameworkSettings.js +0 -0
  47. /package/dist/{types → definitions}/StatusManagerOptions.d.ts +0 -0
  48. /package/dist/{types → definitions}/StatusManagerOptions.js +0 -0
  49. /package/dist/definitions/{ApiResponse.d.ts → api/ApiResponse.d.ts} +0 -0
  50. /package/dist/definitions/{ApiResponse.js → api/ApiResponse.js} +0 -0
  51. /package/dist/{types → definitions/commands}/Command.js +0 -0
  52. /package/dist/{types → definitions/commands}/CommandArgDefinition.d.ts +0 -0
  53. /package/dist/{types → definitions/commands}/CommandArgDefinition.js +0 -0
  54. /package/dist/{types → definitions/commands}/CommandArguments.d.ts +0 -0
  55. /package/dist/{types → definitions/commands}/CommandArguments.js +0 -0
  56. /package/dist/{types → definitions/commands}/CommandChoiceDefinition.d.ts +0 -0
  57. /package/dist/{types → definitions/commands}/CommandChoiceDefinition.js +0 -0
  58. /package/dist/{types → definitions/commands}/CommandParameters.js +0 -0
  59. /package/dist/{types → definitions/commands}/CommandType.d.ts +0 -0
  60. /package/dist/{types → definitions/commands}/CommandType.js +0 -0
  61. /package/dist/{types/Commands → definitions/parameters}/ButtonPressed.d.ts +0 -0
  62. /package/dist/{types/Commands → definitions/parameters}/ButtonPressed.js +0 -0
  63. /package/dist/{types/Commands → definitions/parameters}/ButtonPressedParams.d.ts +0 -0
  64. /package/dist/{types/Commands → definitions/parameters}/ButtonPressedParams.js +0 -0
  65. /package/dist/{types → definitions/parameters}/EventParameters.js +0 -0
  66. /package/dist/{types/Commands → definitions/parameters}/SelectMenu.js +0 -0
  67. /package/dist/{types → definitions/parameters}/SelectMenuParameters.js +0 -0
  68. /package/dist/{utils → services}/DatabaseConfigLoader.d.ts +0 -0
  69. /package/dist/{utils → services}/DatabaseConfigLoader.js +0 -0
  70. /package/dist/{utils → services}/EmojiFallback.d.ts +0 -0
  71. /package/dist/{utils → services}/EmojiFallback.js +0 -0
  72. /package/dist/{managers → services}/EmojiManager.d.ts +0 -0
  73. /package/dist/{managers → services}/EmojiManager.js +0 -0
  74. /package/dist/{managers → services}/StatusManager.js +0 -0
  75. /package/dist/{utils → services}/TextFormatter.d.ts +0 -0
  76. /package/dist/{utils → services}/TextFormatter.js +0 -0
@@ -1,12 +1,13 @@
1
1
  import { Client, GuildMember, TextChannel } from 'discord.js';
2
- import { Command } from './types/Command.js';
3
- import { DatabaseModel } from './types/DatabaseModel.js';
2
+ import { DatabaseModel } from './definitions/DatabaseModel.js';
4
3
  import { EventEmitter } from 'events';
5
- import { FrameworkEvent } from './types/FrameworkEvent.js';
6
- import { FrameworkSettings } from './types/FrameworkSettings.js';
7
- import { Module } from './types/Module.js';
8
- import { StatusManager } from './managers/StatusManager.js';
9
- import { TranslationManager } from './TranslationManager.js';
4
+ import { FrameworkEvent } from './definitions/FrameworkEvent.js';
5
+ import { FrameworkSettings } from './definitions/FrameworkSettings.js';
6
+ import { StatusManager } from './services/StatusManager.js';
7
+ import { TranslationManager } from './services/TranslationManager.js';
8
+ import { EventManager } from './services/EventManager.js';
9
+ import { CommandManager } from './services/CommandManager.js';
10
+ import { ModuleManager } from './services/ModuleManager.js';
10
11
  /**
11
12
  * @class ZumitoFramework
12
13
  * @description The main class of the framework.
@@ -37,18 +38,18 @@ export declare class ZumitoFramework {
37
38
  */
38
39
  settings: FrameworkSettings;
39
40
  /**
40
- * The modules loaded in the framework.
41
- * @type {Map<string, Module>}
41
+ * Module manager instance
42
+ * @type {ModuleManager}
42
43
  * @private
43
44
  */
44
- modules: Map<string, Module>;
45
+ modules: ModuleManager;
45
46
  /**
46
47
  * The commands loaded in the framework.
47
- * @type {Map<string, Command>}
48
+ * @type {CommandManager}
48
49
  * @private
49
50
  * @see {@link Command}
50
51
  */
51
- commands: Map<string, Command>;
52
+ commands: CommandManager;
52
53
  /**
53
54
  * The events loaded in the framework.
54
55
  * @type {Map<string, FrameworkEvent>}
@@ -99,6 +100,13 @@ export declare class ZumitoFramework {
99
100
  * @see {@link https://nodejs.org/api/events.html#events_class_eventemitter}
100
101
  */
101
102
  eventEmitter: EventEmitter;
103
+ /**
104
+ * Event manager for the framework.
105
+ * All events related to the framework and discord.js are handled here.
106
+ * @type {EventManager}
107
+ * @private
108
+ */
109
+ eventManager: EventManager;
102
110
  /**
103
111
  * @constructor
104
112
  * @param {FrameworkSettings} settings - The settings to use for the framework.
@@ -1,15 +1,13 @@
1
1
  import * as fs from 'fs';
2
2
  import * as url from 'url';
3
3
  import { Client, SlashCommandBuilder, } from 'discord.js';
4
- import { ApiResponse } from './definitions/ApiResponse.js';
5
- import { CommandType } from './types/CommandType.js';
4
+ import { ApiResponse } from './definitions/api/ApiResponse.js';
5
+ import { CommandType } from './definitions/commands/CommandType.js';
6
6
  import { EventEmitter } from 'events';
7
- import { Module } from './types/Module.js';
8
7
  import { REST } from '@discordjs/rest';
9
8
  import { Routes } from 'discord-api-types/v9';
10
- import { StatusManager } from './managers/StatusManager.js';
11
- import { TranslationManager } from './TranslationManager.js';
12
- import { baseModule } from './baseModule/index.js';
9
+ import { StatusManager } from './services/StatusManager.js';
10
+ import { TranslationManager } from './services/TranslationManager.js';
13
11
  import { betterLogging } from 'better-logging';
14
12
  import canario from 'canario';
15
13
  import cookieParser from 'cookie-parser';
@@ -17,6 +15,9 @@ import cors from 'cors';
17
15
  import express from 'express';
18
16
  import http from 'http';
19
17
  import path from 'path';
18
+ import { EventManager } from './services/EventManager.js';
19
+ import { CommandManager } from './services/CommandManager.js';
20
+ import { ModuleManager } from './services/ModuleManager.js';
20
21
  // import better-logging
21
22
  betterLogging(console);
22
23
  /**
@@ -49,14 +50,14 @@ export class ZumitoFramework {
49
50
  */
50
51
  settings;
51
52
  /**
52
- * The modules loaded in the framework.
53
- * @type {Map<string, Module>}
53
+ * Module manager instance
54
+ * @type {ModuleManager}
54
55
  * @private
55
56
  */
56
57
  modules;
57
58
  /**
58
59
  * The commands loaded in the framework.
59
- * @type {Map<string, Command>}
60
+ * @type {CommandManager}
60
61
  * @private
61
62
  * @see {@link Command}
62
63
  */
@@ -111,6 +112,13 @@ export class ZumitoFramework {
111
112
  * @see {@link https://nodejs.org/api/events.html#events_class_eventemitter}
112
113
  */
113
114
  eventEmitter = new EventEmitter();
115
+ /**
116
+ * Event manager for the framework.
117
+ * All events related to the framework and discord.js are handled here.
118
+ * @type {EventManager}
119
+ * @private
120
+ */
121
+ eventManager;
114
122
  /**
115
123
  * @constructor
116
124
  * @param {FrameworkSettings} settings - The settings to use for the framework.
@@ -118,11 +126,12 @@ export class ZumitoFramework {
118
126
  */
119
127
  constructor(settings, callback) {
120
128
  this.settings = settings;
121
- this.modules = new Map();
122
- this.commands = new Map();
129
+ this.modules = new ModuleManager(this);
130
+ this.commands = new CommandManager(this);
123
131
  this.events = new Map();
124
132
  this.translations = new TranslationManager();
125
133
  this.models = [];
134
+ this.eventManager = new EventManager();
126
135
  if (settings.logLevel) {
127
136
  console.logLevel = settings.logLevel;
128
137
  }
@@ -145,8 +154,10 @@ export class ZumitoFramework {
145
154
  */
146
155
  async initialize() {
147
156
  await this.initializeDatabase();
148
- this.initializeDiscordClient();
157
+ await this.initializeDiscordClient();
149
158
  this.startApiServer();
159
+ this.eventManager.addEventEmitter('discord', this.client);
160
+ this.eventManager.addEventEmitter('framework', this.eventEmitter);
150
161
  await this.registerModules();
151
162
  await this.refreshSlashCommands();
152
163
  if (this.settings.statusOptions) {
@@ -226,7 +237,7 @@ export class ZumitoFramework {
226
237
  else
227
238
  return;
228
239
  const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
229
- await this.registerModule(__dirname, 'baseModule', baseModule);
240
+ await this.registerModule(path.join(__dirname, 'modules', 'core'), 'baseModule');
230
241
  const files = fs.readdirSync(modulesFolder);
231
242
  for (const file of files) {
232
243
  await this.registerModule(modulesFolder, file);
@@ -250,65 +261,29 @@ export class ZumitoFramework {
250
261
  }
251
262
  async registerModule(modulesFolder, moduleName, module) {
252
263
  if (!module) {
253
- if (fs.existsSync(path.join(modulesFolder, moduleName, 'index.js'))) {
254
- module = await import('file://' + path.join(modulesFolder, moduleName, 'index.js'));
255
- module = Object.values(module)[0];
256
- }
257
- else if (fs.existsSync(path.join(modulesFolder, moduleName, 'index.ts'))) {
258
- module = await import('file://' + path.join(modulesFolder, moduleName, 'index.ts'));
259
- module = Object.values(module)[0];
260
- }
261
- else {
262
- module = Module;
263
- }
264
+ module = await this.modules.loadModuleFile(path.join(modulesFolder, moduleName));
264
265
  }
265
266
  // Create module instance
266
- let moduleInstance;
267
- try {
268
- moduleInstance = new module(path.join(modulesFolder, moduleName), this);
269
- await moduleInstance.initialize();
270
- this.modules.set(moduleName || moduleInstance.constructor.name, moduleInstance);
271
- }
272
- catch (err) {
273
- console.error(`[📦🔴] Error loading module ${moduleName}: ${err.message}`);
274
- console.error(err.stack);
275
- }
276
- // Register module commands
277
- if (moduleInstance.getCommands()) {
278
- moduleInstance.getCommands().forEach((command) => {
279
- this.commands.set(command.name, command);
280
- });
281
- }
282
- this.commands = new Map([
283
- ...this.commands,
284
- ...moduleInstance.getCommands(),
285
- ]);
286
- // Register module events
287
- this.events = new Map([...this.events, ...moduleInstance.getEvents()]);
288
- // Register models
289
- moduleInstance.getModels().forEach((model) => {
290
- this.models.push(model);
291
- });
292
- /*
293
-
294
- // Register module routes
295
- this.routes = new Map([...this.routes, ...moduleInstance.getRoutes()]);
296
-
297
- */
267
+ const moduleInstance = await this.modules.instanceModule(module, path.join(modulesFolder, moduleName), moduleName);
268
+ // Register module in the framework
269
+ this.modules.registerModule(moduleInstance);
298
270
  }
299
271
  /**
300
272
  * Initializes the Discord client using the Discord.js library.
301
273
  * Logs in to the Discord API using the provided token and logs a message when the client is ready.
302
274
  * @private
303
275
  */
304
- initializeDiscordClient() {
276
+ async initializeDiscordClient() {
305
277
  this.client = new Client({
306
278
  intents: this.settings.discordClientOptions.intents,
307
279
  });
308
280
  this.client.login(this.settings.discordClientOptions.token);
309
- this.client.on('ready', () => {
310
- // Bot emoji
311
- console.log('[🤖🟢] Discord client ready');
281
+ await new Promise((resolve) => {
282
+ this.client.on('ready', () => {
283
+ // Bot emoji
284
+ console.log('[🤖🟢] Discord client ready');
285
+ resolve();
286
+ });
312
287
  });
313
288
  }
314
289
  /**
@@ -414,7 +389,7 @@ export class ZumitoFramework {
414
389
  }
415
390
  async refreshSlashCommands() {
416
391
  const rest = new REST({ version: '10' }).setToken(this.settings.discordClientOptions.token);
417
- const commands = Array.from(this.commands.values())
392
+ const commands = Array.from(this.commands.getAll().values())
418
393
  .filter((command) => command.type == CommandType.slash ||
419
394
  command.type == CommandType.separated ||
420
395
  command.type == CommandType.any)
@@ -1,27 +1,25 @@
1
1
  import { ZumitoFramework } from '../ZumitoFramework.js';
2
- import { Command } from './Command.js';
2
+ import { Command } from './commands/Command.js';
3
3
  import { FrameworkEvent } from './FrameworkEvent.js';
4
4
  import { DatabaseModel } from './DatabaseModel.js';
5
+ import { CommandManager } from '../services/CommandManager.js';
5
6
  export declare abstract class Module {
6
7
  protected path: string;
7
8
  protected framework: ZumitoFramework;
8
- protected commands: Map<string, Command>;
9
+ protected commands: CommandManager;
9
10
  protected events: Map<string, FrameworkEvent>;
10
11
  protected models: Array<DatabaseModel>;
12
+ protected commandManager: CommandManager;
11
13
  constructor(path: any, framework: any);
12
14
  initialize(): Promise<void>;
13
15
  registerCommands(): Promise<void>;
14
- onCommandCreated(filePath: string): Promise<void>;
15
- onCommandChanged(filePath: string): Promise<void>;
16
- onErrorLoadingCommand(error: Error): void;
17
16
  getCommands(): Map<string, Command>;
18
17
  registerEvents(): Promise<void>;
19
- registerDiscordEvent(frameworkEvent: FrameworkEvent): void;
18
+ registerEventsFolder(folder: string): Promise<void>;
19
+ registerEvent(frameworkEvent: FrameworkEvent, emitterName: string): void;
20
20
  parseEventArgs(args: any[]): any;
21
21
  getEvents(): Map<string, FrameworkEvent>;
22
22
  registerTranslations(subpath?: string): Promise<void>;
23
- loadTranslationFile(subpath: string, file: string): Promise<any>;
24
- parseTranslation(path: string, lang: string, json: any): any;
25
23
  registerModels(): Promise<void>;
26
24
  getModels(): Array<DatabaseModel>;
27
25
  }
@@ -0,0 +1,129 @@
1
+ import * as fs from 'fs';
2
+ import path from 'path';
3
+ import { ButtonInteraction, CommandInteraction, ModalSubmitInteraction, StringSelectMenuInteraction, } from 'discord.js';
4
+ import { CommandManager } from '../services/CommandManager.js';
5
+ export class Module {
6
+ path;
7
+ framework;
8
+ commands;
9
+ events = new Map();
10
+ models = [];
11
+ commandManager;
12
+ constructor(path, framework) {
13
+ this.path = path;
14
+ this.framework = framework;
15
+ this.commands = new CommandManager(framework);
16
+ }
17
+ async initialize() {
18
+ await this.registerCommands();
19
+ await this.registerEvents();
20
+ await this.registerTranslations();
21
+ await this.registerModels();
22
+ }
23
+ async registerCommands() {
24
+ const commandsFolder = path.join(this.path, 'commands');
25
+ if (fs.existsSync(commandsFolder)) {
26
+ await this.commands.loadCommandsFolder(commandsFolder);
27
+ // register watcher
28
+ if (process.env.DEBUG) {
29
+ /*
30
+ Debug only cause in prod environment commands should't be changed.
31
+ Appart from that, esm module cache invalidation is not working properly
32
+ and can cause memory leaks and crashes.
33
+ */
34
+ this.commands.watchCommandsFolder(commandsFolder);
35
+ }
36
+ }
37
+ }
38
+ getCommands() {
39
+ return this.commands.getAll();
40
+ }
41
+ async registerEvents() {
42
+ if (!fs.existsSync(path.join(this.path, 'events')))
43
+ return;
44
+ const files = fs.readdirSync(path.join(this.path, 'events'));
45
+ for (const file of files) {
46
+ // if file is folder
47
+ if (fs.lstatSync(path.join(this.path, 'events', file)).isDirectory()) {
48
+ console.log('registering events folder ' + file);
49
+ this.registerEventsFolder(file);
50
+ }
51
+ }
52
+ }
53
+ async registerEventsFolder(folder) {
54
+ const folderPath = path.join(this.path, 'events', folder);
55
+ if (!fs.existsSync(folderPath))
56
+ throw new Error(`Folder ${folder} doesn't exist`);
57
+ const files = fs.readdirSync(folderPath);
58
+ for (const file of files) {
59
+ if (file.endsWith('d.ts'))
60
+ continue;
61
+ if (file.endsWith('.js') || file.endsWith('.ts')) {
62
+ let event = await import('file://' + path.join(folderPath, file)).catch((e) => {
63
+ console.error(`[🔄🔴 ] Error loading ${file.slice(0, -3)} event on module ${this.constructor.name}`);
64
+ });
65
+ event = Object.values(event)[0];
66
+ event = new event();
67
+ this.events.set(event.constructor.name.toLowerCase(), event);
68
+ this.registerEvent(event, folder);
69
+ }
70
+ }
71
+ }
72
+ registerEvent(frameworkEvent, emitterName) {
73
+ if (frameworkEvent.disabled)
74
+ return;
75
+ const once = frameworkEvent.once;
76
+ const eventName = frameworkEvent.constructor.name.charAt(0).toLowerCase() +
77
+ frameworkEvent.constructor.name.slice(1);
78
+ this.framework.eventManager.addEventListener(emitterName, eventName, (...args) => {
79
+ const finalArgs = this.parseEventArgs(args);
80
+ frameworkEvent.execute(finalArgs);
81
+ }, { once });
82
+ }
83
+ parseEventArgs(args) {
84
+ const finalArgs = {
85
+ framework: this.framework,
86
+ client: this.framework.client,
87
+ };
88
+ args.forEach((arg) => {
89
+ finalArgs[arg.constructor.name.toLowerCase()] = arg;
90
+ });
91
+ const interaction = args.find((arg) => arg instanceof StringSelectMenuInteraction ||
92
+ arg instanceof CommandInteraction ||
93
+ arg instanceof ButtonInteraction ||
94
+ arg instanceof ModalSubmitInteraction);
95
+ if (interaction) {
96
+ finalArgs['interaction'] = interaction;
97
+ }
98
+ return finalArgs;
99
+ }
100
+ getEvents() {
101
+ return this.events;
102
+ }
103
+ async registerTranslations(subpath = '') {
104
+ if (!fs.existsSync(path.join(this.path, 'translations', subpath)))
105
+ return;
106
+ this.framework.translations.registerTranslationsFromFolder(path.join(this.path, 'translations', subpath), '', process.env.DEBUG ? true : false);
107
+ }
108
+ async registerModels() {
109
+ if (!fs.existsSync(path.join(this.path, 'models')))
110
+ return;
111
+ const files = fs.readdirSync(path.join(this.path, 'models'));
112
+ for (const file of files) {
113
+ if (file.endsWith('d.ts'))
114
+ continue;
115
+ if (file.endsWith('.ts') || file.endsWith('.js')) {
116
+ let model = await import('file://' + `${this.path}/models/${file}`).catch((e) => {
117
+ console.error(`[🔄🔴 ] Error loading ${file.slice(0, -3)} model on module ${this.constructor.name}`);
118
+ console.error(e + '\n' + e.name + '\n' + e.stack);
119
+ });
120
+ model = Object.values(model)[0];
121
+ model = new model();
122
+ this.models.push(model);
123
+ }
124
+ }
125
+ }
126
+ getModels() {
127
+ return this.models;
128
+ }
129
+ }
@@ -1,6 +1,5 @@
1
1
  export declare class Translation {
2
2
  text: Map<string, string>;
3
- constructor();
4
3
  get(language: string, params?: any): string;
5
4
  set(language: string, text: string): void;
6
5
  has(language: string): boolean;
@@ -1,6 +1,5 @@
1
1
  export class Translation {
2
2
  text = new Map();
3
- constructor() { }
4
3
  get(language, params) {
5
4
  let text;
6
5
  if (this.has(language)) {
@@ -1,6 +1,6 @@
1
1
  import { CommandArgDefinition } from './CommandArgDefinition.js';
2
2
  import { CommandParameters } from './CommandParameters.js';
3
- import { SelectMenuParameters } from './SelectMenuParameters.js';
3
+ import { SelectMenuParameters } from '../parameters/SelectMenuParameters.js';
4
4
  /**
5
5
  * @name Command
6
6
  * @description Base class for all commands
@@ -1,5 +1,5 @@
1
1
  import { Client, CommandInteraction, Message } from 'discord.js';
2
- import { ZumitoFramework } from '../ZumitoFramework.js';
2
+ import { ZumitoFramework } from '../../ZumitoFramework.js';
3
3
  /**
4
4
  * @class CommandParameters
5
5
  * @classdesc Parameters passed to a command execution.
@@ -1,5 +1,5 @@
1
1
  import { Client, Interaction, Message } from 'discord.js';
2
- import { ZumitoFramework } from '../ZumitoFramework.js';
2
+ import { ZumitoFramework } from '../../ZumitoFramework.js';
3
3
  export interface EventParameters {
4
4
  message?: Message;
5
5
  interaction?: Interaction;
@@ -1,4 +1,4 @@
1
- import { SelectMenuParameters } from '../SelectMenuParameters.js';
1
+ import { SelectMenuParameters } from './SelectMenuParameters.js';
2
2
  export declare abstract class SelectMenuSelected {
3
3
  abstract selectMenu(selectMenuParameters: SelectMenuParameters): void;
4
4
  }
@@ -1,5 +1,5 @@
1
1
  import { Client, SelectMenuInteraction } from 'discord.js';
2
- import { ZumitoFramework } from '../ZumitoFramework.js';
2
+ import { ZumitoFramework } from '../../ZumitoFramework.js';
3
3
  export interface SelectMenuParameters {
4
4
  path: string[];
5
5
  interaction: SelectMenuInteraction;
package/dist/index.d.ts CHANGED
@@ -1,24 +1,24 @@
1
- import { PresenceDataRule, RuledPresenceData, StatusManagerOptions } from './types/StatusManagerOptions.js';
2
- import { ApiResponse } from './definitions/ApiResponse.js';
3
- import { ButtonPressed } from './types/Commands/ButtonPressed.js';
4
- import { ButtonPressedParams } from './types/Commands/ButtonPressedParams.js';
5
- import { Command } from './types/Command.js';
6
- import { CommandArgDefinition } from './types/CommandArgDefinition.js';
7
- import { CommandArguments } from './types/CommandArguments.js';
8
- import { CommandChoiceDefinition } from './types/CommandChoiceDefinition.js';
9
- import { CommandParameters } from './types/CommandParameters.js';
10
- import { CommandType } from './types/CommandType.js';
11
- import { DatabaseConfigLoader } from './utils/DatabaseConfigLoader.js';
12
- import { DatabaseModel } from './types/DatabaseModel.js';
13
- import { EmojiFallback } from './utils/EmojiFallback.js';
14
- import { FrameworkEvent } from './types/FrameworkEvent.js';
15
- import { FrameworkSettings } from './types/FrameworkSettings.js';
16
- import { Module } from './types/Module.js';
17
- import { SelectMenuParameters } from './types/SelectMenuParameters.js';
18
- import { TextFormatter } from './utils/TextFormatter.js';
19
- import { Translation } from './types/Translation.js';
20
- import { TranslationManager } from './TranslationManager.js';
1
+ import { PresenceDataRule, RuledPresenceData, StatusManagerOptions } from './definitions/StatusManagerOptions.js';
2
+ import { ApiResponse } from './definitions/api/ApiResponse.js';
3
+ import { ButtonPressed } from './definitions/parameters/ButtonPressed.js';
4
+ import { ButtonPressedParams } from './definitions/parameters/ButtonPressedParams.js';
5
+ import { Command } from './definitions/commands/Command.js';
6
+ import { CommandArgDefinition } from './definitions/commands/CommandArgDefinition.js';
7
+ import { CommandArguments } from './definitions/commands/CommandArguments.js';
8
+ import { CommandChoiceDefinition } from './definitions/commands/CommandChoiceDefinition.js';
9
+ import { CommandParameters } from './definitions/commands/CommandParameters.js';
10
+ import { CommandType } from './definitions/commands/CommandType.js';
11
+ import { DatabaseConfigLoader } from './services/DatabaseConfigLoader.js';
12
+ import { DatabaseModel } from './definitions/DatabaseModel.js';
13
+ import { EmojiFallback } from './services/EmojiFallback.js';
14
+ import { FrameworkEvent } from './definitions/FrameworkEvent.js';
15
+ import { FrameworkSettings } from './definitions/FrameworkSettings.js';
16
+ import { Module } from './definitions/Module.js';
17
+ import { SelectMenuParameters } from './definitions/parameters/SelectMenuParameters.js';
18
+ import { TextFormatter } from './services/TextFormatter.js';
19
+ import { Translation } from './definitions/Translation.js';
20
+ import { TranslationManager } from './services/TranslationManager.js';
21
21
  import { ZumitoFramework } from './ZumitoFramework.js';
22
22
  import * as discord from 'discord.js';
23
- import { EventParameters } from './types/EventParameters.js';
23
+ import { EventParameters } from './definitions/parameters/EventParameters.js';
24
24
  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, };
package/dist/index.js CHANGED
@@ -1,16 +1,16 @@
1
- import { ApiResponse } from './definitions/ApiResponse.js';
2
- import { ButtonPressed } from './types/Commands/ButtonPressed.js';
3
- import { Command } from './types/Command.js';
4
- import { CommandArguments } from './types/CommandArguments.js';
5
- import { CommandType } from './types/CommandType.js';
6
- import { DatabaseConfigLoader } from './utils/DatabaseConfigLoader.js';
7
- import { DatabaseModel } from './types/DatabaseModel.js';
8
- import { EmojiFallback } from './utils/EmojiFallback.js';
9
- import { FrameworkEvent } from './types/FrameworkEvent.js';
10
- import { Module } from './types/Module.js';
11
- import { TextFormatter } from './utils/TextFormatter.js';
12
- import { Translation } from './types/Translation.js';
13
- import { TranslationManager } from './TranslationManager.js';
1
+ import { ApiResponse } from './definitions/api/ApiResponse.js';
2
+ import { ButtonPressed } from './definitions/parameters/ButtonPressed.js';
3
+ import { Command } from './definitions/commands/Command.js';
4
+ import { CommandArguments } from './definitions/commands/CommandArguments.js';
5
+ import { CommandType } from './definitions/commands/CommandType.js';
6
+ import { DatabaseConfigLoader } from './services/DatabaseConfigLoader.js';
7
+ import { DatabaseModel } from './definitions/DatabaseModel.js';
8
+ import { EmojiFallback } from './services/EmojiFallback.js';
9
+ import { FrameworkEvent } from './definitions/FrameworkEvent.js';
10
+ import { Module } from './definitions/Module.js';
11
+ import { TextFormatter } from './services/TextFormatter.js';
12
+ import { Translation } from './definitions/Translation.js';
13
+ import { TranslationManager } from './services/TranslationManager.js';
14
14
  import { ZumitoFramework } from './ZumitoFramework.js';
15
15
  import * as discord from 'discord.js';
16
16
  export { ZumitoFramework, Command, Module, CommandArguments, FrameworkEvent, Translation, TranslationManager, ApiResponse, CommandType, ButtonPressed, TextFormatter, EmojiFallback, DatabaseConfigLoader, DatabaseModel, discord, };
@@ -1,6 +1,6 @@
1
- import { Command } from '../../../types/Command.js';
2
- import { EventParameters } from '../../../types/EventParameters.js';
3
- import { FrameworkEvent } from '../../../types/FrameworkEvent.js';
1
+ import { Command } from '../../../../../definitions/commands/Command.js';
2
+ import { EventParameters } from '../../../../../definitions/parameters/EventParameters.js';
3
+ import { FrameworkEvent } from '../../../../../definitions/FrameworkEvent.js';
4
4
  export declare class InteractionCreate extends FrameworkEvent {
5
5
  once: boolean;
6
6
  execute({ interaction, client, framework, }: EventParameters): Promise<void>;
@@ -1,5 +1,5 @@
1
- import { CommandType } from '../../../types/CommandType.js';
2
- import { FrameworkEvent } from '../../../types/FrameworkEvent.js';
1
+ import { CommandType } from '../../../../../definitions/commands/CommandType.js';
2
+ import { FrameworkEvent } from '../../../../../definitions/FrameworkEvent.js';
3
3
  export class InteractionCreate extends FrameworkEvent {
4
4
  once = false;
5
5
  async execute({ interaction, client, framework, }) {
@@ -8,7 +8,7 @@ export class InteractionCreate extends FrameworkEvent {
8
8
  guildSettings = await framework.getGuildSettings(interaction.guildId);
9
9
  }
10
10
  if (interaction.isCommand()) {
11
- if (!framework.commands.has(interaction.commandName))
11
+ if (!framework.commands.getAll().has(interaction.commandName))
12
12
  return;
13
13
  const commandInstance = framework.commands.get(interaction.commandName);
14
14
  const args = new Map();
@@ -37,32 +37,18 @@ export class InteractionCreate extends FrameworkEvent {
37
37
  }
38
38
  }
39
39
  });
40
- if (![
41
- CommandType.any,
42
- CommandType.separated,
43
- CommandType.slash,
44
- ].includes(commandInstance.type))
40
+ if (![CommandType.any, CommandType.separated, CommandType.slash,].includes(commandInstance.type))
45
41
  return;
46
42
  const trans = this.getTransMethod(commandInstance, framework, guildSettings);
47
43
  if (commandInstance.type === CommandType.separated ||
48
44
  commandInstance.type === CommandType.slash) {
49
45
  await commandInstance.executeSlashCommand({
50
- client,
51
- interaction,
52
- args,
53
- framework,
54
- guildSettings,
55
- trans,
46
+ client, interaction, args, framework, guildSettings, trans,
56
47
  });
57
48
  }
58
49
  else {
59
50
  await commandInstance.execute({
60
- client,
61
- interaction,
62
- args,
63
- framework,
64
- guildSettings,
65
- trans,
51
+ client, interaction, args, framework, guildSettings, trans,
66
52
  });
67
53
  }
68
54
  }
@@ -83,7 +69,7 @@ export class InteractionCreate extends FrameworkEvent {
83
69
  });
84
70
  }
85
71
  }
86
- else if (interaction.isSelectMenu()) {
72
+ else if (interaction.isStringSelectMenu()) {
87
73
  const path = interaction.customId.split('.');
88
74
  const commandInstance = framework.commands.get(path[0]);
89
75
  if (!commandInstance)
@@ -107,6 +93,27 @@ export class InteractionCreate extends FrameworkEvent {
107
93
  });
108
94
  }
109
95
  }
96
+ else if (interaction.isModalSubmit()) {
97
+ const path = interaction.customId.split('.');
98
+ const commandInstance = framework.commands.get(path[0]);
99
+ if (!commandInstance) {
100
+ throw new Error(`Command ${path[0]} not found or modal id bad formatted`);
101
+ }
102
+ if (commandInstance.modalSubmit) {
103
+ commandInstance.modalSubmit({
104
+ path,
105
+ interaction,
106
+ client,
107
+ framework,
108
+ guildSettings,
109
+ });
110
+ }
111
+ else {
112
+ framework.eventManager.emitEvent('modalSubmit', 'framework', {
113
+ path, interaction, client, framework, guildSettings,
114
+ });
115
+ }
116
+ }
110
117
  }
111
118
  getTransMethod(commandInstance, framework, guildSettings) {
112
119
  return (key, params) => {