xernerx 3.4.3 → 3.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.
Files changed (71) hide show
  1. package/README.md +10 -10
  2. package/dist/build/ContextCommandBuilder.js +93 -86
  3. package/dist/build/EventBuilder.js +34 -35
  4. package/dist/build/InhibitorBuilder.js +27 -27
  5. package/dist/build/MessageCommandBuilder.js +90 -78
  6. package/dist/build/SlashCommandBuilder.js +125 -118
  7. package/dist/client/XernerxClient.js +101 -83
  8. package/dist/handlers/CommandHandler.js +42 -42
  9. package/dist/handlers/EventHandler.js +16 -16
  10. package/dist/handlers/Handler.js +250 -250
  11. package/dist/handlers/InhibitorHandler.js +21 -21
  12. package/dist/main.cjs +2012 -0
  13. package/dist/main.js +42 -42
  14. package/dist/models/CommandArguments.js +121 -123
  15. package/dist/models/Events.js +294 -304
  16. package/dist/models/Extensions.js +23 -23
  17. package/dist/tools/XernerxError.js +8 -8
  18. package/dist/tools/package.js +37 -41
  19. package/dist/types/enums.js +35 -35
  20. package/dist/types/interfaces.js +1 -1
  21. package/dist/types/options.js +1 -1
  22. package/dist/types/types.js +1 -1
  23. package/dist/utils/ClientUtil.js +222 -218
  24. package/dist/utils/CommandUtil.js +248 -260
  25. package/dist/validators/CommandValidations.js +183 -185
  26. package/dist/validators/InhibitorValidations.js +42 -42
  27. package/dist/validators/Shapes.js +1 -0
  28. package/package.json +54 -39
  29. package/types/build/ContextCommandBuilder.d.ts +68 -0
  30. package/{dist → types}/build/EventBuilder.d.ts +21 -17
  31. package/{dist → types}/build/InhibitorBuilder.d.ts +19 -20
  32. package/types/build/MessageCommandBuilder.d.ts +59 -0
  33. package/types/build/SlashCommandBuilder.d.ts +64 -0
  34. package/{dist → types}/client/XernerxClient.d.ts +28 -28
  35. package/{dist → types}/handlers/CommandHandler.d.ts +27 -27
  36. package/{dist → types}/handlers/EventHandler.d.ts +13 -13
  37. package/{dist → types}/handlers/Handler.d.ts +57 -57
  38. package/{dist → types}/handlers/InhibitorHandler.d.ts +18 -18
  39. package/{dist → types}/main.d.ts +44 -30
  40. package/{dist → types}/models/CommandArguments.d.ts +17 -17
  41. package/{dist → types}/models/Events.d.ts +24 -24
  42. package/{dist → types}/models/Extensions.d.ts +7 -7
  43. package/{dist → types}/tools/XernerxError.d.ts +5 -5
  44. package/{dist → types}/tools/package.d.ts +38 -38
  45. package/types/types/enums.d.ts +44 -0
  46. package/{dist → types}/types/interfaces.d.ts +25 -25
  47. package/{dist → types}/types/options.d.ts +241 -206
  48. package/{dist → types}/types/types.d.ts +61 -32
  49. package/{dist → types}/utils/ClientUtil.d.ts +25 -25
  50. package/{dist → types}/utils/CommandUtil.d.ts +58 -56
  51. package/{dist → types}/validators/CommandValidations.d.ts +12 -7
  52. package/{dist → types}/validators/InhibitorValidations.d.ts +11 -11
  53. package/types/validators/Shapes.d.ts +1 -0
  54. package/dist/build/ContextCommandBuilder.d.ts +0 -42
  55. package/dist/build/MessageCommandBuilder.d.ts +0 -42
  56. package/dist/build/SlashCommandBuilder.d.ts +0 -40
  57. package/dist/build/XContextCommandBuilder.d.ts +0 -40
  58. package/dist/build/XContextCommandBuilder.js +0 -84
  59. package/dist/build/XEventBuilder.d.ts +0 -17
  60. package/dist/build/XEventBuilder.js +0 -35
  61. package/dist/build/XInhibitorBuilder.d.ts +0 -20
  62. package/dist/build/XInhibitorBuilder.js +0 -28
  63. package/dist/build/XMessageCommandBuilder.d.ts +0 -42
  64. package/dist/build/XMessageCommandBuilder.js +0 -80
  65. package/dist/build/XSlashCommandBuilder.d.ts +0 -36
  66. package/dist/build/XSlashCommandBuilder.js +0 -114
  67. package/dist/models/CommandValidations.d.ts +0 -4
  68. package/dist/models/CommandValidations.js +0 -183
  69. package/dist/models/InhibitorValidations.d.ts +0 -12
  70. package/dist/models/InhibitorValidations.js +0 -42
  71. package/dist/types/enums.d.ts +0 -35
@@ -1,304 +1,294 @@
1
- import { GatewayVersion, InteractionType, REST, Routes } from 'discord.js';
2
- import { InteractionCommandUtil, MessageCommandUtil } from '../utils/CommandUtil.js';
3
- import { InteractionArguments, messageArguments } from './CommandArguments.js';
4
- import commandValidation from '../validators/CommandValidations.js';
5
- import { Style } from 'dumfunctions';
6
- import { InhibitorValidation } from '../validators/InhibitorValidations.js';
7
- export class MessageCommandEvents {
8
- client;
9
- constructor(client) {
10
- this.client = client;
11
- }
12
- messageCreate() {
13
- this.client.on('messageCreate', async (message) => {
14
- if (!message.author.bot) {
15
- let command = undefined, px = undefined;
16
- message.author.isOwner = this.client.util.isOwner(message.author.id);
17
- message.util = new MessageCommandUtil(this.client, message);
18
- const commands = this.client.commands.message;
19
- commands
20
- .filter((c) => !c.regex)
21
- .map(async (cmd) => {
22
- if (cmd.prefix) {
23
- cmd.prefix.map((prefix) => {
24
- if (message.content.startsWith(prefix)) {
25
- command = message.content.replace(prefix, '').split(/ +/).shift();
26
- px = prefix;
27
- }
28
- });
29
- }
30
- if (this.client.handlerOptions.message?.prefix) {
31
- const prefix = Array.isArray(this.client.handlerOptions.message.prefix)
32
- ? this.client.handlerOptions.message.prefix
33
- : [this.client.handlerOptions.message.prefix];
34
- prefix.map((prefix) => {
35
- if (message.content.startsWith(prefix)) {
36
- command = message.content.replace(prefix, '').split(/ +/).shift();
37
- px = prefix;
38
- }
39
- });
40
- }
41
- if (this.client.handlerOptions.message?.allowMention) {
42
- if (message.mentions.users.has(this.client.user?.id) ||
43
- message.mentions.repliedUser?.id === this.client.user?.id) {
44
- command = message.content.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift();
45
- px = 'MentionPrefix';
46
- }
47
- }
48
- const prefix = Array.isArray(this.client.handlerOptions.message?.prefix)
49
- ? this.client.handlerOptions.message?.prefix
50
- : [this.client.handlerOptions.message?.prefix];
51
- if ((cmd.name.toLowerCase() == command?.toLowerCase() ||
52
- cmd.aliases?.map((c) => c.toLowerCase())?.includes(command?.toLowerCase())) &&
53
- (cmd.prefix.includes(px) || prefix?.includes(px) || px === 'MentionPrefix')) {
54
- try {
55
- if (this.client.handlerOptions.message?.handleTyping)
56
- message.channel.sendTyping();
57
- const inhibitor = new InhibitorValidation(this.client, message, command);
58
- if (commandValidation(message, cmd, this.client))
59
- return;
60
- if (await inhibitor.inhibit())
61
- return;
62
- if (cmd.conditions &&
63
- (await cmd.conditions(message, (await messageArguments(message, cmd)))))
64
- return;
65
- await cmd.exec(message, (await messageArguments(message, cmd)));
66
- this.client.emit('commandRun', message, cmd);
67
- }
68
- catch (error) {
69
- return this.client.emit('commandError', message, error, cmd);
70
- }
71
- }
72
- });
73
- }
74
- });
75
- }
76
- messageUpdate() {
77
- this.client.on('messageUpdate', async (old, message) => {
78
- message = message;
79
- if (!message.author?.bot) {
80
- let command = undefined, px = undefined;
81
- if (message.author)
82
- message.author.isOwner = this.client.util.isOwner(message.author.id);
83
- message.util = new MessageCommandUtil(this.client, message);
84
- const commands = this.client.commands.message;
85
- commands
86
- .filter((c) => !c.regex)
87
- .map(async (cmd) => {
88
- if (cmd.prefix) {
89
- cmd.prefix.map((prefix) => {
90
- if (message?.content?.startsWith(prefix)) {
91
- command = message.content.replace(prefix, '').split(/ +/).shift();
92
- px = prefix;
93
- }
94
- });
95
- }
96
- if (this.client.handlerOptions.message?.prefix) {
97
- const prefix = Array.isArray(this.client.handlerOptions.message.prefix)
98
- ? this.client.handlerOptions.message.prefix
99
- : [this.client.handlerOptions.message.prefix];
100
- prefix.map((prefix) => {
101
- if (message?.content?.startsWith(prefix)) {
102
- command = message.content.replace(prefix, '').split(/ +/).shift();
103
- px = prefix;
104
- }
105
- });
106
- }
107
- if (this.client.handlerOptions.message?.allowMention) {
108
- if (message.mentions.users.has(this.client.user?.id || '') ||
109
- message.mentions.repliedUser?.id === this.client.user?.id) {
110
- command = message?.content?.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift();
111
- px = 'MentionPrefix';
112
- }
113
- }
114
- const prefix = Array.isArray(this.client.handlerOptions.message?.prefix)
115
- ? this.client.handlerOptions.message?.prefix
116
- : [this.client.handlerOptions.message?.prefix];
117
- if ((cmd.name.toLowerCase() == command?.toLowerCase() ||
118
- cmd.aliases?.map((c) => c.toLowerCase())?.includes(command?.toLowerCase())) &&
119
- (cmd.prefix.includes(px) || prefix?.includes(px) || px === 'MentionPrefix')) {
120
- try {
121
- if (this.client.handlerOptions.message?.handleTyping)
122
- message.channel.sendTyping();
123
- message = message;
124
- const inhibitor = new InhibitorValidation(this.client, message, command);
125
- if (commandValidation(message, cmd, this.client))
126
- return;
127
- if (await inhibitor.inhibit())
128
- return;
129
- if (cmd.conditions &&
130
- (await cmd.conditions(message, (await messageArguments(message, cmd)))))
131
- return;
132
- await cmd.exec(message, (await messageArguments(message, cmd)));
133
- this.client.emit('commandRun', message, cmd);
134
- }
135
- catch (error) {
136
- return this.client.emit('commandError', message, error, cmd);
137
- }
138
- }
139
- });
140
- }
141
- });
142
- }
143
- messageDelete() {
144
- this.client.on('messageDelete', async (message) => {
145
- if (this.client.cache.messages.has(message.id) &&
146
- this.client.handlerOptions.message?.handleDeletes) {
147
- try {
148
- if (this.client.handlerOptions.message?.handleTyping)
149
- message.channel.sendTyping();
150
- const msg = this.client.cache.messages.get(message.id);
151
- const response = await message.channel.messages.fetch(msg?.response);
152
- await response.delete();
153
- }
154
- catch (error) {
155
- this.client.emit('commandError', message, error, null);
156
- }
157
- }
158
- });
159
- }
160
- }
161
- export class SlashCommandEvents {
162
- client;
163
- constructor(client) {
164
- this.client = client;
165
- }
166
- slashCreate() {
167
- this.client.on('interactionCreate', async (interaction) => {
168
- interaction.util = new InteractionCommandUtil(this.client, interaction);
169
- interaction.user.isOwner = this.client.util.isOwner(interaction.user.id);
170
- if (interaction.type === InteractionType.ApplicationCommand) {
171
- if (this.client.commands.slash.has(interaction.commandName)) {
172
- let command = this.client.commands.slash.get(interaction.commandName);
173
- const argumentsInfo = new InteractionArguments(interaction);
174
- try {
175
- const inhibitor = new InhibitorValidation(this.client, interaction, command);
176
- if (await inhibitor.inhibit())
177
- return;
178
- if (commandValidation(interaction, command, this.client))
179
- return;
180
- if (command.defer?.reply !== false && this.client.handlerOptions.slash?.defer?.reply)
181
- await interaction.deferReply({
182
- ephemeral: this.client.handlerOptions.slash?.defer?.ephemeral,
183
- fetchReply: this.client.handlerOptions.slash?.defer?.fetchReply,
184
- });
185
- if (!(interaction.deferred || interaction.replied) && command.defer?.reply)
186
- await interaction.deferReply({
187
- ephemeral: command.defer?.ephemeral,
188
- fetchReply: command.defer?.fetchReply,
189
- });
190
- if (command.conditions &&
191
- (await command.conditions(interaction, {
192
- group: argumentsInfo.group(),
193
- subcommand: argumentsInfo.subcommand(),
194
- args: await argumentsInfo.arguments(),
195
- })))
196
- return;
197
- await command.exec(interaction, {
198
- group: argumentsInfo.group(),
199
- subcommand: argumentsInfo.subcommand(),
200
- args: await argumentsInfo.arguments(),
201
- });
202
- this.client.emit('commandRun', interaction, command);
203
- }
204
- catch (error) {
205
- this.client.emit('commandError', interaction, error, command);
206
- }
207
- }
208
- }
209
- });
210
- }
211
- }
212
- export class ContextCommandEvents {
213
- client;
214
- constructor(client) {
215
- this.client = client;
216
- }
217
- contextCreate() {
218
- this.client.on('interactionCreate', async (interaction) => {
219
- interaction.util = new InteractionCommandUtil(this.client, interaction);
220
- interaction.user.isOwner = this.client.util.isOwner(interaction.user.id);
221
- if (interaction.type === InteractionType.ApplicationCommand) {
222
- if (this.client.commands.context.has(interaction.commandName)) {
223
- let command = this.client.commands.context.get(interaction.commandName);
224
- try {
225
- const inhibitor = new InhibitorValidation(this.client, interaction, command);
226
- if (commandValidation(interaction, command, this.client))
227
- return;
228
- if (await inhibitor.inhibit())
229
- return;
230
- if (command.conditions && (await command.conditions(interaction)))
231
- return;
232
- if (command.defer?.reply !== false && this.client.handlerOptions.context?.defer?.reply)
233
- await interaction.deferReply({
234
- ephemeral: this.client.handlerOptions.context?.defer?.ephemeral,
235
- fetchReply: this.client.handlerOptions.context?.defer?.fetchReply,
236
- });
237
- if (!(interaction.deferred || interaction.replied) && command.defer?.reply)
238
- await interaction.deferReply({
239
- ephemeral: command.defer?.ephemeral,
240
- fetchReply: command.defer?.fetchReply,
241
- });
242
- await command.exec(interaction);
243
- this.client.emit('commandRun', interaction, command);
244
- }
245
- catch (error) {
246
- this.client.emit('commandError', interaction, error, command);
247
- }
248
- }
249
- }
250
- });
251
- }
252
- }
253
- export class CommandsDeploy {
254
- client;
255
- constructor(client) {
256
- this.client = client;
257
- }
258
- deploy() {
259
- this.client.once('ready', async (client) => {
260
- const slashCommands = [], contextCommands = [];
261
- this.client.commands.context.map((command) => command.data ? contextCommands.push(command.data.toJSON()) : null);
262
- this.client.commands.slash.map((command) => (command.data ? slashCommands.push(command.data.toJSON()) : null));
263
- try {
264
- const global = {
265
- slash: this.client.handlerOptions.slash?.global,
266
- context: this.client.handlerOptions.context?.global,
267
- };
268
- const guild = {
269
- slash: this.client.handlerOptions.slash?.guildId,
270
- context: this.client.handlerOptions.context?.guildId,
271
- };
272
- if (global.slash && global.context) {
273
- if (guild.slash !== guild.context)
274
- console.info(Style.log(`Xernerx | Warning: slash and context commands are both set to global, but don't have a matching guildId, using ${(await this.client.guilds.fetch(this.client.handlerOptions.slash?.guildId)).name}!`, { color: Style.TextColor.Red }));
275
- this.put('global', guild.slash, [...contextCommands, ...slashCommands]);
276
- this.put('guild', guild.slash, []);
277
- }
278
- if (global.slash && global.context === false) {
279
- this.put('global', guild.slash, slashCommands);
280
- }
281
- if (global.slash === false && global.context) {
282
- this.put('global', guild.context, contextCommands);
283
- }
284
- if (global.slash === false && global.context === false) {
285
- this.put('guild', guild.slash, [...contextCommands, ...slashCommands]);
286
- }
287
- if (this.client.handlerOptions.context?.logging || this.client.handlerOptions.slash?.logging)
288
- console.info(Style.log(`Xernerx | Deployed ${slashCommands.length} slash commands ${global.slash ? 'globally' : 'locally'} and ${contextCommands.length} context commands ${global.context ? 'globally' : 'locally'}.`, { color: Style.TextColor.Purple }));
289
- }
290
- catch (error) {
291
- console.error(Style.log(`Xernerx | Couldn't deploy interaction commands because <${error}>.`, {
292
- color: Style.BackgroundColor.Red,
293
- }));
294
- }
295
- });
296
- }
297
- put(type, guild, body) {
298
- const rest = new REST({ version: GatewayVersion }).setToken(this.client.token);
299
- if (type === 'guild')
300
- rest.put(Routes.applicationGuildCommands(this.client.user?.id, guild), { body });
301
- else
302
- rest.put(Routes.applicationCommands(this.client.user?.id), { body });
303
- }
304
- }
1
+ import { GatewayVersion, InteractionType, REST, Routes } from 'discord.js';
2
+ import { InteractionCommandUtil, MessageCommandUtil } from '../utils/CommandUtil.js';
3
+ import { InteractionArguments, messageArguments } from './CommandArguments.js';
4
+ import commandValidation from '../validators/CommandValidations.js';
5
+ import { Style } from 'dumfunctions';
6
+ import { InhibitorValidation } from '../validators/InhibitorValidations.js';
7
+ export class MessageCommandEvents {
8
+ client;
9
+ constructor(client) {
10
+ this.client = client;
11
+ }
12
+ messageCreate() {
13
+ this.client.on('messageCreate', async (message) => {
14
+ if (!message.author.bot) {
15
+ let command = undefined, px = undefined;
16
+ message.author.isOwner = this.client.util.isOwner(message.author.id);
17
+ message.util = new MessageCommandUtil(this.client, message);
18
+ const commands = this.client.commands.message;
19
+ commands
20
+ .filter((c) => !c.regex)
21
+ .map(async (cmd) => {
22
+ if (cmd.prefix) {
23
+ cmd.prefix.map((prefix) => {
24
+ if (message.content.startsWith(prefix)) {
25
+ command = message.content.replace(prefix, '').split(/ +/).shift();
26
+ px = prefix;
27
+ }
28
+ });
29
+ }
30
+ if (this.client.handlerOptions.message?.prefix) {
31
+ const prefix = Array.isArray(this.client.handlerOptions.message.prefix) ? this.client.handlerOptions.message.prefix : [this.client.handlerOptions.message.prefix];
32
+ prefix.map((prefix) => {
33
+ if (message.content.startsWith(prefix)) {
34
+ command = message.content.replace(prefix, '').split(/ +/).shift();
35
+ px = prefix;
36
+ }
37
+ });
38
+ }
39
+ if (this.client.handlerOptions.message?.allowMention) {
40
+ if (message.mentions.users.has(this.client.user?.id) || message.mentions.repliedUser?.id === this.client.user?.id) {
41
+ command = message.content.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift();
42
+ px = 'MentionPrefix';
43
+ }
44
+ }
45
+ const prefix = Array.isArray(this.client.handlerOptions.message?.prefix) ? this.client.handlerOptions.message?.prefix : [this.client.handlerOptions.message?.prefix];
46
+ if ((cmd.name.toLowerCase() == command?.toLowerCase() || cmd.aliases?.map((c) => c.toLowerCase())?.includes(command?.toLowerCase())) &&
47
+ (cmd.prefix.includes(px) || prefix?.includes(px) || px === 'MentionPrefix')) {
48
+ try {
49
+ if (this.client.handlerOptions.message?.handleTyping)
50
+ message.channel.sendTyping();
51
+ const inhibitor = new InhibitorValidation(this.client, message, command);
52
+ if (commandValidation(message, cmd, this.client))
53
+ return;
54
+ if (await inhibitor.inhibit())
55
+ return;
56
+ if (cmd.conditions && (await cmd.conditions(message, (await messageArguments(message, cmd)))))
57
+ return;
58
+ await cmd.exec(message, (await messageArguments(message, cmd)));
59
+ this.client.emit('commandRun', message, cmd);
60
+ }
61
+ catch (error) {
62
+ return this.client.emit('commandError', message, error, cmd);
63
+ }
64
+ }
65
+ });
66
+ }
67
+ });
68
+ }
69
+ messageUpdate() {
70
+ this.client.on('messageUpdate', async (old, message) => {
71
+ message = message;
72
+ if (!message.author?.bot) {
73
+ let command = undefined, px = undefined;
74
+ if (message.author)
75
+ message.author.isOwner = this.client.util.isOwner(message.author.id);
76
+ message.util = new MessageCommandUtil(this.client, message);
77
+ const commands = this.client.commands.message;
78
+ commands
79
+ .filter((c) => !c.regex)
80
+ .map(async (cmd) => {
81
+ if (cmd.prefix) {
82
+ cmd.prefix.map((prefix) => {
83
+ if (message?.content?.startsWith(prefix)) {
84
+ command = message.content.replace(prefix, '').split(/ +/).shift();
85
+ px = prefix;
86
+ }
87
+ });
88
+ }
89
+ if (this.client.handlerOptions.message?.prefix) {
90
+ const prefix = Array.isArray(this.client.handlerOptions.message.prefix) ? this.client.handlerOptions.message.prefix : [this.client.handlerOptions.message.prefix];
91
+ prefix.map((prefix) => {
92
+ if (message?.content?.startsWith(prefix)) {
93
+ command = message.content.replace(prefix, '').split(/ +/).shift();
94
+ px = prefix;
95
+ }
96
+ });
97
+ }
98
+ if (this.client.handlerOptions.message?.allowMention) {
99
+ if (message.mentions.users.has(this.client.user?.id || '') || message.mentions.repliedUser?.id === this.client.user?.id) {
100
+ command = message?.content?.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift();
101
+ px = 'MentionPrefix';
102
+ }
103
+ }
104
+ const prefix = Array.isArray(this.client.handlerOptions.message?.prefix) ? this.client.handlerOptions.message?.prefix : [this.client.handlerOptions.message?.prefix];
105
+ if ((cmd.name.toLowerCase() == command?.toLowerCase() || cmd.aliases?.map((c) => c.toLowerCase())?.includes(command?.toLowerCase())) &&
106
+ (cmd.prefix.includes(px) || prefix?.includes(px) || px === 'MentionPrefix')) {
107
+ try {
108
+ if (this.client.handlerOptions.message?.handleTyping)
109
+ message.channel.sendTyping();
110
+ message = message;
111
+ const inhibitor = new InhibitorValidation(this.client, message, command);
112
+ if (commandValidation(message, cmd, this.client))
113
+ return;
114
+ if (await inhibitor.inhibit())
115
+ return;
116
+ if (cmd.conditions && (await cmd.conditions(message, (await messageArguments(message, cmd)))))
117
+ return;
118
+ await cmd.exec(message, (await messageArguments(message, cmd)));
119
+ this.client.emit('commandRun', message, cmd);
120
+ }
121
+ catch (error) {
122
+ return this.client.emit('commandError', message, error, cmd);
123
+ }
124
+ }
125
+ });
126
+ }
127
+ });
128
+ }
129
+ messageDelete() {
130
+ this.client.on('messageDelete', async (message) => {
131
+ if (this.client.cache.messages.has(message.id) && this.client.handlerOptions.message?.handleDeletes) {
132
+ try {
133
+ if (this.client.handlerOptions.message?.handleTyping)
134
+ message.channel.sendTyping();
135
+ const msg = this.client.cache.messages.get(message.id);
136
+ const response = await message.channel.messages.fetch(msg?.response);
137
+ await response.delete();
138
+ }
139
+ catch (error) {
140
+ this.client.emit('commandError', message, error, null);
141
+ }
142
+ }
143
+ });
144
+ }
145
+ }
146
+ export class SlashCommandEvents {
147
+ client;
148
+ constructor(client) {
149
+ this.client = client;
150
+ }
151
+ slashCreate() {
152
+ this.client.on('interactionCreate', async (interaction) => {
153
+ interaction.util = new InteractionCommandUtil(this.client, interaction);
154
+ interaction.user.isOwner = this.client.util.isOwner(interaction.user.id);
155
+ if (interaction.type === InteractionType.ApplicationCommand) {
156
+ if (this.client.commands.slash.has(interaction.commandName)) {
157
+ let command = this.client.commands.slash.get(interaction.commandName);
158
+ const argumentsInfo = new InteractionArguments(interaction);
159
+ try {
160
+ const inhibitor = new InhibitorValidation(this.client, interaction, command);
161
+ if (await inhibitor.inhibit())
162
+ return;
163
+ if (commandValidation(interaction, command, this.client))
164
+ return;
165
+ if (command.defer?.reply !== false && this.client.handlerOptions.slash?.defer?.reply)
166
+ await interaction.deferReply({
167
+ ephemeral: this.client.handlerOptions.slash?.defer?.ephemeral,
168
+ fetchReply: this.client.handlerOptions.slash?.defer?.fetchReply,
169
+ });
170
+ if (!(interaction.deferred || interaction.replied) && command.defer?.reply)
171
+ await interaction.deferReply({
172
+ ephemeral: command.defer?.ephemeral,
173
+ fetchReply: command.defer?.fetchReply,
174
+ });
175
+ if (command.conditions &&
176
+ (await command.conditions(interaction, {
177
+ group: argumentsInfo.group(),
178
+ subcommand: argumentsInfo.subcommand(),
179
+ args: await argumentsInfo.arguments(),
180
+ })))
181
+ return;
182
+ await command.exec(interaction, {
183
+ group: argumentsInfo.group(),
184
+ subcommand: argumentsInfo.subcommand(),
185
+ args: await argumentsInfo.arguments(),
186
+ });
187
+ this.client.emit('commandRun', interaction, command);
188
+ }
189
+ catch (error) {
190
+ this.client.emit('commandError', interaction, error, command);
191
+ }
192
+ }
193
+ }
194
+ });
195
+ }
196
+ }
197
+ export class ContextCommandEvents {
198
+ client;
199
+ constructor(client) {
200
+ this.client = client;
201
+ }
202
+ contextCreate() {
203
+ this.client.on('interactionCreate', async (interaction) => {
204
+ interaction.util = new InteractionCommandUtil(this.client, interaction);
205
+ interaction.user.isOwner = this.client.util.isOwner(interaction.user.id);
206
+ if (interaction.type === InteractionType.ApplicationCommand) {
207
+ if (this.client.commands.context.has(interaction.commandName)) {
208
+ let command = this.client.commands.context.get(interaction.commandName);
209
+ try {
210
+ const inhibitor = new InhibitorValidation(this.client, interaction, command);
211
+ if (commandValidation(interaction, command, this.client))
212
+ return;
213
+ if (await inhibitor.inhibit())
214
+ return;
215
+ if (command.conditions && (await command.conditions(interaction)))
216
+ return;
217
+ if (command.defer?.reply !== false && this.client.handlerOptions.context?.defer?.reply)
218
+ await interaction.deferReply({
219
+ ephemeral: this.client.handlerOptions.context?.defer?.ephemeral,
220
+ fetchReply: this.client.handlerOptions.context?.defer?.fetchReply,
221
+ });
222
+ if (!(interaction.deferred || interaction.replied) && command.defer?.reply)
223
+ await interaction.deferReply({
224
+ ephemeral: command.defer?.ephemeral,
225
+ fetchReply: command.defer?.fetchReply,
226
+ });
227
+ let args = {};
228
+ if (command.type === 3)
229
+ args = await interaction.channel.messages.fetch(interaction.targetId);
230
+ if (command.type === 2)
231
+ args = await this.client.users.fetch(interaction.targetId);
232
+ await command.exec(interaction, args);
233
+ this.client.emit('commandRun', interaction, command);
234
+ }
235
+ catch (error) {
236
+ this.client.emit('commandError', interaction, error, command);
237
+ }
238
+ }
239
+ }
240
+ });
241
+ }
242
+ }
243
+ export class CommandsDeploy {
244
+ client;
245
+ constructor(client) {
246
+ this.client = client;
247
+ }
248
+ deploy() {
249
+ this.client.once('ready', async (client) => {
250
+ const slashCommands = [], contextCommands = [];
251
+ this.client.commands.context.map((command) => (command.data ? contextCommands.push(command.data.toJSON()) : null));
252
+ this.client.commands.slash.map((command) => (command.data ? slashCommands.push(command.data.toJSON()) : null));
253
+ try {
254
+ const global = {
255
+ slash: this.client.handlerOptions.slash?.global,
256
+ context: this.client.handlerOptions.context?.global,
257
+ };
258
+ const guild = {
259
+ slash: this.client.handlerOptions.slash?.guildId,
260
+ context: this.client.handlerOptions.context?.guildId,
261
+ };
262
+ if (global.slash && global.context) {
263
+ if (guild.slash !== guild.context)
264
+ console.info(Style.log(`Xernerx | Warning: slash and context commands are both set to global, but don't have a matching guildId, using ${(await this.client.guilds.fetch(this.client.handlerOptions.slash?.guildId)).name}!`, { color: Style.TextColor.Red }));
265
+ this.put('global', guild.slash, [...contextCommands, ...slashCommands]);
266
+ this.put('guild', guild.slash, []);
267
+ }
268
+ if (global.slash && global.context === false) {
269
+ this.put('global', guild.slash, slashCommands);
270
+ }
271
+ if (global.slash === false && global.context) {
272
+ this.put('global', guild.context, contextCommands);
273
+ }
274
+ if (global.slash === false && global.context === false) {
275
+ this.put('guild', guild.slash, [...contextCommands, ...slashCommands]);
276
+ }
277
+ if (this.client.handlerOptions.context?.logging || this.client.handlerOptions.slash?.logging)
278
+ console.info(Style.log(`Xernerx | Deployed ${slashCommands.length} slash commands ${global.slash ? 'globally' : 'locally'} and ${contextCommands.length} context commands ${global.context ? 'globally' : 'locally'}.`, { color: Style.TextColor.Purple }));
279
+ }
280
+ catch (error) {
281
+ console.error(Style.log(`Xernerx | Couldn't deploy interaction commands because <${error}>.`, {
282
+ color: Style.BackgroundColor.Red,
283
+ }));
284
+ }
285
+ });
286
+ }
287
+ put(type, guild, body) {
288
+ const rest = new REST({ version: GatewayVersion }).setToken(this.client.token);
289
+ if (type === 'guild')
290
+ rest.put(Routes.applicationGuildCommands(this.client.user?.id, guild), { body });
291
+ else
292
+ rest.put(Routes.applicationCommands(this.client.user?.id), { body });
293
+ }
294
+ }