@stelliajs/framework 1.4.6 → 1.5.0
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/.prettierrc +6 -10
- package/dist/client/StelliaClient.js +7 -3
- package/dist/client/StelliaUtils.js +20 -2
- package/dist/structures/Interaction.d.ts +18 -4
- package/dist/utils/files.js +4 -3
- package/dist/utils/translation.js +3 -3
- package/eslint.config.mjs +68 -0
- package/package.json +10 -11
package/.prettierrc
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"useTabs": true,
|
|
9
|
-
"tabWidth": 2,
|
|
10
|
-
"trailingComma": "none",
|
|
11
|
-
"printWidth": 100
|
|
2
|
+
"semi": true,
|
|
3
|
+
"singleQuote": false,
|
|
4
|
+
"useTabs": true,
|
|
5
|
+
"tabWidth": 2,
|
|
6
|
+
"trailingComma": "none",
|
|
7
|
+
"printWidth": 100
|
|
12
8
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
-
import { Client } from "discord.js";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import { pathToFileURL } from "url";
|
|
4
|
+
import { Client } from "discord.js";
|
|
5
5
|
import { StelliaUtils } from "./index.js";
|
|
6
6
|
import { AutoCompleteManager, ButtonManager, CommandManager, ContextMenuManager, EventManager, ModalManager, SelectMenuManager } from "../managers/index.js";
|
|
7
7
|
import { logger } from "../utils/logger.js";
|
|
@@ -75,7 +75,9 @@ export class StelliaClient extends Client {
|
|
|
75
75
|
return reject(new Error("Invalid environment"));
|
|
76
76
|
}
|
|
77
77
|
const environmentData = environments[chosenEnvironment];
|
|
78
|
-
const environmentPath = environmentData.production
|
|
78
|
+
const environmentPath = environmentData.production
|
|
79
|
+
? StelliaClient.convertFilePathToProduction(environmentData.file)
|
|
80
|
+
: environmentData.file;
|
|
79
81
|
const environmentAbsolutePath = pathToFileURL(path.join(srcPath, "..", environmentPath)).href;
|
|
80
82
|
const environmentFile = await import(environmentAbsolutePath);
|
|
81
83
|
resolve(environmentFile.environment);
|
|
@@ -94,7 +96,9 @@ export class StelliaClient extends Client {
|
|
|
94
96
|
};
|
|
95
97
|
areManagersLoaded = () => {
|
|
96
98
|
const managers = Object.values(this.managers);
|
|
97
|
-
return managers.length === 0
|
|
99
|
+
return managers.length === 0
|
|
100
|
+
? true
|
|
101
|
+
: managers.every((manager) => manager.isManagerLoaded());
|
|
98
102
|
};
|
|
99
103
|
static convertFilePathToProduction = (filePath) => {
|
|
100
104
|
return filePath.replace("src", "dist").replace(".ts", ".js");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApplicationCommandType, REST, Routes } from "discord.js";
|
|
1
|
+
import { ApplicationCommandType, MessageFlags, REST, Routes } from "discord.js";
|
|
2
2
|
import { DISCORD_API_VERSION } from "../constants/index.js";
|
|
3
3
|
import { InteractionType } from "../typescript/index.js";
|
|
4
4
|
import { logger } from "../utils/logger.js";
|
|
@@ -99,6 +99,9 @@ export class StelliaUtils {
|
|
|
99
99
|
buttonManager.getByRegex(buttonInteraction.customId);
|
|
100
100
|
if (!button)
|
|
101
101
|
return;
|
|
102
|
+
if (button.data.reply.autoDefer && !buttonInteraction.deferred) {
|
|
103
|
+
await buttonInteraction.deferReply({ flags: button.data.reply.ephemeral ? MessageFlags.Ephemeral : undefined });
|
|
104
|
+
}
|
|
102
105
|
if (this.client.environment.areGuildsConfigurationEnabled) {
|
|
103
106
|
const buttonWithGuildConfiguration = button;
|
|
104
107
|
const guildConfiguration = this.getGuildConfiguration(buttonInteraction.guildId);
|
|
@@ -119,9 +122,12 @@ export class StelliaUtils {
|
|
|
119
122
|
const commandManager = this.client.managers.commands;
|
|
120
123
|
if (!commandManager)
|
|
121
124
|
return;
|
|
122
|
-
|
|
125
|
+
const command = commandManager.getByCustomId(commandInteraction.commandName);
|
|
123
126
|
if (!command)
|
|
124
127
|
return;
|
|
128
|
+
if (command.data.reply.autoDefer && !commandInteraction.deferred) {
|
|
129
|
+
await commandInteraction.deferReply({ flags: command.data.reply.ephemeral ? MessageFlags.Ephemeral : undefined });
|
|
130
|
+
}
|
|
125
131
|
if (this.client.environment.areGuildsConfigurationEnabled) {
|
|
126
132
|
const commandWithGuildConfiguration = command;
|
|
127
133
|
const guildConfiguration = this.getGuildConfiguration(commandInteraction.guildId);
|
|
@@ -162,6 +168,9 @@ export class StelliaUtils {
|
|
|
162
168
|
modalManager.getByRegex(modalInteraction.customId);
|
|
163
169
|
if (!modal)
|
|
164
170
|
return;
|
|
171
|
+
if (modal.data.reply.autoDefer && !modalInteraction.deferred) {
|
|
172
|
+
await modalInteraction.deferReply({ flags: modal.data.reply.ephemeral ? MessageFlags.Ephemeral : undefined });
|
|
173
|
+
}
|
|
165
174
|
if (this.client.environment.areGuildsConfigurationEnabled) {
|
|
166
175
|
const modalWithGuildConfiguration = modal;
|
|
167
176
|
const guildConfiguration = this.getGuildConfiguration(modalInteraction.guildId);
|
|
@@ -186,6 +195,9 @@ export class StelliaUtils {
|
|
|
186
195
|
selectMenuManager.getByRegex(selectMenuInteraction.customId);
|
|
187
196
|
if (!selectMenu)
|
|
188
197
|
return;
|
|
198
|
+
if (selectMenu.data.reply.autoDefer && !selectMenuInteraction.deferred) {
|
|
199
|
+
await selectMenuInteraction.deferReply({ flags: selectMenu.data.reply.ephemeral ? MessageFlags.Ephemeral : undefined });
|
|
200
|
+
}
|
|
189
201
|
if (this.client.environment.areGuildsConfigurationEnabled) {
|
|
190
202
|
const selectMenuWithGuildConfiguration = selectMenu;
|
|
191
203
|
const guildConfiguration = this.getGuildConfiguration(selectMenuInteraction.guildId);
|
|
@@ -208,6 +220,9 @@ export class StelliaUtils {
|
|
|
208
220
|
const messageContextMenu = contextMenuManager.getByCustomId(interaction.commandName);
|
|
209
221
|
if (!messageContextMenu)
|
|
210
222
|
return;
|
|
223
|
+
if (messageContextMenu.data.reply.autoDefer && !interaction.deferred) {
|
|
224
|
+
await interaction.deferReply({ flags: messageContextMenu.data.reply.ephemeral ? MessageFlags.Ephemeral : undefined });
|
|
225
|
+
}
|
|
211
226
|
if (this.client.environment.areGuildsConfigurationEnabled) {
|
|
212
227
|
const messageContextMenuWithGuildConfiguration = messageContextMenu;
|
|
213
228
|
const guildConfiguration = this.getGuildConfiguration(interaction.guildId);
|
|
@@ -230,6 +245,9 @@ export class StelliaUtils {
|
|
|
230
245
|
const userContextMenu = contextMenuManager.getByCustomId(interaction.commandName);
|
|
231
246
|
if (!userContextMenu)
|
|
232
247
|
return;
|
|
248
|
+
if (userContextMenu.data.reply.autoDefer && !interaction.deferred) {
|
|
249
|
+
await interaction.deferReply({ flags: userContextMenu.data.reply.ephemeral ? MessageFlags.Ephemeral : undefined });
|
|
250
|
+
}
|
|
233
251
|
if (this.client.environment.areGuildsConfigurationEnabled) {
|
|
234
252
|
const userContextMenuWithGuildConfiguration = userContextMenu;
|
|
235
253
|
const guildConfiguration = this.getGuildConfiguration(interaction.guildId);
|
|
@@ -2,10 +2,12 @@ import { type AnySelectMenuInteraction, type AutocompleteInteraction, type Await
|
|
|
2
2
|
import { type StelliaClient } from "../client/index.js";
|
|
3
3
|
import { type EventStructure } from "./Event.js";
|
|
4
4
|
import { type GuildConfigurationType } from "../typescript/index.js";
|
|
5
|
-
export interface AutoCompleteStructureWithGuildConfiguration extends MessageInteractionStructure {
|
|
5
|
+
export interface AutoCompleteStructureWithGuildConfiguration extends Omit<MessageInteractionStructure, "data"> {
|
|
6
|
+
data: Omit<MessageDataStructure, "reply">;
|
|
6
7
|
execute(client: StelliaClient, guildConfiguration: GuildConfigurationType, interaction: AutocompleteInteraction<"cached">): Awaitable<unknown>;
|
|
7
8
|
}
|
|
8
|
-
export interface AutoCompleteStructureWithoutGuildConfiguration extends MessageInteractionStructure {
|
|
9
|
+
export interface AutoCompleteStructureWithoutGuildConfiguration extends Omit<MessageInteractionStructure, "data"> {
|
|
10
|
+
data: Omit<MessageDataStructure, "reply">;
|
|
9
11
|
execute(client: StelliaClient, interaction: AutocompleteInteraction<"cached">): Awaitable<unknown>;
|
|
10
12
|
}
|
|
11
13
|
export type AutoCompleteStructure = AutoCompleteStructureWithGuildConfiguration | AutoCompleteStructureWithoutGuildConfiguration;
|
|
@@ -46,7 +48,11 @@ export interface SelectMenuStructureWithoutGuildConfiguration extends MessageInt
|
|
|
46
48
|
export type SelectMenuStructure = SelectMenuStructureWithGuildConfiguration | SelectMenuStructureWithoutGuildConfiguration;
|
|
47
49
|
export type AnyInteractionStructure = AutoCompleteStructure | ButtonStructure | CommandStructure | ContextMenuStructure | EventStructure | ModalStructure | SelectMenuStructure;
|
|
48
50
|
interface CommandInteractionStructure {
|
|
49
|
-
data:
|
|
51
|
+
data: CommandDataStructure;
|
|
52
|
+
}
|
|
53
|
+
interface CommandDataStructure {
|
|
54
|
+
command: SlashCommandOptionsOnlyBuilder | SlashCommandSubcommandsOnlyBuilder;
|
|
55
|
+
reply: ReplyStructure<true> | ReplyStructure<false>;
|
|
50
56
|
}
|
|
51
57
|
interface ContextMenuInteractionStructure {
|
|
52
58
|
data: ContextMenuDataStructure;
|
|
@@ -54,6 +60,7 @@ interface ContextMenuInteractionStructure {
|
|
|
54
60
|
interface ContextMenuDataStructure {
|
|
55
61
|
name: string;
|
|
56
62
|
type: ContextMenuCommandType;
|
|
63
|
+
reply: ReplyStructure<true> | ReplyStructure<false>;
|
|
57
64
|
}
|
|
58
65
|
interface MessageInteractionStructure {
|
|
59
66
|
data: MessageDataStructure;
|
|
@@ -61,5 +68,12 @@ interface MessageInteractionStructure {
|
|
|
61
68
|
interface MessageDataStructure {
|
|
62
69
|
name: string | RegExp;
|
|
63
70
|
once: boolean;
|
|
64
|
-
|
|
71
|
+
reply: ReplyStructure<true> | ReplyStructure<false>;
|
|
72
|
+
}
|
|
73
|
+
type ReplyStructure<T extends boolean = false> = T extends true ? {
|
|
74
|
+
autoDefer: true;
|
|
75
|
+
ephemeral: boolean;
|
|
76
|
+
} : {
|
|
77
|
+
autoDefer: false;
|
|
78
|
+
};
|
|
65
79
|
export {};
|
package/dist/utils/files.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { Collection } from "discord.js";
|
|
2
1
|
import { readdirSync, statSync } from "fs";
|
|
3
2
|
import path from "path";
|
|
3
|
+
import { Collection } from "discord.js";
|
|
4
4
|
export const requiredFiles = async (directoryPath) => {
|
|
5
5
|
const collection = new Collection();
|
|
6
6
|
const filesPath = getAllFilesPath(directoryPath).filter((file) => !file.endsWith(".d.ts") && (file.endsWith(".js") || file.endsWith(".ts")));
|
|
7
7
|
for (const filePath of filesPath) {
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
const interactionData = await loadInteraction(filePath);
|
|
9
|
+
const interactionName = "command" in interactionData.data ? interactionData.data.command.name : interactionData.data.name;
|
|
10
|
+
collection.set(interactionName, interactionData);
|
|
10
11
|
}
|
|
11
12
|
return collection;
|
|
12
13
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { changeLanguage, t } from "i18next";
|
|
2
2
|
export const translateToLocale = async (locale, key, args) => {
|
|
3
|
-
await
|
|
4
|
-
return
|
|
3
|
+
await changeLanguage(locale);
|
|
4
|
+
return t(key, { interpolation: { escapeValue: false }, returnObjects: true, ...args });
|
|
5
5
|
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import js from "@eslint/js";
|
|
2
|
+
import ts from "typescript-eslint";
|
|
3
|
+
import importPlugin from "eslint-plugin-import";
|
|
4
|
+
import prettierConfig from "eslint-config-prettier";
|
|
5
|
+
|
|
6
|
+
export default ts.config(
|
|
7
|
+
js.configs.recommended,
|
|
8
|
+
ts.configs.recommended,
|
|
9
|
+
importPlugin.flatConfigs.recommended,
|
|
10
|
+
importPlugin.flatConfigs.typescript,
|
|
11
|
+
prettierConfig,
|
|
12
|
+
{
|
|
13
|
+
languageOptions: {
|
|
14
|
+
parserOptions: {
|
|
15
|
+
project: "./tsconfig.json",
|
|
16
|
+
sourceType: "module",
|
|
17
|
+
ecmaVersion: "latest"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
rules: {
|
|
21
|
+
"import/namespace": "off",
|
|
22
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
23
|
+
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
|
|
24
|
+
"@typescript-eslint/no-explicit-any": "warn",
|
|
25
|
+
"import/order": [
|
|
26
|
+
"error",
|
|
27
|
+
{
|
|
28
|
+
groups: [
|
|
29
|
+
"builtin",
|
|
30
|
+
"external",
|
|
31
|
+
"internal",
|
|
32
|
+
["parent", "sibling", "index"],
|
|
33
|
+
"object",
|
|
34
|
+
"type"
|
|
35
|
+
],
|
|
36
|
+
pathGroups: [
|
|
37
|
+
{
|
|
38
|
+
pattern: "@/**",
|
|
39
|
+
group: "internal"
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
pathGroupsExcludedImportTypes: ["builtin"],
|
|
43
|
+
alphabetize: {
|
|
44
|
+
order: "asc",
|
|
45
|
+
caseInsensitive: true
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"import/newline-after-import": ["error", { count: 1 }],
|
|
50
|
+
"import/no-unresolved": "error",
|
|
51
|
+
"import/no-duplicates": "error",
|
|
52
|
+
"no-console": "off",
|
|
53
|
+
"no-var": "error",
|
|
54
|
+
"prefer-const": "error"
|
|
55
|
+
},
|
|
56
|
+
settings: {
|
|
57
|
+
"import/resolver": {
|
|
58
|
+
typescript: {
|
|
59
|
+
alwaysTryTypes: true,
|
|
60
|
+
project: "./tsconfig.json"
|
|
61
|
+
},
|
|
62
|
+
node: {
|
|
63
|
+
extensions: [".js", ".ts"]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stelliajs/framework",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"lint": "eslint
|
|
7
|
+
"lint": "eslint src --ext .ts",
|
|
8
8
|
"format": "prettier --write .",
|
|
9
9
|
"build": "tsc && tsc-alias"
|
|
10
10
|
},
|
|
@@ -28,15 +28,14 @@
|
|
|
28
28
|
"log-symbols": "^7.0.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"typescript-eslint": "^8.38.0"
|
|
31
|
+
"@eslint/js": "^9.33.0",
|
|
32
|
+
"discord-api-types": "^0.38.18",
|
|
33
|
+
"eslint-config-prettier": "^10.1.8",
|
|
34
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
35
|
+
"eslint-plugin-import": "^2.32.0",
|
|
36
|
+
"prettier": "^3.6.2",
|
|
37
|
+
"tsc-alias": "^1.8.16",
|
|
38
|
+
"typescript-eslint": "^8.39.0"
|
|
40
39
|
},
|
|
41
40
|
"type": "module",
|
|
42
41
|
"packageManager": "pnpm@10.14.0"
|