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.
- package/README.md +10 -10
- package/dist/build/ContextCommandBuilder.js +93 -86
- package/dist/build/EventBuilder.js +34 -35
- package/dist/build/InhibitorBuilder.js +27 -27
- package/dist/build/MessageCommandBuilder.js +90 -78
- package/dist/build/SlashCommandBuilder.js +125 -118
- package/dist/client/XernerxClient.js +101 -83
- package/dist/handlers/CommandHandler.js +42 -42
- package/dist/handlers/EventHandler.js +16 -16
- package/dist/handlers/Handler.js +250 -250
- package/dist/handlers/InhibitorHandler.js +21 -21
- package/dist/main.cjs +2012 -0
- package/dist/main.js +42 -42
- package/dist/models/CommandArguments.js +121 -123
- package/dist/models/Events.js +294 -304
- package/dist/models/Extensions.js +23 -23
- package/dist/tools/XernerxError.js +8 -8
- package/dist/tools/package.js +37 -41
- package/dist/types/enums.js +35 -35
- package/dist/types/interfaces.js +1 -1
- package/dist/types/options.js +1 -1
- package/dist/types/types.js +1 -1
- package/dist/utils/ClientUtil.js +222 -218
- package/dist/utils/CommandUtil.js +248 -260
- package/dist/validators/CommandValidations.js +183 -185
- package/dist/validators/InhibitorValidations.js +42 -42
- package/dist/validators/Shapes.js +1 -0
- package/package.json +54 -39
- package/types/build/ContextCommandBuilder.d.ts +68 -0
- package/{dist → types}/build/EventBuilder.d.ts +21 -17
- package/{dist → types}/build/InhibitorBuilder.d.ts +19 -20
- package/types/build/MessageCommandBuilder.d.ts +59 -0
- package/types/build/SlashCommandBuilder.d.ts +64 -0
- package/{dist → types}/client/XernerxClient.d.ts +28 -28
- package/{dist → types}/handlers/CommandHandler.d.ts +27 -27
- package/{dist → types}/handlers/EventHandler.d.ts +13 -13
- package/{dist → types}/handlers/Handler.d.ts +57 -57
- package/{dist → types}/handlers/InhibitorHandler.d.ts +18 -18
- package/{dist → types}/main.d.ts +44 -30
- package/{dist → types}/models/CommandArguments.d.ts +17 -17
- package/{dist → types}/models/Events.d.ts +24 -24
- package/{dist → types}/models/Extensions.d.ts +7 -7
- package/{dist → types}/tools/XernerxError.d.ts +5 -5
- package/{dist → types}/tools/package.d.ts +38 -38
- package/types/types/enums.d.ts +44 -0
- package/{dist → types}/types/interfaces.d.ts +25 -25
- package/{dist → types}/types/options.d.ts +241 -206
- package/{dist → types}/types/types.d.ts +61 -32
- package/{dist → types}/utils/ClientUtil.d.ts +25 -25
- package/{dist → types}/utils/CommandUtil.d.ts +58 -56
- package/{dist → types}/validators/CommandValidations.d.ts +12 -7
- package/{dist → types}/validators/InhibitorValidations.d.ts +11 -11
- package/types/validators/Shapes.d.ts +1 -0
- package/dist/build/ContextCommandBuilder.d.ts +0 -42
- package/dist/build/MessageCommandBuilder.d.ts +0 -42
- package/dist/build/SlashCommandBuilder.d.ts +0 -40
- package/dist/build/XContextCommandBuilder.d.ts +0 -40
- package/dist/build/XContextCommandBuilder.js +0 -84
- package/dist/build/XEventBuilder.d.ts +0 -17
- package/dist/build/XEventBuilder.js +0 -35
- package/dist/build/XInhibitorBuilder.d.ts +0 -20
- package/dist/build/XInhibitorBuilder.js +0 -28
- package/dist/build/XMessageCommandBuilder.d.ts +0 -42
- package/dist/build/XMessageCommandBuilder.js +0 -80
- package/dist/build/XSlashCommandBuilder.d.ts +0 -36
- package/dist/build/XSlashCommandBuilder.js +0 -114
- package/dist/models/CommandValidations.d.ts +0 -4
- package/dist/models/CommandValidations.js +0 -183
- package/dist/models/InhibitorValidations.d.ts +0 -12
- package/dist/models/InhibitorValidations.js +0 -42
- package/dist/types/enums.d.ts +0 -35
package/dist/models/Events.js
CHANGED
|
@@ -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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
|
|
230
|
-
if (command.
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
this.put('
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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
|
+
}
|