@stelliajs/framework 1.2.0 → 1.2.3

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 currently being developed and will soon be available for even greater convenience.
6
+ A CLI is available to help you set up a project with StelliaJS : [link to the CLI](https://github.com/StelliaJS/cli)
7
7
 
8
8
  ## Architecture
9
9
  Recommended architecture for StelliaJS project.
@@ -19,6 +19,10 @@ 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
22
26
  │ ├── events/
23
27
  │ │ ├── ready.ts
24
28
  │ │ └── interactionCreate.ts
@@ -36,16 +40,17 @@ Recommended architecture for StelliaJS project.
36
40
  ├── .env
37
41
  ├── package.json
38
42
  ├── package-lock.json
43
+ ├── stellia.json
39
44
  └── tsconfig.json
40
45
  ```
46
+
41
47
  ## Examples
42
48
 
43
- ### Simple client
49
+ ### Simple client with environment
44
50
 
45
51
  ```js
46
52
  import { StelliaClient } from "@stelliajs/framework";
47
- import { GatewayIntentBits } from "discord-api-types/v10";
48
- import { Partials } from "discord.js";
53
+ import { GatewayIntentBits, Partials } from "discord.js";
49
54
 
50
55
  const client = new StelliaClient({
51
56
  intents: [
@@ -56,26 +61,31 @@ const client = new StelliaClient({
56
61
  ],
57
62
  partials: [Partials.Message, Partials.GuildMember]
58
63
  }, {
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"
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
+ }
76
86
  },
77
- selectMenus: {
78
- directoryPath: "./interactions/selectMenus"
87
+ environment: {
88
+ areEnvironmentsEnabled: true
79
89
  }
80
90
  });
81
91
 
@@ -84,34 +94,36 @@ await client.connect(process.env.TOKEN);
84
94
 
85
95
  ### Simple event
86
96
 
87
- #### Ready event
97
+ #### Ready event with environment
88
98
  ```js
89
99
  import { type StelliaClient, type EventStructure } from "@stelliajs/framework";
90
100
  import { Events } from "discord.js";
101
+ import { type CustomEnvironment } from "@environments/environment.model.ts";
91
102
 
92
103
  export default {
93
104
  data: {
94
105
  name: Events.ClientReady,
95
106
  once: true
96
107
  },
97
- async execute(client: StelliaClient<true>) { // <true> ensures that the client is Ready
108
+ async execute(client: StelliaClient<true>, environment: CustomEnvironment) { // <true> ensures that the client is Ready
98
109
  console.log(`Logged in as ${client.user.tag}`);
99
110
  await client.initializeCommands(); // Used to initialise registered commands
100
111
  }
101
112
  } as EventStructure;
102
113
  ```
103
114
 
104
- #### InteractionCreate event
115
+ #### InteractionCreate event with environment
105
116
  ```js
106
117
  import { type StelliaClient, type EventStructure } from "@stelliajs/framework";
107
118
  import { Events, type Interaction } from "discord.js";
119
+ import { type CustomEnvironment } from "@environments/environment.model.ts";
108
120
 
109
121
  export default {
110
122
  data: {
111
123
  name: Events.InteractionCreate,
112
124
  once: false
113
125
  },
114
- async execute(client: StelliaClient<true>, interaction: Interaction) {
126
+ async execute(client: StelliaClient<true>, environment: CustomEnvironment, interaction: Interaction) {
115
127
  if (interaction.inCachedGuild()) {
116
128
  await client.handleInteraction(interaction); // Automatic interaction handling
117
129
  }
@@ -124,11 +136,12 @@ export default {
124
136
  ```js
125
137
  import { type CommandStructure, ephemeralFollowUpResponse, type StelliaClient } from "@stelliajs/framework";
126
138
  import { type ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
139
+ import { type CustomEnvironment } from "@environments/environment.model.ts";
127
140
 
128
141
  export default {
129
142
  data: new SlashCommandBuilder()
130
143
  .setName("ping"),
131
- async execute(client: StelliaClient, interaction: ChatInputCommandInteraction<"cached">) { // All interactions are cached
144
+ async execute(client: StelliaClient, environment: CustomEnvironment, interaction: ChatInputCommandInteraction<"cached">) { // All interactions are cached
132
145
  await ephemeralFollowUpResponse(interaction, "Pong!", true); // Response is ephemeral and deleted after 60 seconds
133
146
  }
134
147
  } as CommandStructure;
@@ -1,6 +1,6 @@
1
- import { Client, type ClientOptions } from "discord.js";
1
+ import { Client, type ClientOptions, type Interaction } from "discord.js";
2
2
  import { type ManagerOptions } from "../managers/index.js";
3
- import { type AnyInteraction, type Environment, type EnvironmentConfiguration, type Managers } from "../typescript/index.js";
3
+ import { 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;
@@ -9,7 +9,7 @@ export declare class StelliaClient<Ready extends boolean = boolean> extends Clie
9
9
  connect: (token: string) => Promise<void>;
10
10
  initializeCommands: () => Promise<void>;
11
11
  getEnvironment: <CustomEnvironment extends EnvironmentConfiguration>() => Promise<CustomEnvironment>;
12
- handleInteraction: (interaction: AnyInteraction) => Promise<void>;
12
+ handleInteraction: (interaction: Interaction<"cached">) => Promise<void>;
13
13
  private areManagersLoaded;
14
14
  private static convertFilePathToProduction;
15
15
  }
@@ -1,12 +1,12 @@
1
1
  import { type StelliaClient } from "./index.js";
2
- import { type AnyInteraction } from "../typescript/index.js";
2
+ import { type Interaction } from "discord.js";
3
3
  export declare class StelliaUtils {
4
4
  readonly client: StelliaClient;
5
5
  private readonly interactionHandlers;
6
6
  private environment;
7
7
  constructor(client: StelliaClient);
8
8
  initializeCommands: () => Promise<void>;
9
- handleInteraction: (interaction: AnyInteraction) => Promise<void>;
9
+ handleInteraction: (interaction: Interaction<"cached">) => Promise<void>;
10
10
  private handleAutoCompleteInteraction;
11
11
  private handleButtonInteraction;
12
12
  private handleCommandInteraction;
@@ -15,7 +15,7 @@ export class StelliaUtils {
15
15
  [InteractionType.ModalSubmit, this.handleModalInteraction],
16
16
  [InteractionType.SelectMenu, this.handleSelectMenuInteraction]
17
17
  ]);
18
- if (this.client.environment.isEnvironmentsEnabled) {
18
+ if (this.client.environment.areEnvironmentsEnabled) {
19
19
  this.client.getEnvironment()
20
20
  .then((environment) => {
21
21
  this.environment = environment;
@@ -59,7 +59,7 @@ export class StelliaUtils {
59
59
  const autoComplete = autoCompleteManager.getByCustomId(interactionAutoComplete.commandName);
60
60
  if (!autoComplete)
61
61
  return;
62
- if (this.client.environment.isEnvironmentsEnabled) {
62
+ if (this.client.environment.areEnvironmentsEnabled) {
63
63
  await autoComplete.execute(this.client, this.environment, interactionAutoComplete);
64
64
  return;
65
65
  }
@@ -78,7 +78,7 @@ export class StelliaUtils {
78
78
  const button = buttonManager.getByCustomId(buttonInteraction.customId) || buttonManager.getByRegex(buttonInteraction.customId);
79
79
  if (!button)
80
80
  return;
81
- if (this.client.environment.isEnvironmentsEnabled) {
81
+ if (this.client.environment.areEnvironmentsEnabled) {
82
82
  await button.execute(this.client, this.environment, buttonInteraction);
83
83
  return;
84
84
  }
@@ -97,7 +97,7 @@ export class StelliaUtils {
97
97
  const command = commandManager.getByCustomId(interactionCommand.commandName);
98
98
  if (!command)
99
99
  return;
100
- if (this.client.environment.isEnvironmentsEnabled) {
100
+ if (this.client.environment.areEnvironmentsEnabled) {
101
101
  await command.execute(this.client, this.environment, interactionCommand);
102
102
  return;
103
103
  }
@@ -132,7 +132,7 @@ export class StelliaUtils {
132
132
  const modal = modalManager.getByCustomId(interactionModal.customId) || modalManager.getByRegex(interactionModal.customId);
133
133
  if (!modal)
134
134
  return;
135
- if (this.client.environment.isEnvironmentsEnabled) {
135
+ if (this.client.environment.areEnvironmentsEnabled) {
136
136
  await modal.execute(this.client, this.environment, interactionModal);
137
137
  return;
138
138
  }
@@ -151,7 +151,7 @@ export class StelliaUtils {
151
151
  const selectMenu = selectMenuManager.getByCustomId(interactionSelectMenu.customId) || selectMenuManager.getByRegex(interactionSelectMenu.customId);
152
152
  if (!selectMenu)
153
153
  return;
154
- if (this.client.environment.isEnvironmentsEnabled) {
154
+ if (this.client.environment.areEnvironmentsEnabled) {
155
155
  await selectMenu.execute(this.client, this.environment, interactionSelectMenu);
156
156
  return;
157
157
  }
@@ -169,7 +169,7 @@ export class StelliaUtils {
169
169
  const messageContextMenu = contextMenuManager.getByCustomId(interaction.commandName);
170
170
  if (!messageContextMenu)
171
171
  return;
172
- if (this.client.environment.isEnvironmentsEnabled) {
172
+ if (this.client.environment.areEnvironmentsEnabled) {
173
173
  await messageContextMenu.execute(this.client, this.environment, interaction);
174
174
  return;
175
175
  }
@@ -187,7 +187,7 @@ export class StelliaUtils {
187
187
  const userContextMenu = contextMenuManager.getByCustomId(interaction.commandName);
188
188
  if (!userContextMenu)
189
189
  return;
190
- if (this.client.environment.isEnvironmentsEnabled) {
190
+ if (this.client.environment.areEnvironmentsEnabled) {
191
191
  await userContextMenu.execute(this.client, this.environment, interaction);
192
192
  return;
193
193
  }
@@ -11,11 +11,30 @@ export class EventManager extends BaseManager {
11
11
  this.interactions = events;
12
12
  for (const event of this.interactions.values()) {
13
13
  const { name, once } = event.data;
14
- if (once) {
15
- this.client.once(name, (...args) => event.execute(this.client, ...args));
14
+ if (this.client.environment.areEnvironmentsEnabled) {
15
+ const environment = await this.client.getEnvironment();
16
+ if (name == Events.ClientReady) {
17
+ this.client.once(name, () => event.execute(this.client, environment));
18
+ continue;
19
+ }
20
+ if (once) {
21
+ this.client.once(name, (...args) => event.execute(this.client, environment, ...args));
22
+ }
23
+ else {
24
+ this.client.on(name, (...args) => event.execute(this.client, environment, ...args));
25
+ }
16
26
  }
17
27
  else {
18
- this.client.on(name, (...args) => event.execute(this.client, ...args));
28
+ if (name == Events.ClientReady) {
29
+ this.client.once(name, () => event.execute(this.client));
30
+ continue;
31
+ }
32
+ if (once) {
33
+ this.client.once(name, (...args) => event.execute(this.client, ...args));
34
+ }
35
+ else {
36
+ this.client.on(name, (...args) => event.execute(this.client, ...args));
37
+ }
19
38
  }
20
39
  }
21
40
  this.client.on(Events.Error, (error) => console.error(error));
@@ -1,9 +1,14 @@
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";
3
4
  export interface EventStructure<Event extends keyof ClientEvents = keyof ClientEvents> {
4
5
  data: {
5
6
  name: Event;
6
7
  once: boolean;
7
8
  };
9
+ execute(client: StelliaClient): Awaitable<unknown>;
10
+ execute(...args: ClientEvents[Event]): Awaitable<unknown>;
8
11
  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>;
9
14
  }
@@ -1,8 +1,6 @@
1
- import { type AnySelectMenuInteraction, type AutocompleteInteraction, type ButtonInteraction, type ChatInputCommandInteraction, type ContextMenuCommandInteraction, type ModalSubmitInteraction, type UserContextMenuCommandInteraction } from "discord.js";
2
1
  import { type AutoCompleteManager, type ButtonManager, type CommandManager, type ContextMenuManager, type EventManager, type ModalManager, type SelectMenuManager } from "../managers/index.js";
3
2
  export type StructureCustomId = string | RegExp;
4
3
  export type InteractionCustomId = string;
5
- export type AnyInteraction = AutocompleteInteraction<"cached"> | ButtonInteraction<"cached"> | ChatInputCommandInteraction<"cached"> | ContextMenuCommandInteraction<"cached"> | ModalSubmitInteraction<"cached"> | AnySelectMenuInteraction<"cached"> | UserContextMenuCommandInteraction<"cached">;
6
4
  export declare enum InteractionType {
7
5
  Autocomplete = "Autocomplete",
8
6
  Button = "Button",
@@ -23,7 +21,7 @@ export interface Managers {
23
21
  modals?: ModalManager;
24
22
  }
25
23
  export interface Environment {
26
- isEnvironmentsEnabled: boolean;
24
+ areEnvironmentsEnabled: boolean;
27
25
  }
28
26
  export interface EnvironmentConfiguration {
29
27
  [key: string]: unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stelliajs/framework",
3
- "version": "1.2.0",
3
+ "version": "1.2.3",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "scripts": {
@@ -16,7 +16,7 @@
16
16
  "keywords": ["discord", "bot", "discordjs", "typescript", "framework"],
17
17
  "dependencies": {
18
18
  "discord-api-types": "^0.37.119",
19
- "discord.js": "^14.17.3"
19
+ "discord.js": "^14.18.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "ts-node": "^10.9.2",