@stelliajs/framework 1.5.3 → 1.5.6

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/README.md CHANGED
@@ -11,7 +11,6 @@ Recommended architecture for StelliaJS project.
11
11
 
12
12
  ```
13
13
  .
14
- ├── dist // Build folder
15
14
  ├── src/
16
15
  │ ├── commands/
17
16
  │ │ ├── contextMenus/
@@ -41,7 +40,7 @@ Recommended architecture for StelliaJS project.
41
40
  │ └── index.ts
42
41
  ├── .env
43
42
  ├── package.json
44
- ├── package-lock.json
43
+ ├── pnpm-lock.yaml
45
44
  ├── stellia.json
46
45
  └── tsconfig.json
47
46
  ```
@@ -2,20 +2,23 @@ import { Client, type ClientOptions, type Interaction } from "discord.js";
2
2
  import { type ManagerOptions } from "../managers/index.js";
3
3
  import { type ClientEnvironment, type GuildConfiguration, type GuildsConfiguration, type Managers } from "../typescript/index.js";
4
4
  export declare class StelliaClient<Ready extends boolean = boolean> extends Client<Ready> {
5
- private readonly utils;
5
+ private utils;
6
6
  readonly managers: Managers;
7
- readonly environment: ClientEnvironment;
8
- constructor(clientOptions: ClientOptions, stelliaOptions?: StelliaOptions);
7
+ readonly environment?: ClientEnvironment;
8
+ private constructor();
9
+ static create(clientOptions: ClientOptions, stelliaOptions?: StelliaOptions): Promise<StelliaClient>;
9
10
  connect: (token: string) => Promise<void>;
10
11
  initializeCommands: () => Promise<void>;
11
12
  getGuildsConfiguration: <CustomGuildsConfiguration extends GuildsConfiguration>() => Promise<CustomGuildsConfiguration>;
12
13
  getGuildConfiguration: <CustomGuildConfiguration extends GuildConfiguration>(guildId: string) => CustomGuildConfiguration | undefined;
13
14
  handleInteraction: (interaction: Interaction<"cached">) => Promise<void>;
14
- private areManagersLoaded;
15
- private static convertFilePathToProduction;
15
+ private initializeAsyncFields;
16
+ private initializeManagers;
17
+ private readonly areManagersLoaded;
18
+ private static readonly convertFilePathToProduction;
16
19
  }
17
20
  interface StelliaOptions {
18
- managers: {
21
+ managers?: {
19
22
  autoCompletes?: ManagerOptions;
20
23
  buttons?: ManagerOptions;
21
24
  commands?: ManagerOptions;
@@ -1,6 +1,6 @@
1
- import * as fs from "node:fs";
2
- import path from "path";
3
- import { pathToFileURL } from "url";
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
4
  import { Client } from "discord.js";
5
5
  import { StelliaUtils } from "./index.js";
6
6
  import { AutoCompleteManager, ButtonManager, CommandManager, ContextMenuManager, EventManager, ModalManager, SelectMenuManager } from "../managers/index.js";
@@ -14,28 +14,6 @@ export class StelliaClient extends Client {
14
14
  if (stelliaOptions?.environment) {
15
15
  this.environment = stelliaOptions.environment;
16
16
  }
17
- if (stelliaOptions?.managers.autoCompletes?.directoryPath) {
18
- this.managers.autoCompletes = new AutoCompleteManager(this, stelliaOptions.managers.autoCompletes.directoryPath);
19
- }
20
- if (stelliaOptions?.managers.buttons?.directoryPath) {
21
- this.managers.buttons = new ButtonManager(this, stelliaOptions.managers.buttons.directoryPath);
22
- }
23
- if (stelliaOptions?.managers.commands?.directoryPath) {
24
- this.managers.commands = new CommandManager(this, stelliaOptions.managers.commands.directoryPath);
25
- }
26
- if (stelliaOptions?.managers.contextMenus?.directoryPath) {
27
- this.managers.contextMenus = new ContextMenuManager(this, stelliaOptions.managers.contextMenus.directoryPath);
28
- }
29
- if (stelliaOptions?.managers.events?.directoryPath) {
30
- this.managers.events = new EventManager(this, stelliaOptions.managers.events.directoryPath);
31
- }
32
- if (stelliaOptions?.managers.selectMenus?.directoryPath) {
33
- this.managers.selectMenus = new SelectMenuManager(this, stelliaOptions.managers.selectMenus.directoryPath);
34
- }
35
- if (stelliaOptions?.managers.modals?.directoryPath) {
36
- this.managers.modals = new ModalManager(this, stelliaOptions.managers.modals.directoryPath);
37
- }
38
- this.utils = new StelliaUtils(this);
39
17
  process.on("unhandledRejection", (error) => {
40
18
  logger.error(`Unhandled promise rejection: ${error.stack}`);
41
19
  });
@@ -43,6 +21,11 @@ export class StelliaClient extends Client {
43
21
  logger.error(`Uncaught exception: ${error.stack}`);
44
22
  });
45
23
  }
24
+ static async create(clientOptions, stelliaOptions) {
25
+ const client = new StelliaClient(clientOptions, stelliaOptions);
26
+ await client.initializeAsyncFields(stelliaOptions);
27
+ return client;
28
+ }
46
29
  connect = async (token) => {
47
30
  if (!this.areManagersLoaded()) {
48
31
  setTimeout(() => {
@@ -67,24 +50,20 @@ export class StelliaClient extends Client {
67
50
  return new Promise((resolve, reject) => {
68
51
  fs.readFile(filePath, async (err, data) => {
69
52
  if (err) {
70
- return reject(err);
53
+ return reject(new Error("stellia.json file not found"));
71
54
  }
72
- try {
73
- const environments = JSON.parse(data.toString()).environments;
74
- if (!Object.keys(environments).includes(chosenEnvironment)) {
75
- return reject(new Error("Invalid environment"));
76
- }
77
- const environmentData = environments[chosenEnvironment];
78
- const environmentPath = environmentData.production
79
- ? StelliaClient.convertFilePathToProduction(environmentData.file)
80
- : environmentData.file;
81
- const environmentAbsolutePath = pathToFileURL(path.join(srcPath, "..", environmentPath)).href;
82
- const environmentFile = await import(environmentAbsolutePath);
83
- resolve(environmentFile.environment);
84
- }
85
- catch (error) {
86
- reject(error);
55
+ const environments = JSON.parse(data.toString()).environments;
56
+ if (!Object.keys(environments).includes(chosenEnvironment)) {
57
+ return reject(new Error("Invalid environment"));
87
58
  }
59
+ const environmentData = environments[chosenEnvironment];
60
+ const environmentPath = environmentData.production
61
+ ? StelliaClient.convertFilePathToProduction(environmentData.file)
62
+ : environmentData.file;
63
+ const environmentAbsolutePath = pathToFileURL(path.join(srcPath, "..", environmentPath)).href;
64
+ import(environmentAbsolutePath)
65
+ .then((environmentFile) => resolve(environmentFile.environment))
66
+ .catch(() => reject(new Error("Error parsing stellia.json file")));
88
67
  });
89
68
  });
90
69
  };
@@ -94,6 +73,38 @@ export class StelliaClient extends Client {
94
73
  handleInteraction = async (interaction) => {
95
74
  await this.utils.handleInteraction(interaction);
96
75
  };
76
+ async initializeAsyncFields(stelliaOptions) {
77
+ this.utils = await StelliaUtils.create(this);
78
+ await this.initializeManagers(stelliaOptions?.managers);
79
+ }
80
+ ;
81
+ async initializeManagers(managers) {
82
+ if (!managers) {
83
+ return;
84
+ }
85
+ if (managers.autoCompletes?.directoryPath) {
86
+ this.managers.autoCompletes = await AutoCompleteManager.create(this, managers.autoCompletes.directoryPath);
87
+ }
88
+ if (managers.buttons?.directoryPath) {
89
+ this.managers.buttons = await ButtonManager.create(this, managers.buttons.directoryPath);
90
+ }
91
+ if (managers.commands?.directoryPath) {
92
+ this.managers.commands = await CommandManager.create(this, managers.commands.directoryPath);
93
+ }
94
+ if (managers.contextMenus?.directoryPath) {
95
+ this.managers.contextMenus = await ContextMenuManager.create(this, managers.contextMenus.directoryPath);
96
+ }
97
+ if (managers.events?.directoryPath) {
98
+ this.managers.events = await EventManager.create(this, managers.events.directoryPath);
99
+ }
100
+ if (managers.selectMenus?.directoryPath) {
101
+ this.managers.selectMenus = await SelectMenuManager.create(this, managers.selectMenus.directoryPath);
102
+ }
103
+ if (managers.modals?.directoryPath) {
104
+ this.managers.modals = await ModalManager.create(this, managers.modals.directoryPath);
105
+ }
106
+ }
107
+ ;
97
108
  areManagersLoaded = () => {
98
109
  const managers = Object.values(this.managers);
99
110
  return managers.length === 0
@@ -5,17 +5,19 @@ export declare class StelliaUtils {
5
5
  readonly client: StelliaClient;
6
6
  private readonly interactionHandlers;
7
7
  private guildsConfiguration;
8
- constructor(client: StelliaClient);
8
+ private constructor();
9
+ static create(client: StelliaClient): Promise<StelliaUtils>;
9
10
  initializeCommands: () => Promise<void>;
10
11
  getGuildConfiguration: <CustomGuildConfiguration extends GuildConfiguration>(guildId: string) => CustomGuildConfiguration | undefined;
11
12
  handleInteraction: (interaction: Interaction<"cached">) => Promise<void>;
12
- private handleAutoCompleteInteraction;
13
- private handleButtonInteraction;
14
- private handleCommandInteraction;
15
- private handleContextMenuInteraction;
16
- private handleModalInteraction;
17
- private handleSelectMenuInteraction;
18
- private handleMessageContextMenuInteraction;
19
- private handleUserContextMenuInteraction;
13
+ private initializeGuildsConfiguration;
14
+ private readonly handleAutoCompleteInteraction;
15
+ private readonly handleButtonInteraction;
16
+ private readonly handleCommandInteraction;
17
+ private readonly handleContextMenuInteraction;
18
+ private readonly handleModalInteraction;
19
+ private readonly handleSelectMenuInteraction;
20
+ private readonly handleMessageContextMenuInteraction;
21
+ private readonly handleUserContextMenuInteraction;
20
22
  private getInteractionType;
21
23
  }
@@ -16,16 +16,14 @@ export class StelliaUtils {
16
16
  [InteractionType.ModalSubmit, this.handleModalInteraction],
17
17
  [InteractionType.SelectMenu, this.handleSelectMenuInteraction]
18
18
  ]);
19
- if (this.client.environment.areGuildsConfigurationEnabled) {
20
- this.client
21
- .getGuildsConfiguration()
22
- .then((guildsConfiguration) => {
23
- this.guildsConfiguration = guildsConfiguration;
24
- logger.success("Guilds configuration loaded successfully for interactions");
25
- })
26
- .catch((error) => logger.error(`Error while loading guilds configuration: ${error.stack}`));
27
- }
28
19
  }
20
+ ;
21
+ static async create(client) {
22
+ const utils = new StelliaUtils(client);
23
+ await utils.initializeGuildsConfiguration();
24
+ return utils;
25
+ }
26
+ ;
29
27
  initializeCommands = async () => {
30
28
  const commands = this.client.managers.commands?.getAll().values();
31
29
  const contextMenus = this.client.managers.contextMenus?.getAll().values();
@@ -44,7 +42,7 @@ export class StelliaUtils {
44
42
  }
45
43
  };
46
44
  getGuildConfiguration = (guildId) => {
47
- if (!this.client.environment.areGuildsConfigurationEnabled || !this.guildsConfiguration) {
45
+ if (!this.client.environment?.areGuildsConfigurationEnabled || !this.guildsConfiguration) {
48
46
  return undefined;
49
47
  }
50
48
  const { guilds, general } = this.guildsConfiguration;
@@ -66,6 +64,19 @@ export class StelliaUtils {
66
64
  }
67
65
  }
68
66
  };
67
+ async initializeGuildsConfiguration() {
68
+ if (this.client.environment?.areGuildsConfigurationEnabled) {
69
+ try {
70
+ const guildsConfiguration = await this.client.getGuildsConfiguration();
71
+ this.guildsConfiguration = guildsConfiguration;
72
+ logger.success("Guilds configuration loaded successfully for interactions");
73
+ }
74
+ catch (error) {
75
+ logger.error(`Error while loading guilds configuration: ${error.stack}`);
76
+ }
77
+ }
78
+ }
79
+ ;
69
80
  handleAutoCompleteInteraction = async (interaction) => {
70
81
  try {
71
82
  const autoCompleteInteraction = interaction;
@@ -75,7 +86,7 @@ export class StelliaUtils {
75
86
  const autoComplete = autoCompleteManager.getByCustomId(autoCompleteInteraction.commandName);
76
87
  if (!autoComplete)
77
88
  return;
78
- if (this.client.environment.areGuildsConfigurationEnabled) {
89
+ if (this.client.environment?.areGuildsConfigurationEnabled) {
79
90
  const autoCompleteWithGuildConfiguration = autoComplete;
80
91
  const guildConfiguration = this.getGuildConfiguration(autoCompleteInteraction.guildId);
81
92
  await autoCompleteWithGuildConfiguration.execute(this.client, guildConfiguration, autoCompleteInteraction);
@@ -102,7 +113,7 @@ export class StelliaUtils {
102
113
  if (button.data.reply.autoDefer && !buttonInteraction.deferred) {
103
114
  await buttonInteraction.deferReply({ flags: button.data.reply.ephemeral ? MessageFlags.Ephemeral : undefined });
104
115
  }
105
- if (this.client.environment.areGuildsConfigurationEnabled) {
116
+ if (this.client.environment?.areGuildsConfigurationEnabled) {
106
117
  const buttonWithGuildConfiguration = button;
107
118
  const guildConfiguration = this.getGuildConfiguration(buttonInteraction.guildId);
108
119
  await buttonWithGuildConfiguration.execute(this.client, guildConfiguration, buttonInteraction);
@@ -128,7 +139,7 @@ export class StelliaUtils {
128
139
  if (command.data.reply.autoDefer && !commandInteraction.deferred) {
129
140
  await commandInteraction.deferReply({ flags: command.data.reply.ephemeral ? MessageFlags.Ephemeral : undefined });
130
141
  }
131
- if (this.client.environment.areGuildsConfigurationEnabled) {
142
+ if (this.client.environment?.areGuildsConfigurationEnabled) {
132
143
  const commandWithGuildConfiguration = command;
133
144
  const guildConfiguration = this.getGuildConfiguration(commandInteraction.guildId);
134
145
  await commandWithGuildConfiguration.execute(this.client, guildConfiguration, commandInteraction);
@@ -171,7 +182,7 @@ export class StelliaUtils {
171
182
  if (modal.data.reply.autoDefer && !modalInteraction.deferred) {
172
183
  await modalInteraction.deferReply({ flags: modal.data.reply.ephemeral ? MessageFlags.Ephemeral : undefined });
173
184
  }
174
- if (this.client.environment.areGuildsConfigurationEnabled) {
185
+ if (this.client.environment?.areGuildsConfigurationEnabled) {
175
186
  const modalWithGuildConfiguration = modal;
176
187
  const guildConfiguration = this.getGuildConfiguration(modalInteraction.guildId);
177
188
  await modalWithGuildConfiguration.execute(this.client, guildConfiguration, modalInteraction);
@@ -198,7 +209,7 @@ export class StelliaUtils {
198
209
  if (selectMenu.data.reply.autoDefer && !selectMenuInteraction.deferred) {
199
210
  await selectMenuInteraction.deferReply({ flags: selectMenu.data.reply.ephemeral ? MessageFlags.Ephemeral : undefined });
200
211
  }
201
- if (this.client.environment.areGuildsConfigurationEnabled) {
212
+ if (this.client.environment?.areGuildsConfigurationEnabled) {
202
213
  const selectMenuWithGuildConfiguration = selectMenu;
203
214
  const guildConfiguration = this.getGuildConfiguration(selectMenuInteraction.guildId);
204
215
  await selectMenuWithGuildConfiguration.execute(this.client, guildConfiguration, selectMenuInteraction);
@@ -223,7 +234,7 @@ export class StelliaUtils {
223
234
  if (messageContextMenu.data.reply.autoDefer && !interaction.deferred) {
224
235
  await interaction.deferReply({ flags: messageContextMenu.data.reply.ephemeral ? MessageFlags.Ephemeral : undefined });
225
236
  }
226
- if (this.client.environment.areGuildsConfigurationEnabled) {
237
+ if (this.client.environment?.areGuildsConfigurationEnabled) {
227
238
  const messageContextMenuWithGuildConfiguration = messageContextMenu;
228
239
  const guildConfiguration = this.getGuildConfiguration(interaction.guildId);
229
240
  await messageContextMenuWithGuildConfiguration.execute(this.client, guildConfiguration, interaction);
@@ -248,7 +259,7 @@ export class StelliaUtils {
248
259
  if (userContextMenu.data.reply.autoDefer && !interaction.deferred) {
249
260
  await interaction.deferReply({ flags: userContextMenu.data.reply.ephemeral ? MessageFlags.Ephemeral : undefined });
250
261
  }
251
- if (this.client.environment.areGuildsConfigurationEnabled) {
262
+ if (this.client.environment?.areGuildsConfigurationEnabled) {
252
263
  const userContextMenuWithGuildConfiguration = userContextMenu;
253
264
  const guildConfiguration = this.getGuildConfiguration(interaction.guildId);
254
265
  await userContextMenuWithGuildConfiguration.execute(this.client, guildConfiguration, interaction);
@@ -4,9 +4,10 @@ import { BaseManager } from "./index.js";
4
4
  import { type InteractionCustomId, type StructureCustomId } from "../typescript/index.js";
5
5
  export declare class AutoCompleteManager extends BaseManager {
6
6
  private interactions;
7
- constructor(client: StelliaClient, directory: string);
7
+ private constructor();
8
+ static create(client: StelliaClient, directory: string): Promise<AutoCompleteManager>;
8
9
  loadData(): Promise<void>;
9
- getByCustomId<AutoCompleteStructure>(id: InteractionCustomId): AutoCompleteStructure | undefined;
10
- getByRegex<AutoCompleteStructure>(id: InteractionCustomId): AutoCompleteStructure | undefined;
10
+ getByCustomId<AutoCompleteStructure>(id: InteractionCustomId): AutoCompleteStructure | null;
11
+ getByRegex<AutoCompleteStructure>(id: InteractionCustomId): AutoCompleteStructure | null;
11
12
  getAll<AutoCompleteStructure>(): Collection<StructureCustomId, AutoCompleteStructure>;
12
13
  }
@@ -3,8 +3,13 @@ import { BaseManager } from "./index.js";
3
3
  import { requiredFiles } from "../utils/index.js";
4
4
  export class AutoCompleteManager extends BaseManager {
5
5
  interactions = new Collection();
6
- constructor(client, directory) {
7
- super(client, directory);
6
+ constructor(client, directoryPath) {
7
+ super(client, directoryPath);
8
+ }
9
+ static async create(client, directory) {
10
+ const manager = new AutoCompleteManager(client, directory);
11
+ await manager.loadData();
12
+ return manager;
8
13
  }
9
14
  async loadData() {
10
15
  const autoCompletes = await requiredFiles(this.directoryPath);
@@ -12,11 +17,18 @@ export class AutoCompleteManager extends BaseManager {
12
17
  this.setManagerLoaded();
13
18
  }
14
19
  getByCustomId(id) {
15
- const autoComplete = this.interactions.get(id) ?? undefined;
20
+ const autoComplete = this.interactions.get(id) ?? null;
16
21
  return autoComplete;
17
22
  }
18
23
  getByRegex(id) {
19
- return undefined;
24
+ let autoComplete = null;
25
+ for (const [customId, action] of this.interactions.entries()) {
26
+ if (customId instanceof RegExp && customId.test(id)) {
27
+ autoComplete = action;
28
+ break;
29
+ }
30
+ }
31
+ return autoComplete;
20
32
  }
21
33
  getAll() {
22
34
  const autoCompletes = this.interactions;
@@ -9,11 +9,11 @@ export declare abstract class BaseManager {
9
9
  readonly client: StelliaClient;
10
10
  readonly directoryPath: string;
11
11
  private isLoaded;
12
- constructor(client: StelliaClient, directory: string);
12
+ protected constructor(client: StelliaClient, directory: string);
13
13
  isManagerLoaded(): boolean;
14
14
  setManagerLoaded(): void;
15
- abstract loadData(): void;
16
- abstract getByCustomId<InteractionStructure extends AnyInteractionStructure>(id: InteractionCustomId): InteractionStructure | undefined;
17
- abstract getByRegex<InteractionStructure extends AnyInteractionStructure>(id: InteractionCustomId): InteractionStructure | undefined;
15
+ abstract loadData(): Promise<void>;
16
+ abstract getByCustomId<InteractionStructure extends AnyInteractionStructure>(id: InteractionCustomId): InteractionStructure | null;
17
+ abstract getByRegex<InteractionStructure extends AnyInteractionStructure>(id: InteractionCustomId): InteractionStructure | null;
18
18
  abstract getAll<InteractionStructure extends AnyInteractionStructure>(): Collection<StructureCustomId, InteractionStructure>;
19
19
  }
@@ -5,7 +5,6 @@ export class BaseManager {
5
5
  constructor(client, directory) {
6
6
  this.client = client;
7
7
  this.directoryPath = directory;
8
- this.loadData();
9
8
  }
10
9
  isManagerLoaded() {
11
10
  return this.isLoaded;
@@ -5,9 +5,10 @@ import { type ButtonStructure } from "../structures/index.js";
5
5
  import { type InteractionCustomId, type StructureCustomId } from "../typescript/index.js";
6
6
  export declare class ButtonManager extends BaseManager {
7
7
  interactions: Collection<StructureCustomId, ButtonStructure>;
8
- constructor(client: StelliaClient, directory: string);
8
+ private constructor();
9
+ static create(client: StelliaClient, directory: string): Promise<ButtonManager>;
9
10
  loadData(): Promise<void>;
10
- getByCustomId<ButtonStructure>(id: InteractionCustomId): ButtonStructure | undefined;
11
- getByRegex<ButtonStructure>(id: InteractionCustomId): ButtonStructure | undefined;
11
+ getByCustomId<ButtonStructure>(id: InteractionCustomId): ButtonStructure | null;
12
+ getByRegex<ButtonStructure>(id: InteractionCustomId): ButtonStructure | null;
12
13
  getAll<ButtonStructure>(): Collection<StructureCustomId, ButtonStructure>;
13
14
  }
@@ -3,8 +3,13 @@ import { BaseManager } from "./index.js";
3
3
  import { requiredFiles } from "../utils/index.js";
4
4
  export class ButtonManager extends BaseManager {
5
5
  interactions = new Collection();
6
- constructor(client, directory) {
7
- super(client, directory);
6
+ constructor(client, directoryPath) {
7
+ super(client, directoryPath);
8
+ }
9
+ static async create(client, directory) {
10
+ const manager = new ButtonManager(client, directory);
11
+ await manager.loadData();
12
+ return manager;
8
13
  }
9
14
  async loadData() {
10
15
  const buttons = await requiredFiles(this.directoryPath);
@@ -12,11 +17,11 @@ export class ButtonManager extends BaseManager {
12
17
  this.setManagerLoaded();
13
18
  }
14
19
  getByCustomId(id) {
15
- const button = this.interactions.get(id) ?? undefined;
20
+ const button = this.interactions.get(id) ?? null;
16
21
  return button;
17
22
  }
18
23
  getByRegex(id) {
19
- let button;
24
+ let button = null;
20
25
  for (const [customId, action] of this.interactions.entries()) {
21
26
  if (customId instanceof RegExp && customId.test(id)) {
22
27
  button = action;
@@ -4,9 +4,10 @@ import { BaseManager } from "./index.js";
4
4
  import { type InteractionCustomId, type StructureCustomId } from "../typescript/index.js";
5
5
  export declare class CommandManager extends BaseManager {
6
6
  private interactions;
7
- constructor(client: StelliaClient, directory: string);
7
+ private constructor();
8
+ static create(client: StelliaClient, directory: string): Promise<CommandManager>;
8
9
  loadData(): Promise<void>;
9
- getByCustomId<CommandStructure>(id: InteractionCustomId): CommandStructure | undefined;
10
- getByRegex<CommandStructure>(id: InteractionCustomId): CommandStructure | undefined;
10
+ getByCustomId<CommandStructure>(id: InteractionCustomId): CommandStructure | null;
11
+ getByRegex<CommandStructure>(id: InteractionCustomId): CommandStructure | null;
11
12
  getAll<CommandStructure>(): Collection<StructureCustomId, CommandStructure>;
12
13
  }
@@ -3,8 +3,13 @@ import { BaseManager } from "./index.js";
3
3
  import { requiredFiles } from "../utils/index.js";
4
4
  export class CommandManager extends BaseManager {
5
5
  interactions = new Collection();
6
- constructor(client, directory) {
7
- super(client, directory);
6
+ constructor(client, directoryPath) {
7
+ super(client, directoryPath);
8
+ }
9
+ static async create(client, directory) {
10
+ const manager = new CommandManager(client, directory);
11
+ await manager.loadData();
12
+ return manager;
8
13
  }
9
14
  async loadData() {
10
15
  const commands = await requiredFiles(this.directoryPath);
@@ -12,11 +17,18 @@ export class CommandManager extends BaseManager {
12
17
  this.setManagerLoaded();
13
18
  }
14
19
  getByCustomId(id) {
15
- const command = this.interactions.get(id) ?? undefined;
20
+ const command = this.interactions.get(id) ?? null;
16
21
  return command;
17
22
  }
18
23
  getByRegex(id) {
19
- return undefined;
24
+ let command = null;
25
+ for (const [customId, action] of this.interactions.entries()) {
26
+ if (customId instanceof RegExp && customId.test(id)) {
27
+ command = action;
28
+ break;
29
+ }
30
+ }
31
+ return command;
20
32
  }
21
33
  getAll() {
22
34
  const commands = this.interactions;
@@ -4,9 +4,10 @@ import { BaseManager } from "./index.js";
4
4
  import { type InteractionCustomId, type StructureCustomId } from "../typescript/index.js";
5
5
  export declare class ContextMenuManager extends BaseManager {
6
6
  private interactions;
7
- constructor(client: StelliaClient, directory: string);
7
+ private constructor();
8
+ static create(client: StelliaClient, directory: string): Promise<ContextMenuManager>;
8
9
  loadData(): Promise<void>;
9
- getByCustomId<ContextMenuStructure>(id: InteractionCustomId): ContextMenuStructure | undefined;
10
- getByRegex<ContextMenuStructure>(id: InteractionCustomId): ContextMenuStructure | undefined;
10
+ getByCustomId<ContextMenuStructure>(id: InteractionCustomId): ContextMenuStructure | null;
11
+ getByRegex<ContextMenuStructure>(id: InteractionCustomId): ContextMenuStructure | null;
11
12
  getAll<ContextMenuStructure>(): Collection<StructureCustomId, ContextMenuStructure>;
12
13
  }
@@ -3,8 +3,13 @@ import { BaseManager } from "./index.js";
3
3
  import { requiredFiles } from "../utils/index.js";
4
4
  export class ContextMenuManager extends BaseManager {
5
5
  interactions = new Collection();
6
- constructor(client, directory) {
7
- super(client, directory);
6
+ constructor(client, directoryPath) {
7
+ super(client, directoryPath);
8
+ }
9
+ static async create(client, directory) {
10
+ const manager = new ContextMenuManager(client, directory);
11
+ await manager.loadData();
12
+ return manager;
8
13
  }
9
14
  async loadData() {
10
15
  const contextMenus = await requiredFiles(this.directoryPath);
@@ -12,11 +17,18 @@ export class ContextMenuManager extends BaseManager {
12
17
  this.setManagerLoaded();
13
18
  }
14
19
  getByCustomId(id) {
15
- const contextMenu = this.interactions.get(id) ?? undefined;
20
+ const contextMenu = this.interactions.get(id) ?? null;
16
21
  return contextMenu;
17
22
  }
18
23
  getByRegex(id) {
19
- return undefined;
24
+ let contextMenu = null;
25
+ for (const [customId, action] of this.interactions.entries()) {
26
+ if (customId instanceof RegExp && customId.test(id)) {
27
+ contextMenu = action;
28
+ break;
29
+ }
30
+ }
31
+ return contextMenu;
20
32
  }
21
33
  getAll() {
22
34
  const contextMenus = this.interactions;
@@ -5,13 +5,15 @@ import { type InteractionCustomId, type StructureCustomId } from "../typescript/
5
5
  export declare class EventManager extends BaseManager {
6
6
  private interactions;
7
7
  private guildsConfiguration;
8
- constructor(client: StelliaClient, directoryPath: string);
8
+ private constructor();
9
+ static create(client: StelliaClient, directoryPath: string): Promise<EventManager>;
9
10
  loadData(): Promise<void>;
10
- getByCustomId<EventStructure>(id: InteractionCustomId): EventStructure | undefined;
11
- getByRegex<EventStructure>(id: InteractionCustomId): EventStructure | undefined;
11
+ getByCustomId<EventStructure>(id: InteractionCustomId): EventStructure | null;
12
+ getByRegex<EventStructure>(id: InteractionCustomId): EventStructure | null;
12
13
  getAll<EventStructure>(): Collection<StructureCustomId, EventStructure>;
13
14
  private loadEventWithGuildConfiguration;
14
- private eventHandler;
15
+ private readonly eventHandler;
15
16
  private loadEventWithoutGuildConfiguration;
16
17
  private getGuildConfiguration;
18
+ private initializeGuildsConfiguration;
17
19
  }
@@ -7,21 +7,19 @@ export class EventManager extends BaseManager {
7
7
  guildsConfiguration;
8
8
  constructor(client, directoryPath) {
9
9
  super(client, directoryPath);
10
- if (this.client.environment.areGuildsConfigurationEnabled) {
11
- this.client
12
- .getGuildsConfiguration()
13
- .then((guildsConfiguration) => {
14
- this.guildsConfiguration = guildsConfiguration;
15
- logger.success("Guilds configuration loaded successfully for event");
16
- })
17
- .catch((error) => logger.error(`Error while loading guilds configuration: ${error.stack}`));
18
- }
19
10
  }
11
+ static async create(client, directoryPath) {
12
+ const manager = new EventManager(client, directoryPath);
13
+ await manager.loadData();
14
+ await manager.initializeGuildsConfiguration();
15
+ return manager;
16
+ }
17
+ ;
20
18
  async loadData() {
21
19
  const events = await requiredFiles(this.directoryPath);
22
20
  this.interactions = events;
23
21
  for (const eventStructure of this.interactions.values()) {
24
- if (this.client.environment.areGuildsConfigurationEnabled) {
22
+ if (this.client.environment?.areGuildsConfigurationEnabled) {
25
23
  await this.loadEventWithGuildConfiguration(eventStructure);
26
24
  }
27
25
  else {
@@ -31,11 +29,18 @@ export class EventManager extends BaseManager {
31
29
  this.setManagerLoaded();
32
30
  }
33
31
  getByCustomId(id) {
34
- const event = this.interactions.get(id) ?? undefined;
32
+ const event = this.interactions.get(id) ?? null;
35
33
  return event;
36
34
  }
37
35
  getByRegex(id) {
38
- return undefined;
36
+ let event = null;
37
+ for (const [customId, action] of this.interactions.entries()) {
38
+ if (customId instanceof RegExp && customId.test(id)) {
39
+ event = action;
40
+ break;
41
+ }
42
+ }
43
+ return event;
39
44
  }
40
45
  getAll() {
41
46
  const events = this.interactions;
@@ -51,6 +56,7 @@ export class EventManager extends BaseManager {
51
56
  this.client.on(name, (...args) => this.eventHandler(event, ...args));
52
57
  }
53
58
  }
59
+ ;
54
60
  eventHandler = (event, ...args) => {
55
61
  const mainArgument = args[0];
56
62
  const guildConfiguration = this.getGuildConfiguration(mainArgument);
@@ -71,6 +77,7 @@ export class EventManager extends BaseManager {
71
77
  this.client.on(name, (...args) => event.execute(this.client, ...args));
72
78
  }
73
79
  }
80
+ ;
74
81
  getGuildConfiguration(mainArgument) {
75
82
  if (mainArgument && typeof mainArgument === "object") {
76
83
  if ("guildId" in mainArgument && mainArgument.guildId) {
@@ -82,4 +89,18 @@ export class EventManager extends BaseManager {
82
89
  }
83
90
  return undefined;
84
91
  }
92
+ ;
93
+ async initializeGuildsConfiguration() {
94
+ if (this.client.environment?.areGuildsConfigurationEnabled) {
95
+ try {
96
+ const guildsConfiguration = await this.client.getGuildsConfiguration();
97
+ this.guildsConfiguration = guildsConfiguration;
98
+ logger.success("Guilds configuration loaded successfully for events");
99
+ }
100
+ catch (error) {
101
+ logger.error(`Error while loading guilds configuration: ${error.stack}`);
102
+ }
103
+ }
104
+ }
105
+ ;
85
106
  }
@@ -4,9 +4,10 @@ import { BaseManager } from "./index.js";
4
4
  import { type InteractionCustomId, type StructureCustomId } from "../typescript/index.js";
5
5
  export declare class ModalManager extends BaseManager {
6
6
  private interactions;
7
- constructor(client: StelliaClient, directory: string);
7
+ private constructor();
8
+ static create(client: StelliaClient, directory: string): Promise<ModalManager>;
8
9
  loadData(): Promise<void>;
9
- getByCustomId<ModalStructure>(id: InteractionCustomId): ModalStructure | undefined;
10
- getByRegex<ModalStructure>(id: InteractionCustomId): ModalStructure | undefined;
10
+ getByCustomId<ModalStructure>(id: InteractionCustomId): ModalStructure | null;
11
+ getByRegex<ModalStructure>(id: InteractionCustomId): ModalStructure | null;
11
12
  getAll<ModalStructure>(): Collection<StructureCustomId, ModalStructure>;
12
13
  }
@@ -3,8 +3,13 @@ import { BaseManager } from "./index.js";
3
3
  import { requiredFiles } from "../utils/index.js";
4
4
  export class ModalManager extends BaseManager {
5
5
  interactions = new Collection();
6
- constructor(client, directory) {
7
- super(client, directory);
6
+ constructor(client, directoryPath) {
7
+ super(client, directoryPath);
8
+ }
9
+ static async create(client, directory) {
10
+ const manager = new ModalManager(client, directory);
11
+ await manager.loadData();
12
+ return manager;
8
13
  }
9
14
  async loadData() {
10
15
  const modals = await requiredFiles(this.directoryPath);
@@ -12,11 +17,11 @@ export class ModalManager extends BaseManager {
12
17
  this.setManagerLoaded();
13
18
  }
14
19
  getByCustomId(id) {
15
- const modal = this.interactions.get(id) ?? undefined;
20
+ const modal = this.interactions.get(id) ?? null;
16
21
  return modal;
17
22
  }
18
23
  getByRegex(id) {
19
- let modal;
24
+ let modal = null;
20
25
  for (const [customId, action] of this.interactions.entries()) {
21
26
  if (customId instanceof RegExp && customId.test(id)) {
22
27
  modal = action;
@@ -4,9 +4,10 @@ import { BaseManager } from "./index.js";
4
4
  import { type InteractionCustomId, type StructureCustomId } from "../typescript/index.js";
5
5
  export declare class SelectMenuManager extends BaseManager {
6
6
  private interactions;
7
- constructor(client: StelliaClient, directory: string);
7
+ private constructor();
8
+ static create(client: StelliaClient, directory: string): Promise<SelectMenuManager>;
8
9
  loadData(): Promise<void>;
9
- getByCustomId<SelectMenuStructure>(id: InteractionCustomId): SelectMenuStructure | undefined;
10
- getByRegex<SelectMenuStructure>(id: InteractionCustomId): SelectMenuStructure | undefined;
10
+ getByCustomId<SelectMenuStructure>(id: InteractionCustomId): SelectMenuStructure | null;
11
+ getByRegex<SelectMenuStructure>(id: InteractionCustomId): SelectMenuStructure | null;
11
12
  getAll<SelectMenuStructure>(): Collection<StructureCustomId, SelectMenuStructure>;
12
13
  }
@@ -3,8 +3,13 @@ import { BaseManager } from "./index.js";
3
3
  import { requiredFiles } from "../utils/index.js";
4
4
  export class SelectMenuManager extends BaseManager {
5
5
  interactions = new Collection();
6
- constructor(client, directory) {
7
- super(client, directory);
6
+ constructor(client, directoryPath) {
7
+ super(client, directoryPath);
8
+ }
9
+ static async create(client, directory) {
10
+ const manager = new SelectMenuManager(client, directory);
11
+ await manager.loadData();
12
+ return manager;
8
13
  }
9
14
  async loadData() {
10
15
  const selectMenus = await requiredFiles(this.directoryPath);
@@ -12,18 +17,18 @@ export class SelectMenuManager extends BaseManager {
12
17
  this.setManagerLoaded();
13
18
  }
14
19
  getByCustomId(id) {
15
- const selectMenu = this.interactions.get(id) ?? undefined;
20
+ const selectMenu = this.interactions.get(id) ?? null;
16
21
  return selectMenu;
17
22
  }
18
23
  getByRegex(id) {
19
- let button;
24
+ let selectMenu = null;
20
25
  for (const [customId, action] of this.interactions.entries()) {
21
26
  if (customId instanceof RegExp && customId.test(id)) {
22
- button = action;
27
+ selectMenu = action;
23
28
  break;
24
29
  }
25
30
  }
26
- return button;
31
+ return selectMenu;
27
32
  }
28
33
  getAll() {
29
34
  const selectMenus = this.interactions;
@@ -1,5 +1,5 @@
1
- import { readdirSync, statSync } from "fs";
2
- import path from "path";
1
+ import { readdirSync, statSync } from "node:fs";
2
+ import path from "node:path";
3
3
  import { Collection } from "discord.js";
4
4
  export const requiredFiles = async (directoryPath) => {
5
5
  const collection = new Collection();
@@ -12,18 +12,13 @@ export const requiredFiles = async (directoryPath) => {
12
12
  return collection;
13
13
  };
14
14
  const loadInteraction = async (filePath) => {
15
- try {
16
- const module = await import(`file://${filePath}`);
17
- const data = module.default;
18
- return data;
19
- }
20
- catch (error) {
21
- throw error;
22
- }
15
+ const module = await import(`file://${filePath}`);
16
+ const data = module.default;
17
+ return data;
23
18
  };
24
19
  const getAllFilesPath = (dirPath, arrayOfFiles = []) => {
25
20
  const files = readdirSync(dirPath);
26
- files.forEach((file) => {
21
+ for (const file of files) {
27
22
  if (statSync(dirPath + "/" + file).isDirectory()) {
28
23
  arrayOfFiles = getAllFilesPath(dirPath + "/" + file, arrayOfFiles);
29
24
  }
@@ -31,6 +26,6 @@ const getAllFilesPath = (dirPath, arrayOfFiles = []) => {
31
26
  const __dirname = path.resolve();
32
27
  arrayOfFiles.push(path.join(__dirname, dirPath, "/", file));
33
28
  }
34
- });
29
+ }
35
30
  return arrayOfFiles;
36
31
  };
@@ -1,15 +1,16 @@
1
1
  import logSymbols from "log-symbols";
2
+ const prefix = "[StelliaJS]";
2
3
  export const logger = {
3
4
  info: (message) => {
4
- console.log(`${logSymbols.info} ${message}`);
5
+ console.log(`${logSymbols.info} ${prefix} ${message}`);
5
6
  },
6
7
  success: (message) => {
7
- console.log(`${logSymbols.success} ${message}`);
8
+ console.log(`${logSymbols.success} ${prefix} ${message}`);
8
9
  },
9
10
  warn: (message) => {
10
- console.warn(`${logSymbols.warning} ${message}`);
11
+ console.warn(`${logSymbols.warning} ${prefix} ${message}`);
11
12
  },
12
13
  error: (message) => {
13
- console.error(`${logSymbols.error} ${message}`);
14
+ console.error(`${logSymbols.error} ${prefix} ${message}`);
14
15
  }
15
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stelliajs/framework",
3
- "version": "1.5.3",
3
+ "version": "1.5.6",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "scripts": {
@@ -23,19 +23,19 @@
23
23
  "framework"
24
24
  ],
25
25
  "dependencies": {
26
- "discord.js": "^14.21.0",
27
- "i18next": "^25.3.4",
26
+ "discord.js": "^14.22.1",
27
+ "i18next": "^25.5.2",
28
28
  "log-symbols": "^7.0.1"
29
29
  },
30
30
  "devDependencies": {
31
- "@eslint/js": "^9.33.0",
32
- "eslint-config-prettier": "^10.1.8",
33
- "eslint-import-resolver-typescript": "^4.4.4",
34
- "eslint-plugin-import": "^2.32.0",
35
- "prettier": "^3.6.2",
36
- "tsc-alias": "^1.8.16",
37
- "typescript-eslint": "^8.39.1"
31
+ "@eslint/js": "^9.36.0",
32
+ "eslint-config-prettier": "^10.1.8",
33
+ "eslint-import-resolver-typescript": "^4.4.4",
34
+ "eslint-plugin-import": "^2.32.0",
35
+ "prettier": "^3.6.2",
36
+ "tsc-alias": "^1.8.16",
37
+ "typescript-eslint": "^8.44.1"
38
38
  },
39
39
  "type": "module",
40
- "packageManager": "pnpm@10.14.0"
40
+ "packageManager": "pnpm@10.17.1"
41
41
  }
package/.prettierrc DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "semi": true,
3
- "singleQuote": false,
4
- "useTabs": true,
5
- "tabWidth": 2,
6
- "trailingComma": "none",
7
- "printWidth": 100
8
- }
package/eslint.config.mjs DELETED
@@ -1,68 +0,0 @@
1
- import js from "@eslint/js";
2
- import ts from "typescript-eslint";
3
- import importPlugin from "eslint-plugin-import";
4
- import prettierConfig from "eslint-config-prettier";
5
-
6
- export default ts.config(
7
- js.configs.recommended,
8
- ts.configs.recommended,
9
- importPlugin.flatConfigs.recommended,
10
- importPlugin.flatConfigs.typescript,
11
- prettierConfig,
12
- {
13
- languageOptions: {
14
- parserOptions: {
15
- project: "./tsconfig.json",
16
- sourceType: "module",
17
- ecmaVersion: "latest"
18
- }
19
- },
20
- rules: {
21
- "import/namespace": "off",
22
- "@typescript-eslint/explicit-function-return-type": "off",
23
- "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
24
- "@typescript-eslint/no-explicit-any": "warn",
25
- "import/order": [
26
- "error",
27
- {
28
- groups: [
29
- "builtin",
30
- "external",
31
- "internal",
32
- ["parent", "sibling", "index"],
33
- "object",
34
- "type"
35
- ],
36
- pathGroups: [
37
- {
38
- pattern: "@/**",
39
- group: "internal"
40
- }
41
- ],
42
- pathGroupsExcludedImportTypes: ["builtin"],
43
- alphabetize: {
44
- order: "asc",
45
- caseInsensitive: true
46
- }
47
- }
48
- ],
49
- "import/newline-after-import": ["error", { count: 1 }],
50
- "import/no-unresolved": "error",
51
- "import/no-duplicates": "error",
52
- "no-console": "off",
53
- "no-var": "error",
54
- "prefer-const": "error"
55
- },
56
- settings: {
57
- "import/resolver": {
58
- typescript: {
59
- alwaysTryTypes: true,
60
- project: "./tsconfig.json"
61
- },
62
- node: {
63
- extensions: [".js", ".ts"]
64
- }
65
- }
66
- }
67
- }
68
- );