@stelliajs/framework 1.0.0 → 1.0.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.
@@ -1,27 +1,21 @@
1
1
  import { Client, type ClientOptions } from "discord.js";
2
- import { AutoCompleteManager, ButtonManager, CommandManager, ContextMenuManager, EventManager, type ManagerOptions, ModalManager, SelectMenuManager } from "../managers/index.js";
3
- import { type AnyInteraction } from "../typescript/index.js";
2
+ import { type ManagerOptions } from "../managers/index.js";
3
+ import { type AnyInteraction, type Managers } from "../typescript/index.js";
4
4
  export declare class StelliaClient<Ready extends boolean = boolean> extends Client<Ready> {
5
5
  private readonly utils;
6
- readonly autoCompletes: AutoCompleteManager;
7
- readonly buttons: ButtonManager;
8
- readonly commands: CommandManager;
9
- readonly contextMenus: ContextMenuManager;
10
- readonly events: EventManager;
11
- readonly selectMenus: SelectMenuManager;
12
- readonly modals: ModalManager;
13
- constructor(clientOptions: ClientOptions, stelliaOptions: StelliaOptions);
6
+ readonly managers: Managers;
7
+ constructor(clientOptions: ClientOptions, stelliaOptions?: StelliaOptions);
14
8
  connect: (token: string) => Promise<void>;
15
9
  initializeCommands: () => Promise<void>;
16
10
  handleInteraction: (interaction: AnyInteraction) => Promise<void>;
17
11
  }
18
12
  interface StelliaOptions {
19
- autoCompletes: ManagerOptions;
20
- buttons: ManagerOptions;
21
- commands: ManagerOptions;
22
- contextMenus: ManagerOptions;
23
- events: ManagerOptions;
24
- selectMenus: ManagerOptions;
25
- modals: ManagerOptions;
13
+ autoCompletes?: ManagerOptions;
14
+ buttons?: ManagerOptions;
15
+ commands?: ManagerOptions;
16
+ contextMenus?: ManagerOptions;
17
+ events?: ManagerOptions;
18
+ selectMenus?: ManagerOptions;
19
+ modals?: ManagerOptions;
26
20
  }
27
21
  export {};
@@ -3,23 +3,31 @@ import { AutoCompleteManager, ButtonManager, CommandManager, ContextMenuManager,
3
3
  import { StelliaUtils } from "./index.js";
4
4
  export class StelliaClient extends Client {
5
5
  utils;
6
- autoCompletes;
7
- buttons;
8
- commands;
9
- contextMenus;
10
- events;
11
- selectMenus;
12
- modals;
6
+ managers = {};
13
7
  constructor(clientOptions, stelliaOptions) {
14
8
  super(clientOptions);
15
9
  this.utils = new StelliaUtils(this);
16
- this.autoCompletes = new AutoCompleteManager(this, stelliaOptions.autoCompletes.directoryPath);
17
- this.buttons = new ButtonManager(this, stelliaOptions.buttons.directoryPath);
18
- this.commands = new CommandManager(this, stelliaOptions.commands.directoryPath);
19
- this.contextMenus = new ContextMenuManager(this, stelliaOptions.contextMenus.directoryPath);
20
- this.events = new EventManager(this, stelliaOptions.events.directoryPath);
21
- this.selectMenus = new SelectMenuManager(this, stelliaOptions.selectMenus.directoryPath);
22
- this.modals = new ModalManager(this, stelliaOptions.modals.directoryPath);
10
+ if (stelliaOptions?.autoCompletes?.directoryPath) {
11
+ this.managers.autoCompletes = new AutoCompleteManager(this, stelliaOptions.autoCompletes.directoryPath);
12
+ }
13
+ if (stelliaOptions?.buttons?.directoryPath) {
14
+ this.managers.buttons = new ButtonManager(this, stelliaOptions.buttons.directoryPath);
15
+ }
16
+ if (stelliaOptions?.commands?.directoryPath) {
17
+ this.managers.commands = new CommandManager(this, stelliaOptions.commands.directoryPath);
18
+ }
19
+ if (stelliaOptions?.contextMenus?.directoryPath) {
20
+ this.managers.contextMenus = new ContextMenuManager(this, stelliaOptions.contextMenus.directoryPath);
21
+ }
22
+ if (stelliaOptions?.events?.directoryPath) {
23
+ this.managers.events = new EventManager(this, stelliaOptions.events.directoryPath);
24
+ }
25
+ if (stelliaOptions?.selectMenus?.directoryPath) {
26
+ this.managers.selectMenus = new SelectMenuManager(this, stelliaOptions.selectMenus.directoryPath);
27
+ }
28
+ if (stelliaOptions?.modals?.directoryPath) {
29
+ this.managers.modals = new ModalManager(this, stelliaOptions.modals.directoryPath);
30
+ }
23
31
  }
24
32
  connect = async (token) => {
25
33
  this.on(Events.Error, (error) => console.error(error));
@@ -16,14 +16,13 @@ export class StelliaUtils {
16
16
  ]);
17
17
  }
18
18
  initializeCommands = async () => {
19
- const commands = [
20
- ...Array.from(this.client.commands.getAll().values()).map((command) => command.data),
21
- ...Array.from(this.client.contextMenus.getAll().values()).map((contextMenu) => contextMenu.data),
22
- ];
19
+ const commands = this.client.managers.commands?.getAll().values();
20
+ const contextMenus = this.client.managers.contextMenus?.getAll().values();
21
+ const applicationCommands = [...(commands || []), ...(contextMenus || [])].map((item) => item.data);
23
22
  if (this.client.isReady()) {
24
23
  const rest = new REST({ version: DISCORD_API_VERSION }).setToken(this.client.token);
25
24
  try {
26
- await rest.put(Routes.applicationCommands(this.client.user.id), { body: commands });
25
+ await rest.put(Routes.applicationCommands(this.client.user.id), { body: applicationCommands });
27
26
  }
28
27
  catch (error) {
29
28
  console.error(error);
@@ -45,7 +44,7 @@ export class StelliaUtils {
45
44
  handleAutoCompleteInteraction = async (interaction) => {
46
45
  try {
47
46
  const interactionAutoComplete = interaction;
48
- const autoComplete = this.client.autoCompletes.get(interactionAutoComplete.commandName);
47
+ const autoComplete = this.client.managers.autoCompletes?.get(interactionAutoComplete.commandName);
49
48
  if (!autoComplete)
50
49
  return;
51
50
  await autoComplete.execute(this.client, interactionAutoComplete);
@@ -57,7 +56,7 @@ export class StelliaUtils {
57
56
  handleButtonInteraction = async (interaction) => {
58
57
  try {
59
58
  const buttonInteraction = interaction;
60
- const button = this.client.buttons.get(buttonInteraction.customId);
59
+ const button = this.client.managers.buttons?.get(buttonInteraction.customId);
61
60
  if (!button)
62
61
  return;
63
62
  await button.execute(this.client, buttonInteraction);
@@ -69,7 +68,7 @@ export class StelliaUtils {
69
68
  handleCommandInteraction = async (interaction) => {
70
69
  try {
71
70
  const interactionCommand = interaction;
72
- const command = this.client.commands.get(interactionCommand.commandName);
71
+ const command = this.client.managers.commands?.get(interactionCommand.commandName);
73
72
  if (!command)
74
73
  return;
75
74
  await command.execute(this.client, interactionCommand);
@@ -97,7 +96,7 @@ export class StelliaUtils {
97
96
  handleModalInteraction = async (interaction) => {
98
97
  try {
99
98
  const interactionModal = interaction;
100
- const modal = this.client.modals.get(interactionModal.customId);
99
+ const modal = this.client.managers.modals?.get(interactionModal.customId);
101
100
  if (!modal)
102
101
  return;
103
102
  await modal.execute(this.client, interactionModal);
@@ -109,7 +108,7 @@ export class StelliaUtils {
109
108
  handleSelectMenuInteraction = async (interaction) => {
110
109
  try {
111
110
  const interactionSelectMenu = interaction;
112
- const selectMenu = this.client.modals.get(interactionSelectMenu.customId);
111
+ const selectMenu = this.client.managers.modals?.get(interactionSelectMenu.customId);
113
112
  if (!selectMenu)
114
113
  return;
115
114
  await selectMenu.execute(this.client, interactionSelectMenu);
@@ -120,7 +119,7 @@ export class StelliaUtils {
120
119
  };
121
120
  handleMessageContextMenuInteraction = async (interaction) => {
122
121
  try {
123
- const messageContextMenu = this.client.contextMenus.get(interaction.commandName);
122
+ const messageContextMenu = this.client.managers.contextMenus?.get(interaction.commandName);
124
123
  if (!messageContextMenu)
125
124
  return;
126
125
  await messageContextMenu.execute(this.client, interaction);
@@ -131,7 +130,7 @@ export class StelliaUtils {
131
130
  };
132
131
  handleUserContextMenuInteraction = async (interaction) => {
133
132
  try {
134
- const userContextMenu = this.client.contextMenus.get(interaction.commandName);
133
+ const userContextMenu = this.client.managers.contextMenus?.get(interaction.commandName);
135
134
  if (!userContextMenu)
136
135
  return;
137
136
  await userContextMenu.execute(this.client, interaction);
@@ -1,4 +1,5 @@
1
1
  import { type AnySelectMenuInteraction, type AutocompleteInteraction, type ButtonInteraction, type ChatInputCommandInteraction, type ContextMenuCommandInteraction, type ModalSubmitInteraction, type UserContextMenuCommandInteraction } from "discord.js";
2
+ import { type AutoCompleteManager, type ButtonManager, type CommandManager, type ContextMenuManager, type EventManager, type ModalManager, type SelectMenuManager } from "../managers/index.js";
2
3
  export type CustomId = string;
3
4
  export type AnyInteraction = AutocompleteInteraction<"cached"> | ButtonInteraction<"cached"> | ChatInputCommandInteraction<"cached"> | ContextMenuCommandInteraction<"cached"> | ModalSubmitInteraction<"cached"> | AnySelectMenuInteraction<"cached"> | UserContextMenuCommandInteraction<"cached">;
4
5
  export declare enum InteractionType {
@@ -10,30 +11,12 @@ export declare enum InteractionType {
10
11
  SelectMenu = "SelectMenu",
11
12
  Unknown = "Unknown"
12
13
  }
13
- export type InteractionData = {
14
- commandName: string;
15
- commandOptions?: CommandOptions;
16
- autoCompletes?: AutoCompletes;
17
- buttons?: Buttons;
18
- modals?: Modals;
19
- selectMenus?: SelectMenus;
20
- };
21
- type CommandOptions = {
22
- [key: string]: string;
23
- };
24
- type AutoCompletes = {
25
- [key: string]: string;
26
- };
27
- type Buttons = {
28
- [key: string]: string;
29
- };
30
- type Modals = {
31
- [key: string]: {
32
- customId: string;
33
- [key: string]: string;
34
- };
35
- };
36
- type SelectMenus = {
37
- [key: string]: string;
38
- };
39
- export {};
14
+ export interface Managers {
15
+ autoCompletes?: AutoCompleteManager;
16
+ buttons?: ButtonManager;
17
+ commands?: CommandManager;
18
+ contextMenus?: ContextMenuManager;
19
+ events?: EventManager;
20
+ selectMenus?: SelectMenuManager;
21
+ modals?: ModalManager;
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stelliajs/framework",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "scripts": {