@stelliajs/framework 1.1.3 → 1.2.0-dev-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,22 +1,28 @@
|
|
|
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;
|
|
14
|
+
private static convertFilePathToProduction;
|
|
12
15
|
}
|
|
13
16
|
interface StelliaOptions {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
managers: {
|
|
18
|
+
autoCompletes?: ManagerOptions;
|
|
19
|
+
buttons?: ManagerOptions;
|
|
20
|
+
commands?: ManagerOptions;
|
|
21
|
+
contextMenus?: ManagerOptions;
|
|
22
|
+
events?: ManagerOptions;
|
|
23
|
+
selectMenus?: ManagerOptions;
|
|
24
|
+
modals?: ManagerOptions;
|
|
25
|
+
};
|
|
26
|
+
environment?: Environment;
|
|
21
27
|
}
|
|
22
28
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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?.
|
|
14
|
-
this.managers.
|
|
19
|
+
if (stelliaOptions?.managers.commands?.directoryPath) {
|
|
20
|
+
this.managers.commands = new CommandManager(this, stelliaOptions.managers.commands.directoryPath);
|
|
15
21
|
}
|
|
16
|
-
if (stelliaOptions?.
|
|
17
|
-
this.managers.
|
|
22
|
+
if (stelliaOptions?.managers.contextMenus?.directoryPath) {
|
|
23
|
+
this.managers.contextMenus = new ContextMenuManager(this, stelliaOptions.managers.contextMenus.directoryPath);
|
|
18
24
|
}
|
|
19
|
-
if (stelliaOptions?.
|
|
20
|
-
this.managers.
|
|
25
|
+
if (stelliaOptions?.managers.events?.directoryPath) {
|
|
26
|
+
this.managers.events = new EventManager(this, stelliaOptions.managers.events.directoryPath);
|
|
21
27
|
}
|
|
22
|
-
if (stelliaOptions?.
|
|
23
|
-
this.managers.
|
|
28
|
+
if (stelliaOptions?.managers.selectMenus?.directoryPath) {
|
|
29
|
+
this.managers.selectMenus = new SelectMenuManager(this, stelliaOptions.managers.selectMenus.directoryPath);
|
|
24
30
|
}
|
|
25
|
-
if (stelliaOptions?.
|
|
26
|
-
this.managers.
|
|
31
|
+
if (stelliaOptions?.managers.modals?.directoryPath) {
|
|
32
|
+
this.managers.modals = new ModalManager(this, stelliaOptions.managers.modals.directoryPath);
|
|
27
33
|
}
|
|
28
|
-
if (stelliaOptions?.
|
|
29
|
-
this.
|
|
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,35 @@ 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 environmentData = environments[chosenEnvironment];
|
|
74
|
+
const environmentPath = environmentData.production ? StelliaClient.convertFilePathToProduction(environmentData.file) : environmentData.file;
|
|
75
|
+
const environmentAbsolutePath = pathToFileURL(path.join(srcPath, "..", environmentPath)).href;
|
|
76
|
+
const environmentFile = await import(environmentAbsolutePath);
|
|
77
|
+
resolve(environmentFile.environment);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
reject(error);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
};
|
|
49
85
|
handleInteraction = async (interaction) => {
|
|
50
86
|
await this.utils.handleInteraction(interaction);
|
|
51
87
|
};
|
|
@@ -53,4 +89,7 @@ export class StelliaClient extends Client {
|
|
|
53
89
|
const managers = Object.values(this.managers);
|
|
54
90
|
return managers.length === 0 ? true : managers.every((manager) => manager.isManagerLoaded());
|
|
55
91
|
};
|
|
92
|
+
static convertFilePathToProduction = (filePath) => {
|
|
93
|
+
return filePath.replace("src", "dist").replace(".ts", ".js");
|
|
94
|
+
};
|
|
56
95
|
}
|
|
@@ -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,14 @@ 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
|
+
console.log("Environment loaded");
|
|
23
|
+
})
|
|
24
|
+
.catch((error) => console.error(error));
|
|
25
|
+
}
|
|
17
26
|
}
|
|
18
27
|
initializeCommands = async () => {
|
|
19
28
|
const commands = this.client.managers.commands?.getAll().values();
|
|
@@ -50,6 +59,10 @@ export class StelliaUtils {
|
|
|
50
59
|
const autoComplete = autoCompleteManager.getByCustomId(interactionAutoComplete.commandName);
|
|
51
60
|
if (!autoComplete)
|
|
52
61
|
return;
|
|
62
|
+
if (this.client.environment.isEnvironmentsEnabled) {
|
|
63
|
+
await autoComplete.execute(this.client, this.environment, interactionAutoComplete);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
53
66
|
await autoComplete.execute(this.client, interactionAutoComplete);
|
|
54
67
|
}
|
|
55
68
|
catch (error) {
|
|
@@ -65,6 +78,10 @@ export class StelliaUtils {
|
|
|
65
78
|
const button = buttonManager.getByCustomId(buttonInteraction.customId) || buttonManager.getByRegex(buttonInteraction.customId);
|
|
66
79
|
if (!button)
|
|
67
80
|
return;
|
|
81
|
+
if (this.client.environment.isEnvironmentsEnabled) {
|
|
82
|
+
await button.execute(this.client, this.environment, buttonInteraction);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
68
85
|
await button.execute(this.client, buttonInteraction);
|
|
69
86
|
}
|
|
70
87
|
catch (error) {
|
|
@@ -80,6 +97,10 @@ export class StelliaUtils {
|
|
|
80
97
|
const command = commandManager.getByCustomId(interactionCommand.commandName);
|
|
81
98
|
if (!command)
|
|
82
99
|
return;
|
|
100
|
+
if (this.client.environment.isEnvironmentsEnabled) {
|
|
101
|
+
await command.execute(this.client, this.environment, interactionCommand);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
83
104
|
await command.execute(this.client, interactionCommand);
|
|
84
105
|
}
|
|
85
106
|
catch (error) {
|
|
@@ -111,6 +132,10 @@ export class StelliaUtils {
|
|
|
111
132
|
const modal = modalManager.getByCustomId(interactionModal.customId) || modalManager.getByRegex(interactionModal.customId);
|
|
112
133
|
if (!modal)
|
|
113
134
|
return;
|
|
135
|
+
if (this.client.environment.isEnvironmentsEnabled) {
|
|
136
|
+
await modal.execute(this.client, this.environment, interactionModal);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
114
139
|
await modal.execute(this.client, interactionModal);
|
|
115
140
|
}
|
|
116
141
|
catch (error) {
|
|
@@ -126,6 +151,10 @@ export class StelliaUtils {
|
|
|
126
151
|
const selectMenu = selectMenuManager.getByCustomId(interactionSelectMenu.customId) || selectMenuManager.getByRegex(interactionSelectMenu.customId);
|
|
127
152
|
if (!selectMenu)
|
|
128
153
|
return;
|
|
154
|
+
if (this.client.environment.isEnvironmentsEnabled) {
|
|
155
|
+
await selectMenu.execute(this.client, this.environment, interactionSelectMenu);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
129
158
|
await selectMenu.execute(this.client, interactionSelectMenu);
|
|
130
159
|
}
|
|
131
160
|
catch (error) {
|
|
@@ -140,6 +169,10 @@ export class StelliaUtils {
|
|
|
140
169
|
const messageContextMenu = contextMenuManager.getByCustomId(interaction.commandName);
|
|
141
170
|
if (!messageContextMenu)
|
|
142
171
|
return;
|
|
172
|
+
if (this.client.environment.isEnvironmentsEnabled) {
|
|
173
|
+
await messageContextMenu.execute(this.client, this.environment, interaction);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
143
176
|
await messageContextMenu.execute(this.client, interaction);
|
|
144
177
|
}
|
|
145
178
|
catch (error) {
|
|
@@ -154,6 +187,10 @@ export class StelliaUtils {
|
|
|
154
187
|
const userContextMenu = contextMenuManager.getByCustomId(interaction.commandName);
|
|
155
188
|
if (!userContextMenu)
|
|
156
189
|
return;
|
|
190
|
+
if (this.client.environment.isEnvironmentsEnabled) {
|
|
191
|
+
await userContextMenu.execute(this.client, this.environment, interaction);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
157
194
|
await userContextMenu.execute(this.client, interaction);
|
|
158
195
|
}
|
|
159
196
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stelliajs/framework",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-dev-2",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -15,7 +15,7 @@
|
|
|
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.
|
|
18
|
+
"discord-api-types": "^0.37.119",
|
|
19
19
|
"discord.js": "^14.17.3"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|