@stelliajs/framework 1.1.0 → 1.1.2

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.
@@ -8,6 +8,7 @@ export declare class StelliaClient<Ready extends boolean = boolean> extends Clie
8
8
  connect: (token: string) => Promise<void>;
9
9
  initializeCommands: () => Promise<void>;
10
10
  handleInteraction: (interaction: AnyInteraction) => Promise<void>;
11
+ private areManagersLoaded;
11
12
  }
12
13
  interface StelliaOptions {
13
14
  autoCompletes?: ManagerOptions;
@@ -1,4 +1,4 @@
1
- import { Client, Events } from "discord.js";
1
+ import { Client } from "discord.js";
2
2
  import { AutoCompleteManager, ButtonManager, CommandManager, ContextMenuManager, EventManager, ModalManager, SelectMenuManager } from "../managers/index.js";
3
3
  import { StelliaUtils } from "./index.js";
4
4
  export class StelliaClient extends Client {
@@ -28,13 +28,20 @@ export class StelliaClient extends Client {
28
28
  if (stelliaOptions?.modals?.directoryPath) {
29
29
  this.managers.modals = new ModalManager(this, stelliaOptions.modals.directoryPath);
30
30
  }
31
- }
32
- connect = async (token) => {
33
- this.on(Events.Error, (error) => console.error(error));
34
- await this.login(token);
35
31
  process.on("unhandledRejection", (error) => {
36
32
  console.error(`Unhandled promise rejection: ${error}`);
37
33
  });
34
+ }
35
+ connect = async (token) => {
36
+ if (!this.areManagersLoaded()) {
37
+ setTimeout(() => {
38
+ console.log("Managers are not loaded yet, retrying in 500ms...");
39
+ this.connect(token);
40
+ }, 500);
41
+ return;
42
+ }
43
+ console.log("Managers are loaded, connecting to Discord...");
44
+ await this.login(token);
38
45
  };
39
46
  initializeCommands = async () => {
40
47
  await this.utils.initializeCommands();
@@ -42,4 +49,8 @@ export class StelliaClient extends Client {
42
49
  handleInteraction = async (interaction) => {
43
50
  await this.utils.handleInteraction(interaction);
44
51
  };
52
+ areManagersLoaded = () => {
53
+ const managers = Object.values(this.managers);
54
+ return managers.length === 0 ? true : managers.every((manager) => manager.isManagerLoaded());
55
+ };
45
56
  }
@@ -9,6 +9,7 @@ export class AutoCompleteManager extends BaseManager {
9
9
  async loadData() {
10
10
  const autoCompletes = await requiredFiles(this.directoryPath);
11
11
  this.interactions = autoCompletes;
12
+ this.setManagerLoaded();
12
13
  }
13
14
  getByCustomId(id) {
14
15
  const autoComplete = this.interactions.get(id) ?? undefined;
@@ -8,7 +8,10 @@ export interface ManagerOptions {
8
8
  export declare abstract class BaseManager {
9
9
  readonly client: StelliaClient;
10
10
  readonly directoryPath: string;
11
+ private isLoaded;
11
12
  constructor(client: StelliaClient, directory: string);
13
+ isManagerLoaded(): boolean;
14
+ setManagerLoaded(): void;
12
15
  abstract loadData(): void;
13
16
  abstract getByCustomId<InteractionStructure extends AnyInteractionStructure>(id: InteractionCustomId): InteractionStructure | undefined;
14
17
  abstract getByRegex<InteractionStructure extends AnyInteractionStructure>(id: InteractionCustomId): InteractionStructure | undefined;
@@ -1,9 +1,16 @@
1
1
  export class BaseManager {
2
2
  client;
3
3
  directoryPath;
4
+ isLoaded = false;
4
5
  constructor(client, directory) {
5
6
  this.client = client;
6
7
  this.directoryPath = directory;
7
8
  this.loadData();
8
9
  }
10
+ isManagerLoaded() {
11
+ return this.isLoaded;
12
+ }
13
+ setManagerLoaded() {
14
+ this.isLoaded = true;
15
+ }
9
16
  }
@@ -9,6 +9,7 @@ export class ButtonManager extends BaseManager {
9
9
  async loadData() {
10
10
  const buttons = await requiredFiles(this.directoryPath);
11
11
  this.interactions = buttons;
12
+ this.setManagerLoaded();
12
13
  }
13
14
  getByCustomId(id) {
14
15
  const button = this.interactions.get(id) ?? undefined;
@@ -1,10 +1,9 @@
1
1
  import { Collection } from "discord.js";
2
2
  import { type StelliaClient } from "../client/index.js";
3
3
  import { BaseManager } from "./index.js";
4
- import { type CommandStructure } from "../structures/index.js";
5
4
  import { type StructureCustomId, type InteractionCustomId } from "../typescript/index.js";
6
5
  export declare class CommandManager extends BaseManager {
7
- interactions: Collection<StructureCustomId, CommandStructure>;
6
+ private interactions;
8
7
  constructor(client: StelliaClient, directory: string);
9
8
  loadData(): Promise<void>;
10
9
  getByCustomId<CommandStructure>(id: InteractionCustomId): CommandStructure | undefined;
@@ -9,6 +9,7 @@ export class CommandManager extends BaseManager {
9
9
  async loadData() {
10
10
  const commands = await requiredFiles(this.directoryPath);
11
11
  this.interactions = commands;
12
+ this.setManagerLoaded();
12
13
  }
13
14
  getByCustomId(id) {
14
15
  const command = this.interactions.get(id) ?? undefined;
@@ -1,10 +1,9 @@
1
1
  import { Collection } from "discord.js";
2
2
  import { type StelliaClient } from "../client/index.js";
3
3
  import { BaseManager } from "./index.js";
4
- import { type ContextMenuStructure } from "../structures/index.js";
5
4
  import { type StructureCustomId, type InteractionCustomId } from "../typescript/index.js";
6
5
  export declare class ContextMenuManager extends BaseManager {
7
- interactions: Collection<StructureCustomId, ContextMenuStructure>;
6
+ private interactions;
8
7
  constructor(client: StelliaClient, directory: string);
9
8
  loadData(): Promise<void>;
10
9
  getByCustomId<ContextMenuStructure>(id: InteractionCustomId): ContextMenuStructure | undefined;
@@ -9,6 +9,7 @@ export class ContextMenuManager extends BaseManager {
9
9
  async loadData() {
10
10
  const contextMenus = await requiredFiles(this.directoryPath);
11
11
  this.interactions = contextMenus;
12
+ this.setManagerLoaded();
12
13
  }
13
14
  getByCustomId(id) {
14
15
  const contextMenu = this.interactions.get(id) ?? undefined;
@@ -1,10 +1,9 @@
1
1
  import { Collection } from "discord.js";
2
2
  import { type StelliaClient } from "../client/index.js";
3
3
  import { BaseManager } from "./index.js";
4
- import { type EventStructure } from "../structures/index.js";
5
4
  import { type StructureCustomId, type InteractionCustomId } from "../typescript/index.js";
6
5
  export declare class EventManager extends BaseManager {
7
- interactions: Collection<StructureCustomId, EventStructure>;
6
+ private interactions;
8
7
  constructor(client: StelliaClient, directoryPath: string);
9
8
  loadData(): Promise<void>;
10
9
  getByCustomId<EventStructure>(id: InteractionCustomId): EventStructure | undefined;
@@ -1,4 +1,4 @@
1
- import { Collection } from "discord.js";
1
+ import { Collection, Events } from "discord.js";
2
2
  import { BaseManager } from "./index.js";
3
3
  import { requiredFiles } from "../utils/index.js";
4
4
  export class EventManager extends BaseManager {
@@ -18,6 +18,8 @@ export class EventManager extends BaseManager {
18
18
  this.client.on(name, (...args) => event.execute(this.client, ...args));
19
19
  }
20
20
  }
21
+ this.client.on(Events.Error, (error) => console.error(error));
22
+ this.setManagerLoaded();
21
23
  }
22
24
  getByCustomId(id) {
23
25
  const event = this.interactions.get(id) ?? undefined;
@@ -1,10 +1,9 @@
1
1
  import { Collection } from "discord.js";
2
2
  import { type StelliaClient } from "../client/index.js";
3
3
  import { BaseManager } from "./index.js";
4
- import { type ModalStructure } from "../structures/index.js";
5
4
  import { type StructureCustomId, type InteractionCustomId } from "../typescript/index.js";
6
5
  export declare class ModalManager extends BaseManager {
7
- interactions: Collection<StructureCustomId, ModalStructure>;
6
+ private interactions;
8
7
  constructor(client: StelliaClient, directory: string);
9
8
  loadData(): Promise<void>;
10
9
  getByCustomId<ModalStructure>(id: InteractionCustomId): ModalStructure | undefined;
@@ -9,6 +9,7 @@ export class ModalManager extends BaseManager {
9
9
  async loadData() {
10
10
  const modals = await requiredFiles(this.directoryPath);
11
11
  this.interactions = modals;
12
+ this.setManagerLoaded();
12
13
  }
13
14
  getByCustomId(id) {
14
15
  const modal = this.interactions.get(id) ?? undefined;
@@ -1,10 +1,9 @@
1
1
  import { Collection } from "discord.js";
2
2
  import { type StelliaClient } from "../client/index.js";
3
3
  import { BaseManager } from "./index.js";
4
- import { type SelectMenuStructure } from "../structures/index.js";
5
4
  import { type StructureCustomId, type InteractionCustomId } from "../typescript/index.js";
6
5
  export declare class SelectMenuManager extends BaseManager {
7
- interactions: Collection<StructureCustomId, SelectMenuStructure>;
6
+ private interactions;
8
7
  constructor(client: StelliaClient, directory: string);
9
8
  loadData(): Promise<void>;
10
9
  getByCustomId<SelectMenuStructure>(id: InteractionCustomId): SelectMenuStructure | undefined;
@@ -9,6 +9,7 @@ export class SelectMenuManager extends BaseManager {
9
9
  async loadData() {
10
10
  const selectMenus = await requiredFiles(this.directoryPath);
11
11
  this.interactions = selectMenus;
12
+ this.setManagerLoaded();
12
13
  }
13
14
  getByCustomId(id) {
14
15
  const selectMenu = this.interactions.get(id) ?? undefined;
@@ -12,6 +12,7 @@ export declare enum InteractionType {
12
12
  SelectMenu = "SelectMenu",
13
13
  Unknown = "Unknown"
14
14
  }
15
+ export type Manager = AutoCompleteManager | ButtonManager | CommandManager | ContextMenuManager | EventManager | ModalManager | SelectMenuManager;
15
16
  export interface Managers {
16
17
  autoCompletes?: AutoCompleteManager;
17
18
  buttons?: ButtonManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stelliajs/framework",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "scripts": {
@@ -15,8 +15,8 @@
15
15
  "description": "A framework for simplify the creation of discord bots",
16
16
  "keywords": ["discord", "bot", "discordjs", "typescript", "framework"],
17
17
  "dependencies": {
18
- "discord-api-types": "^0.37.100",
19
- "discord.js": "^14.16.1"
18
+ "discord-api-types": "^0.37.115",
19
+ "discord.js": "^14.17.2"
20
20
  },
21
21
  "devDependencies": {
22
22
  "ts-node": "^10.9.2",