@stelliajs/framework 1.2.3 → 1.3.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.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ## About
4
4
 
5
5
  StelliaJS is built using Discord JS V14 and TypeScript. It allows you to quickly set up a new bot with a simple and complete architecture.
6
- A CLI is available to help you set up a project with StelliaJS : [link to the CLI](https://github.com/StelliaJS/cli)
6
+ A CLI is currently being developed and will soon be available for even greater convenience.
7
7
 
8
8
  ## Architecture
9
9
  Recommended architecture for StelliaJS project.
@@ -19,10 +19,6 @@ Recommended architecture for StelliaJS project.
19
19
  │ │ │ ├── ban.ts
20
20
  │ │ │ └── mute.ts
21
21
  │ │ └── ping.ts
22
- │ ├── environments/
23
- │ │ ├── environment.development.ts
24
- │ │ ├── environment.model.ts
25
- │ │ └── environment.ts
26
22
  │ ├── events/
27
23
  │ │ ├── ready.ts
28
24
  │ │ └── interactionCreate.ts
@@ -40,17 +36,16 @@ Recommended architecture for StelliaJS project.
40
36
  ├── .env
41
37
  ├── package.json
42
38
  ├── package-lock.json
43
- ├── stellia.json
44
39
  └── tsconfig.json
45
40
  ```
46
-
47
41
  ## Examples
48
42
 
49
- ### Simple client with environment
43
+ ### Simple client
50
44
 
51
45
  ```js
52
46
  import { StelliaClient } from "@stelliajs/framework";
53
- import { GatewayIntentBits, Partials } from "discord.js";
47
+ import { GatewayIntentBits } from "discord-api-types/v10";
48
+ import { Partials } from "discord.js";
54
49
 
55
50
  const client = new StelliaClient({
56
51
  intents: [
@@ -61,31 +56,26 @@ const client = new StelliaClient({
61
56
  ],
62
57
  partials: [Partials.Message, Partials.GuildMember]
63
58
  }, {
64
- managers: {
65
- autoCompletes: {
66
- directoryPath: "./interactions/autoCompletes"
67
- },
68
- buttons: {
69
- directoryPath: "./interactions/buttons"
70
- },
71
- commands: {
72
- directoryPath: "./commands/slash"
73
- },
74
- contextMenus: {
75
- directoryPath: "./commands/contextMenus"
76
- },
77
- events: {
78
- directoryPath: "./events"
79
- },
80
- modals: {
81
- directoryPath: "./interactions/modals"
82
- },
83
- selectMenus: {
84
- directoryPath: "./interactions/selectMenus"
85
- }
59
+ autoCompletes: {
60
+ directoryPath: "./interactions/autoCompletes"
61
+ },
62
+ buttons: {
63
+ directoryPath: "./interactions/buttons"
64
+ },
65
+ commands: {
66
+ directoryPath: "./commands/slash"
67
+ },
68
+ contextMenus: {
69
+ directoryPath: "./commands/contextMenus"
70
+ },
71
+ events: {
72
+ directoryPath: "./events"
73
+ },
74
+ modals: {
75
+ directoryPath: "./interactions/modals"
86
76
  },
87
- environment: {
88
- areEnvironmentsEnabled: true
77
+ selectMenus: {
78
+ directoryPath: "./interactions/selectMenus"
89
79
  }
90
80
  });
91
81
 
@@ -94,36 +84,34 @@ await client.connect(process.env.TOKEN);
94
84
 
95
85
  ### Simple event
96
86
 
97
- #### Ready event with environment
87
+ #### Ready event
98
88
  ```js
99
89
  import { type StelliaClient, type EventStructure } from "@stelliajs/framework";
100
90
  import { Events } from "discord.js";
101
- import { type CustomEnvironment } from "@environments/environment.model.ts";
102
91
 
103
92
  export default {
104
93
  data: {
105
94
  name: Events.ClientReady,
106
95
  once: true
107
96
  },
108
- async execute(client: StelliaClient<true>, environment: CustomEnvironment) { // <true> ensures that the client is Ready
97
+ async execute(client: StelliaClient<true>) { // <true> ensures that the client is Ready
109
98
  console.log(`Logged in as ${client.user.tag}`);
110
99
  await client.initializeCommands(); // Used to initialise registered commands
111
100
  }
112
101
  } as EventStructure;
113
102
  ```
114
103
 
115
- #### InteractionCreate event with environment
104
+ #### InteractionCreate event
116
105
  ```js
117
106
  import { type StelliaClient, type EventStructure } from "@stelliajs/framework";
118
107
  import { Events, type Interaction } from "discord.js";
119
- import { type CustomEnvironment } from "@environments/environment.model.ts";
120
108
 
121
109
  export default {
122
110
  data: {
123
111
  name: Events.InteractionCreate,
124
112
  once: false
125
113
  },
126
- async execute(client: StelliaClient<true>, environment: CustomEnvironment, interaction: Interaction) {
114
+ async execute(client: StelliaClient<true>, interaction: Interaction) {
127
115
  if (interaction.inCachedGuild()) {
128
116
  await client.handleInteraction(interaction); // Automatic interaction handling
129
117
  }
@@ -136,12 +124,11 @@ export default {
136
124
  ```js
137
125
  import { type CommandStructure, ephemeralFollowUpResponse, type StelliaClient } from "@stelliajs/framework";
138
126
  import { type ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
139
- import { type CustomEnvironment } from "@environments/environment.model.ts";
140
127
 
141
128
  export default {
142
129
  data: new SlashCommandBuilder()
143
130
  .setName("ping"),
144
- async execute(client: StelliaClient, environment: CustomEnvironment, interaction: ChatInputCommandInteraction<"cached">) { // All interactions are cached
131
+ async execute(client: StelliaClient, interaction: ChatInputCommandInteraction<"cached">) { // All interactions are cached
145
132
  await ephemeralFollowUpResponse(interaction, "Pong!", true); // Response is ephemeral and deleted after 60 seconds
146
133
  }
147
134
  } as CommandStructure;
@@ -52,18 +52,21 @@ export class StelliaUtils {
52
52
  };
53
53
  handleAutoCompleteInteraction = async (interaction) => {
54
54
  try {
55
- const interactionAutoComplete = interaction;
55
+ const autoCompleteInteraction = interaction;
56
56
  const autoCompleteManager = this.client.managers.autoCompletes;
57
57
  if (!autoCompleteManager)
58
58
  return;
59
- const autoComplete = autoCompleteManager.getByCustomId(interactionAutoComplete.commandName);
59
+ const autoComplete = autoCompleteManager.getByCustomId(autoCompleteInteraction.commandName);
60
60
  if (!autoComplete)
61
61
  return;
62
62
  if (this.client.environment.areEnvironmentsEnabled) {
63
- await autoComplete.execute(this.client, this.environment, interactionAutoComplete);
64
- return;
63
+ const autoCompleteWithEnv = autoComplete;
64
+ await autoCompleteWithEnv.execute(this.client, this.environment, autoCompleteInteraction);
65
+ }
66
+ else {
67
+ const autoCompleteWithoutEnv = autoComplete;
68
+ await autoCompleteWithoutEnv.execute(this.client, autoCompleteInteraction);
65
69
  }
66
- await autoComplete.execute(this.client, interactionAutoComplete);
67
70
  }
68
71
  catch (error) {
69
72
  console.error(error);
@@ -79,10 +82,13 @@ export class StelliaUtils {
79
82
  if (!button)
80
83
  return;
81
84
  if (this.client.environment.areEnvironmentsEnabled) {
82
- await button.execute(this.client, this.environment, buttonInteraction);
83
- return;
85
+ const buttonWithEnv = button;
86
+ await buttonWithEnv.execute(this.client, this.environment, buttonInteraction);
87
+ }
88
+ else {
89
+ const buttonWithoutEnv = button;
90
+ await buttonWithoutEnv.execute(this.client, buttonInteraction);
84
91
  }
85
- await button.execute(this.client, buttonInteraction);
86
92
  }
87
93
  catch (error) {
88
94
  console.error(error);
@@ -90,18 +96,21 @@ export class StelliaUtils {
90
96
  };
91
97
  handleCommandInteraction = async (interaction) => {
92
98
  try {
93
- const interactionCommand = interaction;
99
+ const commandInteraction = interaction;
94
100
  const commandManager = this.client.managers.commands;
95
101
  if (!commandManager)
96
102
  return;
97
- const command = commandManager.getByCustomId(interactionCommand.commandName);
103
+ let command = commandManager.getByCustomId(commandInteraction.commandName);
98
104
  if (!command)
99
105
  return;
100
106
  if (this.client.environment.areEnvironmentsEnabled) {
101
- await command.execute(this.client, this.environment, interactionCommand);
102
- return;
107
+ const commandWithEnv = command;
108
+ await commandWithEnv.execute(this.client, this.environment, commandInteraction);
109
+ }
110
+ else {
111
+ const commandWithoutEnv = command;
112
+ await commandWithoutEnv.execute(this.client, commandInteraction);
103
113
  }
104
- await command.execute(this.client, interactionCommand);
105
114
  }
106
115
  catch (error) {
107
116
  console.error(error);
@@ -125,18 +134,21 @@ export class StelliaUtils {
125
134
  };
126
135
  handleModalInteraction = async (interaction) => {
127
136
  try {
128
- const interactionModal = interaction;
137
+ const modalInteraction = interaction;
129
138
  const modalManager = this.client.managers.modals;
130
139
  if (!modalManager)
131
140
  return;
132
- const modal = modalManager.getByCustomId(interactionModal.customId) || modalManager.getByRegex(interactionModal.customId);
141
+ const modal = modalManager.getByCustomId(modalInteraction.customId) || modalManager.getByRegex(modalInteraction.customId);
133
142
  if (!modal)
134
143
  return;
135
144
  if (this.client.environment.areEnvironmentsEnabled) {
136
- await modal.execute(this.client, this.environment, interactionModal);
137
- return;
145
+ const modalWithEnv = modal;
146
+ await modalWithEnv.execute(this.client, this.environment, modalInteraction);
147
+ }
148
+ else {
149
+ const modalWithoutEnv = modal;
150
+ await modalWithoutEnv.execute(this.client, modalInteraction);
138
151
  }
139
- await modal.execute(this.client, interactionModal);
140
152
  }
141
153
  catch (error) {
142
154
  console.error(error);
@@ -144,18 +156,21 @@ export class StelliaUtils {
144
156
  };
145
157
  handleSelectMenuInteraction = async (interaction) => {
146
158
  try {
147
- const interactionSelectMenu = interaction;
159
+ const selectMenuInteraction = interaction;
148
160
  const selectMenuManager = this.client.managers.selectMenus;
149
161
  if (!selectMenuManager)
150
162
  return;
151
- const selectMenu = selectMenuManager.getByCustomId(interactionSelectMenu.customId) || selectMenuManager.getByRegex(interactionSelectMenu.customId);
163
+ const selectMenu = selectMenuManager.getByCustomId(selectMenuInteraction.customId) || selectMenuManager.getByRegex(selectMenuInteraction.customId);
152
164
  if (!selectMenu)
153
165
  return;
154
166
  if (this.client.environment.areEnvironmentsEnabled) {
155
- await selectMenu.execute(this.client, this.environment, interactionSelectMenu);
156
- return;
167
+ const selectMenuWithEnv = selectMenu;
168
+ await selectMenuWithEnv.execute(this.client, this.environment, selectMenuInteraction);
169
+ }
170
+ else {
171
+ const modalWithoutEnv = selectMenu;
172
+ await modalWithoutEnv.execute(this.client, selectMenuInteraction);
157
173
  }
158
- await selectMenu.execute(this.client, interactionSelectMenu);
159
174
  }
160
175
  catch (error) {
161
176
  console.error(error);
@@ -170,10 +185,13 @@ export class StelliaUtils {
170
185
  if (!messageContextMenu)
171
186
  return;
172
187
  if (this.client.environment.areEnvironmentsEnabled) {
173
- await messageContextMenu.execute(this.client, this.environment, interaction);
174
- return;
188
+ const messageContextMenuWithEnv = messageContextMenu;
189
+ await messageContextMenuWithEnv.execute(this.client, this.environment, interaction);
190
+ }
191
+ else {
192
+ const messageContextMenuWithoutEnv = messageContextMenu;
193
+ await messageContextMenuWithoutEnv.execute(this.client, interaction);
175
194
  }
176
- await messageContextMenu.execute(this.client, interaction);
177
195
  }
178
196
  catch (error) {
179
197
  console.error(error);
@@ -188,10 +206,13 @@ export class StelliaUtils {
188
206
  if (!userContextMenu)
189
207
  return;
190
208
  if (this.client.environment.areEnvironmentsEnabled) {
191
- await userContextMenu.execute(this.client, this.environment, interaction);
192
- return;
209
+ const userContextMenuWithEnv = userContextMenu;
210
+ await userContextMenuWithEnv.execute(this.client, this.environment, interaction);
211
+ }
212
+ else {
213
+ const userContextMenuWithoutEnv = userContextMenu;
214
+ await userContextMenuWithoutEnv.execute(this.client, interaction);
193
215
  }
194
- await userContextMenu.execute(this.client, interaction);
195
216
  }
196
217
  catch (error) {
197
218
  console.error(error);
@@ -9,12 +9,13 @@ export class EventManager extends BaseManager {
9
9
  async loadData() {
10
10
  const events = await requiredFiles(this.directoryPath);
11
11
  this.interactions = events;
12
- for (const event of this.interactions.values()) {
13
- const { name, once } = event.data;
12
+ for (const eventStructure of this.interactions.values()) {
13
+ const { name, once } = eventStructure.data;
14
14
  if (this.client.environment.areEnvironmentsEnabled) {
15
15
  const environment = await this.client.getEnvironment();
16
+ const event = eventStructure;
16
17
  if (name == Events.ClientReady) {
17
- this.client.once(name, () => event.execute(this.client, environment));
18
+ this.client.once(Events.ClientReady, () => event.execute(this.client, environment));
18
19
  continue;
19
20
  }
20
21
  if (once) {
@@ -25,6 +26,7 @@ export class EventManager extends BaseManager {
25
26
  }
26
27
  }
27
28
  else {
29
+ const event = eventStructure;
28
30
  if (name == Events.ClientReady) {
29
31
  this.client.once(name, () => event.execute(this.client));
30
32
  continue;
@@ -1,14 +1,19 @@
1
1
  import { type Awaitable, type ClientEvents } from "discord.js";
2
2
  import { type StelliaClient } from "../client/index.js";
3
- import type { EnvironmentConfiguration } from "../typescript/types.js";
4
- export interface EventStructure<Event extends keyof ClientEvents = keyof ClientEvents> {
5
- data: {
6
- name: Event;
7
- once: boolean;
8
- };
9
- execute(client: StelliaClient): Awaitable<unknown>;
10
- execute(...args: ClientEvents[Event]): Awaitable<unknown>;
3
+ import { type EnvironmentConfiguration } from "../typescript/types.js";
4
+ export interface EventStructureWithEnvironment extends EventInteractionStructure {
5
+ execute(client: StelliaClient, environment: EnvironmentConfiguration, ...args: ClientEvents[Event]): Awaitable<unknown>;
6
+ }
7
+ export interface EventStructureWithoutEnvironment extends EventInteractionStructure {
11
8
  execute(client: StelliaClient, ...args: ClientEvents[Event]): Awaitable<unknown>;
12
- execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment): Awaitable<unknown>;
13
- execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment, ...args: ClientEvents[Event]): Awaitable<unknown>;
14
9
  }
10
+ export type EventStructure = EventStructureWithEnvironment | EventStructureWithoutEnvironment;
11
+ interface EventInteractionStructure {
12
+ data: EventDataStructure;
13
+ }
14
+ interface EventDataStructure {
15
+ name: Event;
16
+ once: boolean;
17
+ }
18
+ type Event = keyof ClientEvents;
19
+ export {};
@@ -1,39 +1,64 @@
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";
1
+ import { type AnySelectMenuInteraction, type AutocompleteInteraction, type Awaitable, type ButtonInteraction, type ChatInputCommandInteraction, type ContextMenuCommandType, type MessageContextMenuCommandInteraction, type ModalSubmitInteraction, type SlashCommandOptionsOnlyBuilder, type UserContextMenuCommandInteraction } from "discord.js";
2
2
  import { type StelliaClient } from "../client/index.js";
3
3
  import { type EnvironmentConfiguration } from "../typescript/index.js";
4
4
  import { type EventStructure } from "./Event.js";
5
- export interface AutoCompleteStructure {
6
- data: DefaultDataStructure;
5
+ export interface AutoCompleteStructureWithEnvironment extends MessageInteractionStructure {
6
+ execute(client: StelliaClient, environment: EnvironmentConfiguration, interaction: AutocompleteInteraction<"cached">): Awaitable<unknown>;
7
+ }
8
+ export interface AutoCompleteStructureWithoutEnvironment extends MessageInteractionStructure {
7
9
  execute(client: StelliaClient, interaction: AutocompleteInteraction<"cached">): Awaitable<unknown>;
8
- execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment, interaction: AutocompleteInteraction<"cached">): Awaitable<unknown>;
9
10
  }
10
- export interface ButtonStructure {
11
- data: DefaultDataStructure;
11
+ export type AutoCompleteStructure = AutoCompleteStructureWithEnvironment | AutoCompleteStructureWithoutEnvironment;
12
+ export interface ButtonStructureWithEnvironment extends MessageInteractionStructure {
13
+ execute(client: StelliaClient, environment: EnvironmentConfiguration, interaction: ButtonInteraction<"cached">): Awaitable<unknown>;
14
+ }
15
+ export interface ButtonStructureWithoutEnvironment extends MessageInteractionStructure {
12
16
  execute(client: StelliaClient, interaction: ButtonInteraction<"cached">): Awaitable<unknown>;
13
- execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment, interaction: ButtonInteraction<"cached">): Awaitable<unknown>;
14
17
  }
15
- export interface CommandStructure {
16
- data: SlashCommandBuilder;
18
+ export type ButtonStructure = ButtonStructureWithEnvironment | ButtonStructureWithoutEnvironment;
19
+ export interface CommandStructureWithEnvironment extends CommandInteractionStructure {
20
+ execute(client: StelliaClient, environment: EnvironmentConfiguration, interaction: ChatInputCommandInteraction<"cached">): Awaitable<unknown>;
21
+ }
22
+ export interface CommandStructureWithoutEnvironment extends CommandInteractionStructure {
17
23
  execute(client: StelliaClient, interaction: ChatInputCommandInteraction<"cached">): Awaitable<unknown>;
18
- execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment, interaction: ChatInputCommandInteraction<"cached">): Awaitable<unknown>;
19
24
  }
20
- export interface ContextMenuStructure {
21
- data: ContextMenuCommandBuilder;
25
+ export type CommandStructure = CommandStructureWithEnvironment | CommandStructureWithoutEnvironment;
26
+ export interface ContextMenuStructureWithEnvironment extends ContextMenuInteractionStructure {
27
+ execute(client: StelliaClient, environment: EnvironmentConfiguration, interaction: MessageContextMenuCommandInteraction<"cached"> | UserContextMenuCommandInteraction<"cached">): Awaitable<unknown>;
28
+ }
29
+ export interface ContextMenuStructureWithoutEnvironment extends ContextMenuInteractionStructure {
22
30
  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>;
24
31
  }
25
- export interface ModalStructure {
26
- data: DefaultDataStructure;
32
+ export type ContextMenuStructure = ContextMenuStructureWithEnvironment | ContextMenuStructureWithoutEnvironment;
33
+ export interface ModalStructureWithEnvironment extends MessageInteractionStructure {
34
+ execute(client: StelliaClient, environment: EnvironmentConfiguration, interaction: ModalSubmitInteraction<"cached">): Awaitable<unknown>;
35
+ }
36
+ export interface ModalStructureWithoutEnvironment extends MessageInteractionStructure {
27
37
  execute(client: StelliaClient, interaction: ModalSubmitInteraction<"cached">): Awaitable<unknown>;
28
- execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment, interaction: ModalSubmitInteraction<"cached">): Awaitable<unknown>;
29
38
  }
30
- export interface SelectMenuStructure {
31
- data: DefaultDataStructure;
39
+ export type ModalStructure = ModalStructureWithEnvironment | ModalStructureWithoutEnvironment;
40
+ export interface SelectMenuStructureWithEnvironment extends MessageInteractionStructure {
41
+ execute(client: StelliaClient, environment: EnvironmentConfiguration, interaction: AnySelectMenuInteraction<"cached">): Awaitable<unknown>;
42
+ }
43
+ export interface SelectMenuStructureWithoutEnvironment extends MessageInteractionStructure {
32
44
  execute(client: StelliaClient, interaction: AnySelectMenuInteraction<"cached">): Awaitable<unknown>;
33
- execute<CustomEnvironment extends EnvironmentConfiguration>(client: StelliaClient, environment: CustomEnvironment, interaction: AnySelectMenuInteraction<"cached">): Awaitable<unknown>;
34
45
  }
46
+ export type SelectMenuStructure = SelectMenuStructureWithEnvironment | SelectMenuStructureWithoutEnvironment;
35
47
  export type AnyInteractionStructure = AutoCompleteStructure | ButtonStructure | CommandStructure | ContextMenuStructure | EventStructure | ModalStructure | SelectMenuStructure;
36
- interface DefaultDataStructure {
48
+ interface CommandInteractionStructure {
49
+ data: SlashCommandOptionsOnlyBuilder;
50
+ }
51
+ interface ContextMenuInteractionStructure {
52
+ data: ContextMenuDataStructure;
53
+ }
54
+ interface ContextMenuDataStructure {
55
+ name: string;
56
+ type: ContextMenuCommandType;
57
+ }
58
+ interface MessageInteractionStructure {
59
+ data: MessageDataStructure;
60
+ }
61
+ interface MessageDataStructure {
37
62
  name: string | RegExp;
38
63
  once: boolean;
39
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stelliajs/framework",
3
- "version": "1.2.3",
3
+ "version": "1.3.0-dev-1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "scripts": {
@@ -15,12 +15,13 @@
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.119",
19
- "discord.js": "^14.18.0"
18
+ "discord-api-types": "^0.38.2",
19
+ "discord.js": "^14.19.3"
20
20
  },
21
21
  "devDependencies": {
22
22
  "ts-node": "^10.9.2",
23
- "tsc-alias": "^1.8.10"
23
+ "tsc-alias": "^1.8.15"
24
24
  },
25
- "type": "module"
25
+ "type": "module",
26
+ "packageManager": "pnpm@10.10.0"
26
27
  }