xernerx 4.17.7 → 4.17.9
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/dist/build/XernerxContextCommand.d.ts +47 -75
- package/dist/build/XernerxContextCommand.js +115 -119
- package/dist/build/XernerxEvent.d.ts +10 -10
- package/dist/build/XernerxEvent.js +17 -17
- package/dist/build/XernerxInhibitor.d.ts +15 -39
- package/dist/build/XernerxInhibitor.js +18 -18
- package/dist/build/XernerxMessageCommand.d.ts +52 -78
- package/dist/build/XernerxMessageCommand.js +114 -118
- package/dist/build/XernerxSlashCommand.d.ts +63 -97
- package/dist/build/XernerxSlashCommand.js +173 -177
- package/dist/client/XernerxClient.d.ts +55 -61
- package/dist/client/XernerxClient.js +94 -91
- package/dist/client/XernerxShardClient.d.ts +14 -14
- package/dist/client/XernerxShardClient.js +48 -61
- package/dist/functions/deploy.js +52 -45
- package/dist/functions/load.js +29 -28
- package/dist/functions/reload.js +24 -23
- package/dist/functions/setPresence.d.ts +1 -1
- package/dist/functions/setPresence.js +16 -17
- package/dist/handlers/CommandHandler.d.ts +10 -10
- package/dist/handlers/CommandHandler.js +337 -312
- package/dist/handlers/EventHandler.d.ts +5 -3
- package/dist/handlers/EventHandler.js +76 -48
- package/dist/handlers/ExtensionHandler.d.ts +3 -3
- package/dist/handlers/ExtensionHandler.js +23 -23
- package/dist/handlers/Handler.d.ts +17 -22
- package/dist/handlers/Handler.js +57 -45
- package/dist/handlers/InhibitorHandler.d.ts +3 -3
- package/dist/handlers/InhibitorHandler.js +23 -25
- package/dist/handlers/IntegrationHandler.d.ts +6 -6
- package/dist/handlers/IntegrationHandler.js +20 -20
- package/dist/main.d.ts +22 -29
- package/dist/main.js +22 -29
- package/dist/models/Arguments.d.ts +1 -4
- package/dist/models/Arguments.js +149 -134
- package/dist/models/Cooldowns.d.ts +6 -6
- package/dist/models/Cooldowns.js +29 -25
- package/dist/models/XernerxEntitlement.d.ts +45 -0
- package/dist/models/XernerxEntitlement.js +57 -0
- package/dist/models/XernerxUser.d.ts +14 -0
- package/dist/models/XernerxUser.js +13 -0
- package/dist/tools/XernerxError.d.ts +4 -4
- package/dist/tools/XernerxError.js +8 -8
- package/dist/tools/XernerxIntents.d.ts +2 -2
- package/dist/tools/XernerxIntents.js +21 -21
- package/dist/tools/XernerxLog.d.ts +25 -25
- package/dist/tools/XernerxLog.js +131 -140
- package/dist/tools/XernerxText.d.ts +23 -23
- package/dist/tools/XernerxText.js +89 -79
- package/dist/types/extenders.d.ts +47 -55
- package/dist/types/interfaces.d.ts +190 -195
- package/dist/types/types.d.ts +5 -104
- package/dist/utils/ClientUtil.d.ts +10 -12
- package/dist/utils/ClientUtil.js +117 -96
- package/dist/utils/InteractionUtil.d.ts +13 -13
- package/dist/utils/InteractionUtil.js +147 -148
- package/dist/utils/MessageUtil.d.ts +14 -14
- package/dist/utils/MessageUtil.js +161 -162
- package/dist/utils/Util.d.ts +7 -7
- package/dist/utils/Util.js +7 -7
- package/dist/validators/commandValidation.d.ts +1 -4
- package/dist/validators/commandValidation.js +114 -157
- package/dist/validators/inhibitorValidations.d.ts +2 -21
- package/dist/validators/inhibitorValidations.js +39 -39
- package/package.json +6 -5
- package/tsup.config.ts +19 -0
- package/dist/functions/xernerxUser.d.ts +0 -4
- package/dist/functions/xernerxUser.js +0 -10
|
@@ -4,7 +4,7 @@ import * as path from 'path';
|
|
|
4
4
|
import { GatewayIntentBits } from 'discord.js';
|
|
5
5
|
import Handler from './Handler.js';
|
|
6
6
|
import MessageUtil from '../utils/MessageUtil.js';
|
|
7
|
-
import
|
|
7
|
+
import XernerxUser from '../models/XernerxUser.js';
|
|
8
8
|
import InteractionUtil from '../utils/InteractionUtil.js';
|
|
9
9
|
import commandValidation from '../validators/commandValidation.js';
|
|
10
10
|
import XernerxLog from '../tools/XernerxLog.js';
|
|
@@ -12,315 +12,340 @@ import { interactionArguments, messageArguments } from '../models/Arguments.js';
|
|
|
12
12
|
import { inhibitorValidation } from '../validators/inhibitorValidations.js';
|
|
13
13
|
import { Style } from 'dumfunctions';
|
|
14
14
|
export default class CommandHandler extends Handler {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
15
|
+
constructor(client) {
|
|
16
|
+
super(client);
|
|
17
|
+
this.readyTimestamp = Number(Date.now());
|
|
18
|
+
}
|
|
19
|
+
async loadMessageCommands(options) {
|
|
20
|
+
const commands = [];
|
|
21
|
+
if (!this.client.options.intents.has(GatewayIntentBits.MessageContent))
|
|
22
|
+
new XernerxLog(this.client).warn(`Message commands might not work as you're missing the intent MessageContent!`);
|
|
23
|
+
if (!this.client.options.intents.has(GatewayIntentBits.GuildMessages))
|
|
24
|
+
new XernerxLog(this.client).warn(`Message commands might not work as you're missing the intent GuildMessages!`);
|
|
25
|
+
options = z
|
|
26
|
+
.object({
|
|
27
|
+
directory: z.string(),
|
|
28
|
+
prefix: z.string().or(z.array(z.string())),
|
|
29
|
+
allowMention: z.boolean().default(false),
|
|
30
|
+
cooldown: z.number().default(0),
|
|
31
|
+
permissions: z
|
|
32
|
+
.object({
|
|
33
|
+
user: z.array(z.string()).or(z.null()).default(null),
|
|
34
|
+
client: z.array(z.string()).or(z.null()).default(null),
|
|
35
|
+
dm: z.boolean().default(true),
|
|
36
|
+
})
|
|
37
|
+
.default({}),
|
|
38
|
+
handleEdits: z.boolean().default(false),
|
|
39
|
+
handleDeletes: z.boolean().default(false),
|
|
40
|
+
handleTyping: z.boolean().default(false),
|
|
41
|
+
logging: z.boolean().default(false),
|
|
42
|
+
})
|
|
43
|
+
.parse(options);
|
|
44
|
+
this.client.modules.options.message = options;
|
|
45
|
+
const files = await this.readdir(options.directory, 'MessageCommands');
|
|
46
|
+
for (const file of files) {
|
|
47
|
+
const filepath = `${path.resolve(options.directory)}\\${file}`;
|
|
48
|
+
const command = await this.load(filepath, 'MessageCommand');
|
|
49
|
+
this._checks(command);
|
|
50
|
+
commands.push(command.id);
|
|
51
|
+
}
|
|
52
|
+
new XernerxLog(this.client).info(`Loaded ${Style.log(String(files.length), { color: Style.TextColor.Cyan })} Message Commands: ${commands.map((command) => Style.log(command, { color: Style.TextColor.LightYellow })).join(', ')}`);
|
|
53
|
+
this.emit({
|
|
54
|
+
name: 'messageCreate',
|
|
55
|
+
filetype: 'MessageCommand',
|
|
56
|
+
run: (message) => this.messageCommandRun(message),
|
|
57
|
+
});
|
|
58
|
+
this.emit({
|
|
59
|
+
name: 'messageUpdate',
|
|
60
|
+
filetype: 'MessageCommand',
|
|
61
|
+
run: (message, message2) => this.messageCommandRun(message, message2),
|
|
62
|
+
});
|
|
63
|
+
this.emit({
|
|
64
|
+
name: 'messageDelete',
|
|
65
|
+
filetype: 'MessageCommand',
|
|
66
|
+
run: (message) => this.messageCommandRun(message, 'delete'),
|
|
67
|
+
});
|
|
68
|
+
this.client.on('messageReactionAdd', (message) => {
|
|
69
|
+
message.util = new MessageUtil(this.client, message);
|
|
70
|
+
});
|
|
71
|
+
this.client.on('messageReactionRemove', (message) => {
|
|
72
|
+
message.util = new MessageUtil(this.client, message);
|
|
73
|
+
});
|
|
74
|
+
this.client.on('messageReactionRemoveAll', (message) => {
|
|
75
|
+
message.util = new MessageUtil(this.client, message);
|
|
76
|
+
});
|
|
77
|
+
this.client.on('messageReactionRemoveEmoji', (message) => {
|
|
78
|
+
message.util = new MessageUtil(this.client, message);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// public reloadMessageCommands() {
|
|
82
|
+
// return reload(this.client, 'message');
|
|
83
|
+
// }
|
|
84
|
+
async loadSlashCommands(options) {
|
|
85
|
+
const commands = [];
|
|
86
|
+
if (!this.client.settings.local)
|
|
87
|
+
new XernerxLog(this.client).warn(`Slash commands might not work as you haven't specified a local guild ID.`);
|
|
88
|
+
options = z
|
|
89
|
+
.object({
|
|
90
|
+
directory: z.string(),
|
|
91
|
+
cooldown: z.number().default(0),
|
|
92
|
+
permissions: z
|
|
93
|
+
.object({
|
|
94
|
+
user: z.array(z.string()).or(z.null()).default(null),
|
|
95
|
+
client: z.array(z.string()).or(z.null()).default(null),
|
|
96
|
+
dm: z.boolean().default(true),
|
|
97
|
+
})
|
|
98
|
+
.default({}),
|
|
99
|
+
logging: z.boolean().default(false),
|
|
100
|
+
defer: z
|
|
101
|
+
.object({
|
|
102
|
+
reply: z.boolean().default(false),
|
|
103
|
+
ephemeral: z.boolean().default(false),
|
|
104
|
+
fetchReply: z.boolean().default(false),
|
|
105
|
+
})
|
|
106
|
+
.default({}),
|
|
107
|
+
})
|
|
108
|
+
.parse(options);
|
|
109
|
+
this.client.modules.options.slash = options;
|
|
110
|
+
const files = await this.readdir(options.directory, 'SlashCommands');
|
|
111
|
+
for (const file of files) {
|
|
112
|
+
const filepath = `${path.resolve(options.directory)}\\${file}`;
|
|
113
|
+
const command = await this.load(filepath, 'SlashCommand');
|
|
114
|
+
commands.push(command.id);
|
|
115
|
+
}
|
|
116
|
+
new XernerxLog(this.client).info(`Loaded ${Style.log(String(files.length), { color: Style.TextColor.Cyan })} Slash Commands: ${commands.map((command) => Style.log(command, { color: Style.TextColor.LightYellow })).join(', ')}`);
|
|
117
|
+
this.emit({
|
|
118
|
+
name: 'interactionCreate',
|
|
119
|
+
filetype: 'SlashCommand',
|
|
120
|
+
run: (interaction) => this.slashCommandRun(interaction),
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
async loadContextCommands(options) {
|
|
124
|
+
const commands = [];
|
|
125
|
+
if (!this.client.settings.local)
|
|
126
|
+
new XernerxLog(this.client).warn(`Context commands might not work as you haven't specified a local guild ID.`);
|
|
127
|
+
options = z
|
|
128
|
+
.object({
|
|
129
|
+
directory: z.string(),
|
|
130
|
+
cooldown: z.number().default(0),
|
|
131
|
+
permissions: z
|
|
132
|
+
.object({
|
|
133
|
+
user: z.array(z.string()).or(z.null()).default(null),
|
|
134
|
+
client: z.array(z.string()).or(z.null()).default(null),
|
|
135
|
+
dm: z.boolean().default(true),
|
|
136
|
+
})
|
|
137
|
+
.default({}),
|
|
138
|
+
logging: z.boolean().default(false),
|
|
139
|
+
defer: z
|
|
140
|
+
.object({
|
|
141
|
+
reply: z.boolean().default(false),
|
|
142
|
+
ephemeral: z.boolean().default(false),
|
|
143
|
+
fetchReply: z.boolean().default(false),
|
|
144
|
+
})
|
|
145
|
+
.default({}),
|
|
146
|
+
})
|
|
147
|
+
.parse(options);
|
|
148
|
+
this.client.modules.options.context = options;
|
|
149
|
+
const files = await this.readdir(options.directory, 'ContextCommands');
|
|
150
|
+
for (const file of files) {
|
|
151
|
+
const filepath = `${path.resolve(options.directory)}\\${file}`;
|
|
152
|
+
const command = await this.load(filepath, 'ContextCommand');
|
|
153
|
+
commands.push(command.id);
|
|
154
|
+
}
|
|
155
|
+
new XernerxLog(this.client).info(`Loaded ${Style.log(String(files.length), { color: Style.TextColor.Cyan })} Context Commands: ${commands.map((command) => Style.log(command, { color: Style.TextColor.LightYellow })).join(', ')}`);
|
|
156
|
+
this.emit({
|
|
157
|
+
name: 'interactionCreate',
|
|
158
|
+
filetype: 'ContextCommand',
|
|
159
|
+
run: (interaction) => this.contextCommandRun(interaction),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
async messageCommandRun(message, message2) {
|
|
163
|
+
const filetype = 'MessageCommand';
|
|
164
|
+
if (message.author.id === this.client.user?.id && this.client.settings.ignore?.self)
|
|
165
|
+
return;
|
|
166
|
+
else if (message.author.bot && this.client.settings.ignore?.bots)
|
|
167
|
+
return;
|
|
168
|
+
if (message.system && this.client.settings.ignore?.system)
|
|
169
|
+
return;
|
|
170
|
+
message.util = new MessageUtil(this.client, message);
|
|
171
|
+
message.user = new XernerxUser(this.client, message);
|
|
172
|
+
if (await inhibitorValidation(message, undefined, undefined, 'pre'))
|
|
173
|
+
return;
|
|
174
|
+
if (typeof message2 === 'object')
|
|
175
|
+
message = message2;
|
|
176
|
+
if (message2 === 'delete' && this.client.modules.options.message?.handleDeletes) {
|
|
177
|
+
if (!this.client.cache.messages.has(message.id))
|
|
178
|
+
return;
|
|
179
|
+
const id = this.client.cache.messages.get(message.id);
|
|
180
|
+
if (!id)
|
|
181
|
+
return;
|
|
182
|
+
(async () => {
|
|
183
|
+
const msg = await message.channel.messages.fetch(id);
|
|
184
|
+
await msg.delete();
|
|
185
|
+
this.client.cache.messages.delete(message.id);
|
|
186
|
+
})();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (message.content && this.client.modules.options.message) {
|
|
190
|
+
const commands = this.client.commands.message;
|
|
191
|
+
const prefixes = Array.isArray(this.client.modules.options.message.prefix) ? this.client.modules.options.message.prefix : [this.client.modules.options.message.prefix];
|
|
192
|
+
let commandName = null, cmd, commandAlias = null, commandPrefix = null;
|
|
193
|
+
commands.map((command) => {
|
|
194
|
+
let prefix = null;
|
|
195
|
+
if (command.regex && message.content.match(command.regex)) {
|
|
196
|
+
const [match] = message.content.match(command.regex) || [null];
|
|
197
|
+
if (match)
|
|
198
|
+
commandName = command.name;
|
|
199
|
+
}
|
|
200
|
+
const cp = Array.isArray(command.prefix) ? command.prefix : [command.prefix];
|
|
201
|
+
prefixes.map((p) => {
|
|
202
|
+
if (message.content.startsWith(p))
|
|
203
|
+
prefix = p;
|
|
204
|
+
});
|
|
205
|
+
cp.map((p) => {
|
|
206
|
+
if (message.content.startsWith(p))
|
|
207
|
+
prefix = p;
|
|
208
|
+
});
|
|
209
|
+
if (!prefix)
|
|
210
|
+
return;
|
|
211
|
+
if (!commandName)
|
|
212
|
+
commandName =
|
|
213
|
+
message.content
|
|
214
|
+
.replace(prefix, '')
|
|
215
|
+
.split(command.separator || / +/)
|
|
216
|
+
.shift()
|
|
217
|
+
?.trim()
|
|
218
|
+
?.toLowerCase() || '';
|
|
219
|
+
if (!this.client.commands.message.has(commandName) && command.aliases?.includes(commandName)) {
|
|
220
|
+
commandAlias = commandName;
|
|
221
|
+
commandName = command.name;
|
|
222
|
+
}
|
|
223
|
+
commandAlias = commandAlias ? commandAlias : commandName;
|
|
224
|
+
commandPrefix = prefix;
|
|
225
|
+
});
|
|
226
|
+
if (!cmd && this.client.modules.options.message.allowMention) {
|
|
227
|
+
if (message.mentions.users.has(this.client.user?.id) || message.mentions.repliedUser?.id === this.client.user?.id) {
|
|
228
|
+
commandName =
|
|
229
|
+
message.content
|
|
230
|
+
.replace(`<@${this.client.user?.id}>`, '')
|
|
231
|
+
.trim()
|
|
232
|
+
.split(/ +/)
|
|
233
|
+
.shift()
|
|
234
|
+
?.toLowerCase() || null;
|
|
235
|
+
commands.map((command) => {
|
|
236
|
+
if (command.aliases?.includes(commandName)) {
|
|
237
|
+
commandName = command.name;
|
|
238
|
+
return (commandAlias = commandName);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
commandPrefix = `<@${this.client.user?.id}>`;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (this.client.commands.message.has(commandName)) {
|
|
245
|
+
if (this.client.modules.options.message?.handleTyping)
|
|
246
|
+
message.channel.sendTyping();
|
|
247
|
+
cmd = this.client.commands.message.get(commandName);
|
|
248
|
+
}
|
|
249
|
+
if (!commandPrefix || !commandName)
|
|
250
|
+
return;
|
|
251
|
+
if (!cmd)
|
|
252
|
+
return await this.client.emit('commandNotFound', message, commandName, filetype);
|
|
253
|
+
await this.client.emit('commandStart', message, cmd);
|
|
254
|
+
const args = await messageArguments(message, cmd, commandPrefix);
|
|
255
|
+
message.util.parsed = {
|
|
256
|
+
alias: commandAlias,
|
|
257
|
+
prefix: commandPrefix,
|
|
258
|
+
args: args.args,
|
|
259
|
+
};
|
|
260
|
+
cmd.util = message.util;
|
|
261
|
+
return await this.exec(cmd, message, args, filetype);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async slashCommandRun(interaction) {
|
|
265
|
+
const filetype = 'SlashCommand';
|
|
266
|
+
interaction.util = new InteractionUtil(this.client, interaction);
|
|
267
|
+
interaction.user = new XernerxUser(this.client, interaction);
|
|
268
|
+
if (await inhibitorValidation(interaction, undefined, undefined, 'pre'))
|
|
269
|
+
return;
|
|
270
|
+
let cmd = null;
|
|
271
|
+
if (this.client.commands.slash.has(interaction.commandName))
|
|
272
|
+
cmd = this.client.commands.slash.get(interaction.commandName);
|
|
273
|
+
if (!cmd)
|
|
274
|
+
return this.client.emit('commandNotFound', interaction, interaction.commandName, filetype);
|
|
275
|
+
new Promise(async (resolve) => {
|
|
276
|
+
if (interaction.isAutocomplete()) {
|
|
277
|
+
const focused = interaction.options.getFocused(true);
|
|
278
|
+
const options = interaction.options;
|
|
279
|
+
await cmd.autocomplete(interaction, focused, options);
|
|
280
|
+
}
|
|
281
|
+
else
|
|
282
|
+
resolve(true);
|
|
283
|
+
})
|
|
284
|
+
.then(async () => {
|
|
285
|
+
await this.client.emit('commandStart', interaction);
|
|
286
|
+
const args = await interactionArguments(interaction, cmd);
|
|
287
|
+
interaction.util.parsed = {
|
|
288
|
+
alias: [interaction.commandName, args.group || null, args.subcommand || null].filter((x) => x).join(' '),
|
|
289
|
+
args: args.args,
|
|
290
|
+
};
|
|
291
|
+
cmd.util = interaction.util;
|
|
292
|
+
return await this.exec(cmd, interaction, args, filetype);
|
|
293
|
+
})
|
|
294
|
+
.catch((error) => this.client.emit('commandError', interaction, error, cmd));
|
|
295
|
+
}
|
|
296
|
+
async contextCommandRun(interaction) {
|
|
297
|
+
const filetype = 'ContextCommand';
|
|
298
|
+
interaction.util = new InteractionUtil(this.client, interaction);
|
|
299
|
+
interaction.user = new XernerxUser(this.client, interaction);
|
|
300
|
+
if (await inhibitorValidation(interaction, undefined, undefined, 'pre'))
|
|
301
|
+
return;
|
|
302
|
+
let cmd;
|
|
303
|
+
if (this.client.commands.context.has(interaction.commandName))
|
|
304
|
+
cmd = this.client.commands.context.get(interaction.commandName);
|
|
305
|
+
if (!cmd)
|
|
306
|
+
return this.client.emit('commandNotFound', interaction, interaction.commandName, filetype);
|
|
307
|
+
await this.client.emit('commandStart', interaction);
|
|
308
|
+
const args = await interactionArguments(interaction, cmd);
|
|
309
|
+
interaction.util.parsed = {
|
|
310
|
+
alias: interaction.commandName,
|
|
311
|
+
args: args,
|
|
312
|
+
};
|
|
313
|
+
cmd.util = interaction.util;
|
|
314
|
+
return await this.exec(cmd, interaction, args, filetype);
|
|
315
|
+
}
|
|
316
|
+
async exec(cmd, event, args, type) {
|
|
317
|
+
try {
|
|
318
|
+
if (cmd.filetype == 'SlashCommand' && (cmd?.defer?.reply ?? this.client.modules.options.slash?.defer?.reply)) {
|
|
319
|
+
await event.deferReply({
|
|
320
|
+
ephemeral: cmd.defer?.ephemeral || this.client.modules.options.slash?.defer?.ephemeral || false,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
if (cmd.filetype == 'ContextCommand' && (cmd?.defer?.reply ?? this.client.modules.options.context?.defer?.reply)) {
|
|
324
|
+
await event.deferReply({
|
|
325
|
+
ephemeral: cmd.defer?.ephemeral || this.client.modules.options.context?.defer?.ephemeral || false,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
if (await commandValidation(event, cmd))
|
|
329
|
+
return;
|
|
330
|
+
if (await inhibitorValidation(event, args, cmd, 'check'))
|
|
331
|
+
return;
|
|
332
|
+
if (cmd.conditions && (await cmd.conditions(event, args)))
|
|
333
|
+
return;
|
|
334
|
+
await cmd.exec(event, args);
|
|
335
|
+
await inhibitorValidation(event, args, cmd, 'post');
|
|
336
|
+
return await this.client.emit('commandFinish', event, cmd);
|
|
337
|
+
}
|
|
338
|
+
catch (error) {
|
|
339
|
+
new XernerxLog(this.client).error(`An error occurred executing ${Style.log(cmd.name, { color: Style.TextColor.Blue })}`, error);
|
|
340
|
+
return await this.client.emit('commandError', event, error, cmd);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
_checks(command) {
|
|
344
|
+
if ((command.strict?.voice || command.ignore?.voice) && !this.client.options.intents.has('GuildVoiceStates'))
|
|
345
|
+
new XernerxLog(this.client).warn(`${Style.log(command.id, { color: Style.TextColor.Blue })} options ${Style.log(`Xernerx${command.filetype}#strict#voice`, {
|
|
346
|
+
color: Style.BackgroundColor.Grey,
|
|
347
|
+
})} or ${Style.log(`Xernerx${command.filetype}#ignore#voice`, {
|
|
348
|
+
color: Style.BackgroundColor.Grey,
|
|
349
|
+
})} will misbehave due to missing the ${Style.log('GuildVoiceStates', { color: Style.TextColor.Yellow })} intent.`);
|
|
350
|
+
}
|
|
326
351
|
}
|