@stelliajs/framework 1.5.6 → 1.5.8
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 +105 -64
- package/dist/managers/EventManager.js +6 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -49,108 +49,149 @@ Recommended architecture for StelliaJS project.
|
|
|
49
49
|
|
|
50
50
|
### Simple client with environment
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
#### Client initialization
|
|
53
|
+
```ts
|
|
54
54
|
import { StelliaClient } from "@stelliajs/framework";
|
|
55
|
+
import { GatewayIntentBits, Partials } from "discord.js";
|
|
56
|
+
|
|
57
|
+
(async () => {
|
|
58
|
+
const client = new StelliaClient({
|
|
59
|
+
intents: [
|
|
60
|
+
GatewayIntentBits.Guilds,
|
|
61
|
+
GatewayIntentBits.GuildMessages,
|
|
62
|
+
GatewayIntentBits.MessageContent,
|
|
63
|
+
GatewayIntentBits.GuildMembers
|
|
64
|
+
],
|
|
65
|
+
partials: [Partials.Message, Partials.GuildMember]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
managers: {
|
|
69
|
+
autoCompletes: {
|
|
70
|
+
directoryPath: "./interactions/autoCompletes"
|
|
71
|
+
},
|
|
72
|
+
buttons: {
|
|
73
|
+
directoryPath: "./interactions/buttons"
|
|
74
|
+
},
|
|
75
|
+
commands: {
|
|
76
|
+
directoryPath: "./commands/slash"
|
|
77
|
+
},
|
|
78
|
+
contextMenus: {
|
|
79
|
+
directoryPath: "./commands/contextMenus"
|
|
80
|
+
},
|
|
81
|
+
events: {
|
|
82
|
+
directoryPath: "./events"
|
|
83
|
+
},
|
|
84
|
+
modals: {
|
|
85
|
+
directoryPath: "./interactions/modals"
|
|
86
|
+
},
|
|
87
|
+
selectMenus: {
|
|
88
|
+
directoryPath: "./interactions/selectMenus"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
environment: {
|
|
92
|
+
areGuildsConfigurationEnabled: true
|
|
93
|
+
}
|
|
94
|
+
});
|
|
55
95
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
intents: [
|
|
59
|
-
GatewayIntentBits.Guilds,
|
|
60
|
-
GatewayIntentBits.GuildMessages,
|
|
61
|
-
GatewayIntentBits.MessageContent,
|
|
62
|
-
GatewayIntentBits.GuildMembers
|
|
63
|
-
],
|
|
64
|
-
partials: [Partials.Message, Partials.GuildMember]
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
managers: {
|
|
68
|
-
autoCompletes: {
|
|
69
|
-
directoryPath: "./interactions/autoCompletes"
|
|
70
|
-
},
|
|
71
|
-
buttons: {
|
|
72
|
-
directoryPath: "./interactions/buttons"
|
|
73
|
-
},
|
|
74
|
-
commands: {
|
|
75
|
-
directoryPath: "./commands/slash"
|
|
76
|
-
},
|
|
77
|
-
contextMenus: {
|
|
78
|
-
directoryPath: "./commands/contextMenus"
|
|
79
|
-
},
|
|
80
|
-
events: {
|
|
81
|
-
directoryPath: "./events"
|
|
82
|
-
},
|
|
83
|
-
modals: {
|
|
84
|
-
directoryPath: "./interactions/modals"
|
|
85
|
-
},
|
|
86
|
-
selectMenus: {
|
|
87
|
-
directoryPath: "./interactions/selectMenus"
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
environment: {
|
|
91
|
-
areGuildsConfigurationEnabled: true
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
await client.connect(process.env.TOKEN);
|
|
96
|
+
await client.connect(process.env.TOKEN);
|
|
97
|
+
})();
|
|
97
98
|
```
|
|
98
99
|
|
|
99
|
-
|
|
100
|
+
#### Environment model
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import {
|
|
104
|
+
BaseGeneralConfiguration,
|
|
105
|
+
BaseGuildConfiguration,
|
|
106
|
+
GuildConfiguration,
|
|
107
|
+
GuildsConfiguration
|
|
108
|
+
} from "@stelliajs/framework";
|
|
109
|
+
import { Snowflake } from "discord.js";
|
|
110
|
+
|
|
111
|
+
interface MyBotGeneralConfiguration extends BaseGeneralConfiguration {
|
|
112
|
+
botName: string;
|
|
113
|
+
}
|
|
114
|
+
interface MyBotSpecificGuildConfiguration extends BaseGuildConfiguration {
|
|
115
|
+
channels: {
|
|
116
|
+
logs: Snowflake;
|
|
117
|
+
welcome: Snowflake;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface MyBotGuildConfiguration extends GuildConfiguration {
|
|
122
|
+
general: MyBotGeneralConfiguration;
|
|
123
|
+
guild: MyBotSpecificGuildConfiguration;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface MyBotGuildsConfiguration extends GuildsConfiguration {
|
|
127
|
+
general: MyBotGeneralConfiguration;
|
|
128
|
+
guilds: {
|
|
129
|
+
[guildId: Snowflake]: MyBotSpecificGuildConfiguration;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
```
|
|
100
133
|
|
|
101
|
-
|
|
134
|
+
### Interactions/Events with environment
|
|
102
135
|
|
|
103
|
-
|
|
104
|
-
|
|
136
|
+
#### Ready event
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { type EventStructure, type StelliaClient } from "@stelliajs/framework";
|
|
105
140
|
import { Events } from "discord.js";
|
|
106
|
-
import { type
|
|
141
|
+
import { type MyBotGuildsConfiguration } from "@environments/environment.model.ts";
|
|
107
142
|
|
|
108
143
|
export default {
|
|
109
144
|
data: {
|
|
110
145
|
name: Events.ClientReady,
|
|
111
146
|
once: true
|
|
112
147
|
},
|
|
113
|
-
async execute(client: StelliaClient<true>,
|
|
148
|
+
async execute(client: StelliaClient<true>, guildsConfiguration: MyBotGuildsConfiguration) { // <true> ensures that the client is Ready
|
|
114
149
|
console.log(`Logged in as ${client.user.tag}`);
|
|
115
150
|
await client.initializeCommands(); // Used to initialise registered commands
|
|
116
151
|
}
|
|
117
|
-
}
|
|
152
|
+
} satisfies EventStructure;
|
|
118
153
|
```
|
|
119
154
|
|
|
120
|
-
#### InteractionCreate event
|
|
155
|
+
#### InteractionCreate event
|
|
121
156
|
|
|
122
|
-
```
|
|
157
|
+
```ts
|
|
123
158
|
import { type StelliaClient, type EventStructure } from "@stelliajs/framework";
|
|
124
159
|
import { Events, type Interaction } from "discord.js";
|
|
125
|
-
import { type
|
|
160
|
+
import { type MyBotGuildConfiguration } from "@environments/environment.model.ts";
|
|
126
161
|
|
|
127
162
|
export default {
|
|
128
163
|
data: {
|
|
129
164
|
name: Events.InteractionCreate,
|
|
130
165
|
once: false
|
|
131
166
|
},
|
|
132
|
-
async execute(client: StelliaClient<true>,
|
|
167
|
+
async execute(client: StelliaClient<true>, guildConfiguration: MyBotGuildConfiguration, interaction: Interaction) {
|
|
133
168
|
if (interaction.inCachedGuild()) {
|
|
134
169
|
await client.handleInteraction(interaction); // Automatic interaction handling
|
|
135
170
|
}
|
|
136
171
|
}
|
|
137
|
-
}
|
|
172
|
+
} satisfies EventStructure;
|
|
138
173
|
```
|
|
139
174
|
|
|
140
|
-
|
|
175
|
+
#### Command interaction
|
|
141
176
|
|
|
142
|
-
```
|
|
143
|
-
import { type CommandStructure,
|
|
177
|
+
```ts
|
|
178
|
+
import { type CommandStructure, type StelliaClient } from "@stelliajs/framework";
|
|
144
179
|
import { type ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
|
|
145
|
-
import { type
|
|
180
|
+
import { type MyBotGuildConfiguration } from "@environments/environment.model.ts";
|
|
146
181
|
|
|
147
182
|
export default {
|
|
148
|
-
data:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
183
|
+
data: {
|
|
184
|
+
command: new SlashCommandBuilder()
|
|
185
|
+
.setName("ping"),
|
|
186
|
+
reply: {
|
|
187
|
+
autoDefer: true, // Defer the reply to avoid the interaction failing after 3 seconds
|
|
188
|
+
ephemeral: true, // The reply will be visible only by the user who triggered the interaction
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
async execute(client: StelliaClient, guildConfiguration: MyBotGuildConfiguration, interaction: ChatInputCommandInteraction<"cached">) { // All interactions are cached
|
|
192
|
+
await interaction.editReply("Pong!");
|
|
152
193
|
}
|
|
153
|
-
}
|
|
194
|
+
} satisfies CommandStructure;
|
|
154
195
|
```
|
|
155
196
|
|
|
156
197
|
## Help
|
|
@@ -86,6 +86,12 @@ export class EventManager extends BaseManager {
|
|
|
86
86
|
if ("guild" in mainArgument && mainArgument.guild) {
|
|
87
87
|
return this.client.getGuildConfiguration(mainArgument.guild.id);
|
|
88
88
|
}
|
|
89
|
+
if (mainArgument && typeof mainArgument === "object" &&
|
|
90
|
+
"message" in mainArgument && mainArgument.message &&
|
|
91
|
+
typeof mainArgument.message === "object" && "guild" in mainArgument.message &&
|
|
92
|
+
mainArgument.message.guild && "id" in mainArgument.message.guild) {
|
|
93
|
+
return this.client.getGuildConfiguration(mainArgument.message.guild.id);
|
|
94
|
+
}
|
|
89
95
|
}
|
|
90
96
|
return undefined;
|
|
91
97
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stelliajs/framework",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
"framework"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"discord.js": "^14.
|
|
27
|
-
"i18next": "^25.
|
|
26
|
+
"discord.js": "^14.24.0",
|
|
27
|
+
"i18next": "^25.6.0",
|
|
28
28
|
"log-symbols": "^7.0.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@eslint/js": "^9.
|
|
31
|
+
"@eslint/js": "^9.38.0",
|
|
32
32
|
"eslint-config-prettier": "^10.1.8",
|
|
33
33
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
34
34
|
"eslint-plugin-import": "^2.32.0",
|
|
35
35
|
"prettier": "^3.6.2",
|
|
36
36
|
"tsc-alias": "^1.8.16",
|
|
37
|
-
"typescript-eslint": "^8.
|
|
37
|
+
"typescript-eslint": "^8.46.2"
|
|
38
38
|
},
|
|
39
39
|
"type": "module",
|
|
40
|
-
"packageManager": "pnpm@10.
|
|
40
|
+
"packageManager": "pnpm@10.19.0"
|
|
41
41
|
}
|