xernerx 4.17.3 → 4.17.5

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