@stelliajs/framework 1.1.3 → 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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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,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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stelliajs/framework",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.0-dev-1",
|
|
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": {
|