@stelliajs/framework 1.1.2 → 1.2.0-dev-1

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,22 +1,27 @@
1
1
  import { Client, type ClientOptions } from "discord.js";
2
2
  import { type ManagerOptions } from "../managers/index.js";
3
- import { type AnyInteraction, type Managers } from "../typescript/index.js";
3
+ import { type AnyInteraction, type Environment, type EnvironmentConfiguration, 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
6
  readonly managers: Managers;
7
+ readonly environment: Environment;
7
8
  constructor(clientOptions: ClientOptions, stelliaOptions?: StelliaOptions);
8
9
  connect: (token: string) => Promise<void>;
9
10
  initializeCommands: () => Promise<void>;
11
+ getEnvironment: <CustomEnvironment extends EnvironmentConfiguration>() => Promise<CustomEnvironment>;
10
12
  handleInteraction: (interaction: AnyInteraction) => Promise<void>;
11
13
  private areManagersLoaded;
12
14
  }
13
15
  interface StelliaOptions {
14
- autoCompletes?: ManagerOptions;
15
- buttons?: ManagerOptions;
16
- commands?: ManagerOptions;
17
- contextMenus?: ManagerOptions;
18
- events?: ManagerOptions;
19
- selectMenus?: ManagerOptions;
20
- modals?: ManagerOptions;
16
+ managers: {
17
+ autoCompletes?: ManagerOptions;
18
+ buttons?: ManagerOptions;
19
+ commands?: ManagerOptions;
20
+ contextMenus?: ManagerOptions;
21
+ events?: ManagerOptions;
22
+ selectMenus?: ManagerOptions;
23
+ modals?: ManagerOptions;
24
+ };
25
+ environment?: Environment;
21
26
  }
22
27
  export {};
@@ -1,33 +1,40 @@
1
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
+ import path from "path";
5
+ import * as fs from "node:fs";
6
+ import { pathToFileURL } from 'url';
4
7
  export class StelliaClient extends Client {
5
8
  utils;
6
9
  managers = {};
10
+ environment;
7
11
  constructor(clientOptions, stelliaOptions) {
8
12
  super(clientOptions);
9
- this.utils = new StelliaUtils(this);
10
- if (stelliaOptions?.autoCompletes?.directoryPath) {
11
- this.managers.autoCompletes = new AutoCompleteManager(this, stelliaOptions.autoCompletes.directoryPath);
13
+ if (stelliaOptions?.managers.autoCompletes?.directoryPath) {
14
+ this.managers.autoCompletes = new AutoCompleteManager(this, stelliaOptions.managers.autoCompletes.directoryPath);
15
+ }
16
+ if (stelliaOptions?.managers.buttons?.directoryPath) {
17
+ this.managers.buttons = new ButtonManager(this, stelliaOptions.managers.buttons.directoryPath);
12
18
  }
13
- if (stelliaOptions?.buttons?.directoryPath) {
14
- this.managers.buttons = new ButtonManager(this, stelliaOptions.buttons.directoryPath);
19
+ if (stelliaOptions?.managers.commands?.directoryPath) {
20
+ this.managers.commands = new CommandManager(this, stelliaOptions.managers.commands.directoryPath);
15
21
  }
16
- if (stelliaOptions?.commands?.directoryPath) {
17
- this.managers.commands = new CommandManager(this, stelliaOptions.commands.directoryPath);
22
+ if (stelliaOptions?.managers.contextMenus?.directoryPath) {
23
+ this.managers.contextMenus = new ContextMenuManager(this, stelliaOptions.managers.contextMenus.directoryPath);
18
24
  }
19
- if (stelliaOptions?.contextMenus?.directoryPath) {
20
- this.managers.contextMenus = new ContextMenuManager(this, stelliaOptions.contextMenus.directoryPath);
25
+ if (stelliaOptions?.managers.events?.directoryPath) {
26
+ this.managers.events = new EventManager(this, stelliaOptions.managers.events.directoryPath);
21
27
  }
22
- if (stelliaOptions?.events?.directoryPath) {
23
- this.managers.events = new EventManager(this, stelliaOptions.events.directoryPath);
28
+ if (stelliaOptions?.managers.selectMenus?.directoryPath) {
29
+ this.managers.selectMenus = new SelectMenuManager(this, stelliaOptions.managers.selectMenus.directoryPath);
24
30
  }
25
- if (stelliaOptions?.selectMenus?.directoryPath) {
26
- this.managers.selectMenus = new SelectMenuManager(this, stelliaOptions.selectMenus.directoryPath);
31
+ if (stelliaOptions?.managers.modals?.directoryPath) {
32
+ this.managers.modals = new ModalManager(this, stelliaOptions.managers.modals.directoryPath);
27
33
  }
28
- if (stelliaOptions?.modals?.directoryPath) {
29
- this.managers.modals = new ModalManager(this, stelliaOptions.modals.directoryPath);
34
+ if (stelliaOptions?.environment) {
35
+ this.environment = stelliaOptions.environment;
30
36
  }
37
+ this.utils = new StelliaUtils(this);
31
38
  process.on("unhandledRejection", (error) => {
32
39
  console.error(`Unhandled promise rejection: ${error}`);
33
40
  });
@@ -46,6 +53,34 @@ export class StelliaClient extends Client {
46
53
  initializeCommands = async () => {
47
54
  await this.utils.initializeCommands();
48
55
  };
56
+ getEnvironment = async () => {
57
+ const chosenEnvironment = process.argv.find(arg => arg.startsWith("--config"))?.split("=")[1];
58
+ if (!chosenEnvironment) {
59
+ throw new Error("Environment not provided");
60
+ }
61
+ const srcPath = path.dirname(path.resolve(process.argv[1]));
62
+ const filePath = path.join(srcPath, "..", "stellia.json");
63
+ return new Promise((resolve, reject) => {
64
+ fs.readFile(filePath, async (err, data) => {
65
+ if (err) {
66
+ return reject(err);
67
+ }
68
+ try {
69
+ const environments = JSON.parse(data.toString()).environments;
70
+ if (!Object.keys(environments).includes(chosenEnvironment)) {
71
+ return reject(new Error("Invalid environment"));
72
+ }
73
+ const environmentPath = environments[chosenEnvironment];
74
+ const environmentAbsolutePath = pathToFileURL(path.join(srcPath, "..", environmentPath.file)).href;
75
+ const environmentFile = await import(environmentAbsolutePath);
76
+ resolve(environmentFile.environment);
77
+ }
78
+ catch (error) {
79
+ reject(error);
80
+ }
81
+ });
82
+ });
83
+ };
49
84
  handleInteraction = async (interaction) => {
50
85
  await this.utils.handleInteraction(interaction);
51
86
  };
@@ -1,8 +1,9 @@
1
1
  import { type StelliaClient } from "./index.js";
2
- import { AnyInteraction } from "../typescript/index.js";
2
+ import { type AnyInteraction } from "../typescript/index.js";
3
3
  export declare class StelliaUtils {
4
4
  readonly client: StelliaClient;
5
5
  private readonly interactionHandlers;
6
+ private environment;
6
7
  constructor(client: StelliaClient);
7
8
  initializeCommands: () => Promise<void>;
8
9
  handleInteraction: (interaction: AnyInteraction) => Promise<void>;
@@ -4,6 +4,7 @@ import { InteractionType } from "../typescript/index.js";
4
4
  export class StelliaUtils {
5
5
  client;
6
6
  interactionHandlers;
7
+ environment;
7
8
  constructor(client) {
8
9
  this.client = client;
9
10
  this.interactionHandlers = new Map([
@@ -14,6 +15,13 @@ export class StelliaUtils {
14
15
  [InteractionType.ModalSubmit, this.handleModalInteraction],
15
16
  [InteractionType.SelectMenu, this.handleSelectMenuInteraction]
16
17
  ]);
18
+ if (this.client.environment.isEnvironmentsEnabled) {
19
+ this.client.getEnvironment()
20
+ .then((environment) => {
21
+ this.environment = environment;
22
+ })
23
+ .catch((error) => console.error(error));
24
+ }
17
25
  }
18
26
  initializeCommands = async () => {
19
27
  const commands = this.client.managers.commands?.getAll().values();
@@ -50,6 +58,10 @@ export class StelliaUtils {
50
58
  const autoComplete = autoCompleteManager.getByCustomId(interactionAutoComplete.commandName);
51
59
  if (!autoComplete)
52
60
  return;
61
+ if (this.client.environment.isEnvironmentsEnabled) {
62
+ await autoComplete.execute(this.client, this.environment, interactionAutoComplete);
63
+ return;
64
+ }
53
65
  await autoComplete.execute(this.client, interactionAutoComplete);
54
66
  }
55
67
  catch (error) {
@@ -65,6 +77,10 @@ export class StelliaUtils {
65
77
  const button = buttonManager.getByCustomId(buttonInteraction.customId) || buttonManager.getByRegex(buttonInteraction.customId);
66
78
  if (!button)
67
79
  return;
80
+ if (this.client.environment.isEnvironmentsEnabled) {
81
+ await button.execute(this.client, this.environment, buttonInteraction);
82
+ return;
83
+ }
68
84
  await button.execute(this.client, buttonInteraction);
69
85
  }
70
86
  catch (error) {
@@ -80,6 +96,10 @@ export class StelliaUtils {
80
96
  const command = commandManager.getByCustomId(interactionCommand.commandName);
81
97
  if (!command)
82
98
  return;
99
+ if (this.client.environment.isEnvironmentsEnabled) {
100
+ await command.execute(this.client, this.environment, interactionCommand);
101
+ return;
102
+ }
83
103
  await command.execute(this.client, interactionCommand);
84
104
  }
85
105
  catch (error) {
@@ -111,6 +131,10 @@ export class StelliaUtils {
111
131
  const modal = modalManager.getByCustomId(interactionModal.customId) || modalManager.getByRegex(interactionModal.customId);
112
132
  if (!modal)
113
133
  return;
134
+ if (this.client.environment.isEnvironmentsEnabled) {
135
+ await modal.execute(this.client, this.environment, interactionModal);
136
+ return;
137
+ }
114
138
  await modal.execute(this.client, interactionModal);
115
139
  }
116
140
  catch (error) {
@@ -126,6 +150,10 @@ export class StelliaUtils {
126
150
  const selectMenu = selectMenuManager.getByCustomId(interactionSelectMenu.customId) || selectMenuManager.getByRegex(interactionSelectMenu.customId);
127
151
  if (!selectMenu)
128
152
  return;
153
+ if (this.client.environment.isEnvironmentsEnabled) {
154
+ await selectMenu.execute(this.client, this.environment, interactionSelectMenu);
155
+ return;
156
+ }
129
157
  await selectMenu.execute(this.client, interactionSelectMenu);
130
158
  }
131
159
  catch (error) {
@@ -140,6 +168,10 @@ export class StelliaUtils {
140
168
  const messageContextMenu = contextMenuManager.getByCustomId(interaction.commandName);
141
169
  if (!messageContextMenu)
142
170
  return;
171
+ if (this.client.environment.isEnvironmentsEnabled) {
172
+ await messageContextMenu.execute(this.client, this.environment, interaction);
173
+ return;
174
+ }
143
175
  await messageContextMenu.execute(this.client, interaction);
144
176
  }
145
177
  catch (error) {
@@ -154,6 +186,10 @@ export class StelliaUtils {
154
186
  const userContextMenu = contextMenuManager.getByCustomId(interaction.commandName);
155
187
  if (!userContextMenu)
156
188
  return;
189
+ if (this.client.environment.isEnvironmentsEnabled) {
190
+ await userContextMenu.execute(this.client, this.environment, interaction);
191
+ return;
192
+ }
157
193
  await userContextMenu.execute(this.client, interaction);
158
194
  }
159
195
  catch (error) {
@@ -1,30 +1,38 @@
1
1
  import { type AnySelectMenuInteraction, type AutocompleteInteraction, type Awaitable, type ButtonInteraction, type ChatInputCommandInteraction, type ContextMenuCommandBuilder, type MessageContextMenuCommandInteraction, type ModalSubmitInteraction, type SlashCommandBuilder, type UserContextMenuCommandInteraction } from "discord.js";
2
2
  import { type StelliaClient } from "../client/index.js";
3
+ import { type EnvironmentConfiguration } from "../typescript/index.js";
4
+ import { type EventStructure } from "./Event.js";
3
5
  export interface AutoCompleteStructure {
4
6
  data: DefaultDataStructure;
5
7
  execute(client: StelliaClient, interaction: AutocompleteInteraction<"cached">): Awaitable<unknown>;
8
+ execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment, interaction: AutocompleteInteraction<"cached">): Awaitable<unknown>;
6
9
  }
7
10
  export interface ButtonStructure {
8
11
  data: DefaultDataStructure;
9
12
  execute(client: StelliaClient, interaction: ButtonInteraction<"cached">): Awaitable<unknown>;
13
+ execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment, interaction: ButtonInteraction<"cached">): Awaitable<unknown>;
10
14
  }
11
15
  export interface CommandStructure {
12
16
  data: SlashCommandBuilder;
13
17
  execute(client: StelliaClient, interaction: ChatInputCommandInteraction<"cached">): Awaitable<unknown>;
18
+ execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment, interaction: ChatInputCommandInteraction<"cached">): Awaitable<unknown>;
14
19
  }
15
20
  export interface ContextMenuStructure {
16
21
  data: ContextMenuCommandBuilder;
17
22
  execute(client: StelliaClient, interaction: MessageContextMenuCommandInteraction<"cached"> | UserContextMenuCommandInteraction<"cached">): Awaitable<unknown>;
23
+ execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment, interaction: MessageContextMenuCommandInteraction<"cached"> | UserContextMenuCommandInteraction<"cached">): Awaitable<unknown>;
18
24
  }
19
25
  export interface ModalStructure {
20
26
  data: DefaultDataStructure;
21
27
  execute(client: StelliaClient, interaction: ModalSubmitInteraction<"cached">): Awaitable<unknown>;
28
+ execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment, interaction: ModalSubmitInteraction<"cached">): Awaitable<unknown>;
22
29
  }
23
30
  export interface SelectMenuStructure {
24
31
  data: DefaultDataStructure;
25
32
  execute(client: StelliaClient, interaction: AnySelectMenuInteraction<"cached">): Awaitable<unknown>;
33
+ execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment, interaction: AnySelectMenuInteraction<"cached">): Awaitable<unknown>;
26
34
  }
27
- export type AnyInteractionStructure = AutoCompleteStructure | ButtonStructure | CommandStructure | ContextMenuStructure | ModalStructure | SelectMenuStructure;
35
+ export type AnyInteractionStructure = AutoCompleteStructure | ButtonStructure | CommandStructure | ContextMenuStructure | EventStructure | ModalStructure | SelectMenuStructure;
28
36
  interface DefaultDataStructure {
29
37
  name: string | RegExp;
30
38
  once: boolean;
@@ -22,3 +22,9 @@ export interface Managers {
22
22
  selectMenus?: SelectMenuManager;
23
23
  modals?: ModalManager;
24
24
  }
25
+ export interface Environment {
26
+ isEnvironmentsEnabled: boolean;
27
+ }
28
+ export interface EnvironmentConfiguration {
29
+ [key: string]: unknown;
30
+ }
@@ -1,12 +1,13 @@
1
+ import { MessageFlags } from "discord.js";
1
2
  export const ephemeralFollowUpResponse = async (interaction, data, automaticDeletion = false) => {
2
3
  if (!interaction.deferred) {
3
- await interaction.deferReply({ ephemeral: true });
4
+ await interaction.deferReply({ flags: MessageFlags.Ephemeral });
4
5
  }
5
6
  if (typeof data === "string") {
6
- await interaction.followUp({ content: data, ephemeral: true });
7
+ await interaction.followUp({ content: data, flags: MessageFlags.Ephemeral });
7
8
  }
8
9
  else {
9
- await interaction.followUp({ ...data, ephemeral: true });
10
+ await interaction.followUp({ ...data, flags: MessageFlags.Ephemeral });
10
11
  }
11
12
  if (automaticDeletion) {
12
13
  setTimeout(() => {
@@ -19,13 +20,13 @@ export const ephemeralFollowUpResponse = async (interaction, data, automaticDele
19
20
  };
20
21
  export const ephemeralReplyResponse = async (interaction, data, automaticDeletion = false) => {
21
22
  if (!interaction.deferred) {
22
- await interaction.deferReply({ ephemeral: true });
23
+ await interaction.deferReply({ flags: MessageFlags.Ephemeral });
23
24
  }
24
25
  if (typeof data === "string") {
25
- await interaction.reply({ content: data, ephemeral: true });
26
+ await interaction.reply({ content: data, flags: MessageFlags.Ephemeral });
26
27
  }
27
28
  else {
28
- await interaction.reply({ ...data, ephemeral: true });
29
+ await interaction.reply({ ...data, flags: MessageFlags.Ephemeral });
29
30
  }
30
31
  if (automaticDeletion) {
31
32
  setTimeout(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stelliajs/framework",
3
- "version": "1.1.2",
3
+ "version": "1.2.0-dev-1",
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.115",
19
- "discord.js": "^14.17.2"
18
+ "discord-api-types": "^0.37.119",
19
+ "discord.js": "^14.17.3"
20
20
  },
21
21
  "devDependencies": {
22
22
  "ts-node": "^10.9.2",