xernerx 4.5.23 → 4.5.26

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 (70) hide show
  1. package/README.md +3 -0
  2. package/dist/build/XernerxContextCommand.d.ts +42 -50
  3. package/dist/build/XernerxContextCommand.js +71 -71
  4. package/dist/build/XernerxEvent.d.ts +15 -15
  5. package/dist/build/XernerxEvent.js +22 -22
  6. package/dist/build/XernerxInhibitor.d.ts +14 -25
  7. package/dist/build/XernerxInhibitor.js +20 -20
  8. package/dist/build/XernerxMessageCommand.d.ts +47 -53
  9. package/dist/build/XernerxMessageCommand.js +70 -70
  10. package/dist/build/XernerxSlashCommand.d.ts +57 -71
  11. package/dist/build/XernerxSlashCommand.js +128 -128
  12. package/dist/client/XernerxClient.d.ts +40 -48
  13. package/dist/client/XernerxClient.js +77 -77
  14. package/dist/client/XernerxShardClient.d.ts +12 -12
  15. package/dist/client/XernerxShardClient.js +39 -47
  16. package/dist/functions/deploy.d.ts +1 -1
  17. package/dist/functions/deploy.js +36 -31
  18. package/dist/functions/load.d.ts +1 -1
  19. package/dist/functions/load.js +29 -28
  20. package/dist/functions/reload.d.ts +1 -1
  21. package/dist/functions/reload.js +38 -35
  22. package/dist/functions/sendWebhook.d.ts +1 -1
  23. package/dist/functions/sendWebhook.js +12 -11
  24. package/dist/functions/setPresence.d.ts +2 -2
  25. package/dist/functions/setPresence.js +17 -18
  26. package/dist/functions/xernerxUser.d.ts +1 -1
  27. package/dist/functions/xernerxUser.js +6 -6
  28. package/dist/handlers/CommandHandler.d.ts +9 -9
  29. package/dist/handlers/CommandHandler.d.ts.map +1 -1
  30. package/dist/handlers/CommandHandler.js +281 -249
  31. package/dist/handlers/CommandHandler.js.map +1 -1
  32. package/dist/handlers/EventHandler.d.ts +3 -3
  33. package/dist/handlers/EventHandler.js +19 -19
  34. package/dist/handlers/ExtensionHandler.d.ts +3 -3
  35. package/dist/handlers/ExtensionHandler.js +20 -18
  36. package/dist/handlers/Handler.d.ts +8 -8
  37. package/dist/handlers/Handler.js +42 -32
  38. package/dist/handlers/InhibitorHandler.d.ts +3 -3
  39. package/dist/handlers/InhibitorHandler.js +19 -19
  40. package/dist/handlers/WebhookHandler.d.ts +6 -4
  41. package/dist/handlers/WebhookHandler.js +44 -47
  42. package/dist/main.d.ts +22 -29
  43. package/dist/main.js +22 -29
  44. package/dist/models/Arguments.d.ts +2 -5
  45. package/dist/models/Arguments.js +150 -135
  46. package/dist/tools/XernerxError.d.ts +5 -5
  47. package/dist/tools/XernerxError.js +9 -9
  48. package/dist/tools/XernerxLog.d.ts +13 -13
  49. package/dist/tools/XernerxLog.js +69 -74
  50. package/dist/tools/XernerxText.d.ts +23 -23
  51. package/dist/tools/XernerxText.js +85 -76
  52. package/dist/types/extenders.d.ts +36 -44
  53. package/dist/types/extenders.js +1 -1
  54. package/dist/types/interfaces.d.ts +182 -185
  55. package/dist/types/interfaces.js +1 -1
  56. package/dist/types/types.d.ts +7 -179
  57. package/dist/types/types.js +1 -1
  58. package/dist/utils/ClientUtil.d.ts +9 -11
  59. package/dist/utils/ClientUtil.js +73 -57
  60. package/dist/utils/InteractionUtil.d.ts +7 -7
  61. package/dist/utils/InteractionUtil.js +98 -96
  62. package/dist/utils/MessageUtil.d.ts +11 -11
  63. package/dist/utils/MessageUtil.js +135 -130
  64. package/dist/utils/Util.d.ts +5 -5
  65. package/dist/utils/Util.js +8 -8
  66. package/dist/validators/commandValidation.d.ts +2 -5
  67. package/dist/validators/commandValidation.js +53 -43
  68. package/dist/validators/inhibitorValidations.d.ts +3 -19
  69. package/dist/validators/inhibitorValidations.js +31 -31
  70. package/package.json +16 -13
@@ -3,13 +3,13 @@ import XernerxClient from '../client/XernerxClient.js';
3
3
  import { ContextHandlerOptions, MessageHandlerOptions, SlashHandlerOptions } from '../types/interfaces.js';
4
4
  import Handler from './Handler.js';
5
5
  export default class CommandHandler extends Handler {
6
- constructor(client: XernerxClient);
7
- loadMessageCommands(options: MessageHandlerOptions): void;
8
- loadSlashCommands(options: SlashHandlerOptions): void;
9
- loadContextCommands(options: ContextHandlerOptions): void;
10
- private messageCommandRun;
11
- private slashCommandRun;
12
- private contextCommandRun;
13
- private exec;
6
+ constructor(client: XernerxClient);
7
+ loadMessageCommands(options: MessageHandlerOptions): void;
8
+ loadSlashCommands(options: SlashHandlerOptions): void;
9
+ loadContextCommands(options: ContextHandlerOptions): void;
10
+ private messageCommandRun;
11
+ private slashCommandRun;
12
+ private contextCommandRun;
13
+ private exec;
14
14
  }
15
- //# sourceMappingURL=CommandHandler.d.ts.map
15
+ //# sourceMappingURL=CommandHandler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CommandHandler.d.ts","sourceRoot":"","sources":["../../src/handlers/CommandHandler.ts"],"names":[],"mappings":"AAAA,cAAc;AAMd,OAAO,aAAa,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC3G,OAAO,OAAO,MAAM,cAAc,CAAC;AAenC,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,OAAO;gBACtC,MAAM,EAAE,aAAa;IAI1B,mBAAmB,CAAC,OAAO,EAAE,qBAAqB;IA2DlD,iBAAiB,CAAC,OAAO,EAAE,mBAAmB;IA4C9C,mBAAmB,CAAC,OAAO,EAAE,qBAAqB;YA4C3C,iBAAiB;YAwHjB,eAAe;YA+Bf,iBAAiB;YAoBjB,IAAI;CAoBlB"}
1
+ {"version":3,"file":"CommandHandler.d.ts","sourceRoot":"","sources":["../../src/handlers/CommandHandler.ts"],"names":[],"mappings":"AAAA,cAAc;AAMd,OAAO,aAAa,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC3G,OAAO,OAAO,MAAM,cAAc,CAAC;AAenC,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,OAAO;gBACtC,MAAM,EAAE,aAAa;IAI1B,mBAAmB,CAAC,OAAO,EAAE,qBAAqB;IA2DlD,iBAAiB,CAAC,OAAO,EAAE,mBAAmB;IA4C9C,mBAAmB,CAAC,OAAO,EAAE,qBAAqB;YA4C3C,iBAAiB;YA8HjB,eAAe;YA+Bf,iBAAiB;YAoBjB,IAAI;CAoBlB"}
@@ -12,253 +12,285 @@ 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
- }
18
- loadMessageCommands(options) {
19
- 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!`);
20
- 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!`);
21
- options = z
22
- .object({
23
- directory: z.string(),
24
- prefix: z.string().or(z.array(z.string())),
25
- allowMention: z.boolean().default(false),
26
- cooldown: z.number().default(0),
27
- permissions: z
28
- .object({
29
- user: z.array(z.string()).default([]),
30
- client: z.array(z.string()).default([]),
31
- dm: z.boolean().default(true),
32
- })
33
- .default({}),
34
- handleEdits: z.boolean().default(false),
35
- handleDeletes: z.boolean().default(false),
36
- handleTyping: z.boolean().default(false),
37
- logging: z.boolean().default(false),
38
- })
39
- .parse(options);
40
- this.client.modules.options.message = options;
41
- const files = this.readdir(options.directory);
42
- for (const file of files) {
43
- const filepath = `${path.resolve(options.directory)}\\${file}`;
44
- this.load(filepath, 'MessageCommand');
45
- }
46
- new XernerxLog(this.client).info(`Loaded ${Style.log(String(files.length), { color: Style.TextColor.Cyan })} Message Commands.`);
47
- this.emit({
48
- name: 'messageCreate',
49
- filetype: 'MessageCommand',
50
- run: (message) => this.messageCommandRun(message),
51
- });
52
- this.emit({
53
- name: 'messageUpdate',
54
- filetype: 'MessageCommand',
55
- run: (message, message2) => this.messageCommandRun(message, message2),
56
- });
57
- this.emit({
58
- name: 'messageDelete',
59
- filetype: 'MessageCommand',
60
- run: (message) => this.messageCommandRun(message, 'delete'),
61
- });
62
- }
63
- // public reloadMessageCommands() {
64
- // return reload(this.client, 'message');
65
- // }
66
- loadSlashCommands(options) {
67
- if (!this.client.settings.local) new XernerxLog(this.client).warn(`Slash commands might not work as you haven't specified a local guild ID.`);
68
- options = z
69
- .object({
70
- directory: z.string(),
71
- cooldown: z.number().default(0),
72
- permissions: z
73
- .object({
74
- user: z.array(z.string()).default([]),
75
- client: z.array(z.string()).default([]),
76
- dm: z.boolean().default(true),
77
- })
78
- .default({}),
79
- logging: z.boolean().default(false),
80
- defer: z
81
- .object({
82
- reply: z.boolean().default(false),
83
- ephemeral: z.boolean().default(false),
84
- fetchReply: z.boolean().default(false),
85
- })
86
- .default({}),
87
- })
88
- .parse(options);
89
- this.client.modules.options.slash = options;
90
- const files = this.readdir(options.directory);
91
- for (const file of files) {
92
- const filepath = `${path.resolve(options.directory)}\\${file}`;
93
- this.load(filepath, 'SlashCommand');
94
- }
95
- new XernerxLog(this.client).info(`Loaded ${Style.log(String(files.length), { color: Style.TextColor.Cyan })} Slash Commands.`);
96
- this.emit({
97
- name: 'interactionCreate',
98
- filetype: 'SlashCommand',
99
- run: (interaction) => this.slashCommandRun(interaction),
100
- });
101
- }
102
- loadContextCommands(options) {
103
- if (!this.client.settings.local) new XernerxLog(this.client).warn(`Context commands might not work as you haven't specified a local guild ID.`);
104
- options = z
105
- .object({
106
- directory: z.string(),
107
- cooldown: z.number().default(0),
108
- permissions: z
109
- .object({
110
- user: z.array(z.string()).default([]),
111
- client: z.array(z.string()).default([]),
112
- dm: z.boolean().default(true),
113
- })
114
- .default({}),
115
- logging: z.boolean().default(false),
116
- defer: z
117
- .object({
118
- reply: z.boolean().default(false),
119
- ephemeral: z.boolean().default(false),
120
- fetchReply: z.boolean().default(false),
121
- })
122
- .default({}),
123
- })
124
- .parse(options);
125
- this.client.modules.options.context = options;
126
- const files = this.readdir(options.directory);
127
- for (const file of files) {
128
- const filepath = `${path.resolve(options.directory)}\\${file}`;
129
- this.load(filepath, 'ContextCommand');
130
- }
131
- new XernerxLog(this.client).info(`Loaded ${Style.log(String(files.length), { color: Style.TextColor.Cyan })} Context Commands.`);
132
- this.emit({
133
- name: 'interactionCreate',
134
- filetype: 'ContextCommand',
135
- run: (interaction) => this.contextCommandRun(interaction),
136
- });
137
- }
138
- async messageCommandRun(message, message2) {
139
- const filetype = 'MessageCommand';
140
- if (message.author.id === this.client.user?.id && this.client.settings.ignore?.self) return;
141
- else if (message.author.bot && this.client.settings.ignore?.bots) return;
142
- if (message.system && this.client.settings.ignore?.system) return;
143
- message.util = new MessageUtil(this.client, message);
144
- message.user = await xernerxUser(message, this.client);
145
- if (typeof message2 === 'object') message = message2;
146
- if (message2 === 'delete' && this.client.modules.options.message?.handleDeletes) {
147
- if (!this.client.cache.messages.has(message.id)) return;
148
- const id = this.client.cache.messages.get(message.id);
149
- if (!id) return;
150
- (async () => {
151
- const msg = await message.channel.messages.fetch(id);
152
- await msg.delete();
153
- this.client.cache.messages.delete(message.id);
154
- })();
155
- return;
156
- }
157
- if (message.content && this.client.modules.options.message) {
158
- const commands = this.client.commands.message;
159
- const prefixes = Array.isArray(this.client.modules.options.message.prefix) ? this.client.modules.options.message.prefix : [this.client.modules.options.message.prefix];
160
- let commandName = null,
161
- cmd,
162
- commandAlias = null,
163
- commandPrefix = null;
164
- commands.map((command) => {
165
- let prefix = null;
166
- if (command.regex && message.content.match(command.regex)) {
167
- const [match] = message.content.match(command.regex) || [null];
168
- if (match) commandName = command.name;
169
- }
170
- const cp = Array.isArray(command.prefix) ? command.prefix : [command.prefix];
171
- prefixes.map((p) => {
172
- if (message.content.startsWith(p)) prefix = p;
173
- });
174
- cp.map((p) => {
175
- if (message.content.startsWith(p)) prefix = p;
176
- });
177
- if (!prefix) return;
178
- if (!commandName)
179
- commandName =
180
- message.content
181
- .replace(prefix, '')
182
- .split(command.separator || / +/)
183
- .shift()
184
- ?.trim()
185
- ?.toLowerCase() || '';
186
- if (!this.client.commands.message.has(commandName) && command.aliases?.includes(commandName)) {
187
- commandAlias = commandName;
188
- commandName = command.name;
189
- }
190
- commandAlias = commandAlias ? commandAlias : commandName;
191
- commandPrefix = prefix;
192
- });
193
- if (!cmd && this.client.modules.options.message.allowMention) {
194
- if (message.mentions.users.has(this.client.user?.id) || message.mentions.repliedUser?.id === this.client.user?.id) {
195
- commandName = message.content.replace(`<@${this.client.user?.id}>`, '').trim().split(/ +/).shift()?.toLowerCase() || null;
196
- commands.map((command) => {
197
- if (command.aliases?.includes(commandName)) {
198
- commandName = command.name;
199
- return (commandAlias = commandName);
200
- }
201
- });
202
- commandPrefix = `<@${this.client.user?.id}>`;
203
- }
204
- }
205
- if (this.client.commands.message.has(commandName)) {
206
- if (this.client.modules.options.message?.handleTyping) message.channel.sendTyping();
207
- cmd = this.client.commands.message.get(commandName);
208
- }
209
- if (!commandPrefix || !commandName) return;
210
- if (!cmd) return await this.client.emit('commandNotFound', message, commandName, filetype);
211
- if (await inhibitorValidation(message, cmd)) return;
212
- message.util.parsed = {
213
- alias: commandAlias,
214
- prefix: commandPrefix,
215
- };
216
- this.client.emit('commandStart', message, cmd, filetype);
217
- return await this.exec(cmd, message, await messageArguments(message, cmd, commandPrefix), filetype);
218
- }
219
- }
220
- async slashCommandRun(interaction) {
221
- const filetype = 'SlashCommand';
222
- interaction.util = new InteractionUtil(this.client, interaction);
223
- interaction.user = await xernerxUser(interaction, this.client);
224
- let cmd = null;
225
- if (this.client.commands.slash.has(interaction.commandName)) cmd = this.client.commands.slash.get(interaction.commandName);
226
- if (await inhibitorValidation(interaction, cmd)) return;
227
- if (!cmd) return this.client.emit('commandNotFound', interaction, interaction.commandName, filetype);
228
- new Promise(async (resolve) => {
229
- if (interaction.isAutocomplete()) {
230
- const focused = interaction.options.getFocused(true);
231
- const options = interaction.options;
232
- await cmd.autocomplete(interaction, focused, options);
233
- } else resolve(true);
234
- })
235
- .then(async () => {
236
- this.client.emit('commandStart', interaction, filetype);
237
- return await this.exec(cmd, interaction, await interactionArguments(interaction, cmd), filetype);
238
- })
239
- .catch((error) => this.client.emit('commandError', interaction, error, cmd, filetype));
240
- }
241
- async contextCommandRun(interaction) {
242
- const filetype = 'ContextCommand';
243
- interaction.util = new InteractionUtil(this.client, interaction);
244
- interaction.user = await xernerxUser(interaction, this.client);
245
- let cmd;
246
- if (this.client.commands.context.has(interaction.commandName)) cmd = this.client.commands.context.get(interaction.commandName);
247
- if (await inhibitorValidation(interaction, cmd)) return;
248
- if (!cmd) return this.client.emit('commandNotFound', interaction, interaction.commandName, filetype);
249
- this.client.emit('commandStart', interaction, filetype);
250
- return await this.exec(cmd, interaction, await interactionArguments(interaction, cmd), filetype);
251
- }
252
- async exec(cmd, event, args, type) {
253
- try {
254
- if (await commandValidation(event, cmd)) return;
255
- if (cmd.conditions && (await cmd.conditions(event, args))) return;
256
- await cmd.exec(event, args);
257
- return await this.client.emit('commandFinish', event, type);
258
- } catch (error) {
259
- new XernerxLog(this.client).error(`An error occurred executing ${Style.log(cmd.name, { color: Style.TextColor.Blue })}`, error);
260
- return await this.client.emit('commandError', event, error, cmd, type);
261
- }
262
- }
15
+ constructor(client) {
16
+ super(client);
17
+ }
18
+ loadMessageCommands(options) {
19
+ if (!this.client.options.intents.has(GatewayIntentBits.MessageContent))
20
+ new XernerxLog(this.client).warn(`Message commands might not work as you're missing the intent MessageContent!`);
21
+ if (!this.client.options.intents.has(GatewayIntentBits.GuildMessages))
22
+ 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()).default([]),
32
+ client: z.array(z.string()).default([]),
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 = this.readdir(options.directory);
44
+ for (const file of files) {
45
+ const filepath = `${path.resolve(options.directory)}\\${file}`;
46
+ this.load(filepath, 'MessageCommand');
47
+ }
48
+ new XernerxLog(this.client).info(`Loaded ${Style.log(String(files.length), { color: Style.TextColor.Cyan })} Message Commands.`);
49
+ this.emit({
50
+ name: 'messageCreate',
51
+ filetype: 'MessageCommand',
52
+ run: (message) => this.messageCommandRun(message),
53
+ });
54
+ this.emit({
55
+ name: 'messageUpdate',
56
+ filetype: 'MessageCommand',
57
+ run: (message, message2) => this.messageCommandRun(message, message2),
58
+ });
59
+ this.emit({
60
+ name: 'messageDelete',
61
+ filetype: 'MessageCommand',
62
+ run: (message) => this.messageCommandRun(message, 'delete'),
63
+ });
64
+ }
65
+ // public reloadMessageCommands() {
66
+ // return reload(this.client, 'message');
67
+ // }
68
+ loadSlashCommands(options) {
69
+ if (!this.client.settings.local)
70
+ new XernerxLog(this.client).warn(`Slash commands might not work as you haven't specified a local guild ID.`);
71
+ options = z
72
+ .object({
73
+ directory: z.string(),
74
+ cooldown: z.number().default(0),
75
+ permissions: z
76
+ .object({
77
+ user: z.array(z.string()).default([]),
78
+ client: z.array(z.string()).default([]),
79
+ dm: z.boolean().default(true),
80
+ })
81
+ .default({}),
82
+ logging: z.boolean().default(false),
83
+ defer: z
84
+ .object({
85
+ reply: z.boolean().default(false),
86
+ ephemeral: z.boolean().default(false),
87
+ fetchReply: z.boolean().default(false),
88
+ })
89
+ .default({}),
90
+ })
91
+ .parse(options);
92
+ this.client.modules.options.slash = options;
93
+ const files = this.readdir(options.directory);
94
+ for (const file of files) {
95
+ const filepath = `${path.resolve(options.directory)}\\${file}`;
96
+ this.load(filepath, 'SlashCommand');
97
+ }
98
+ new XernerxLog(this.client).info(`Loaded ${Style.log(String(files.length), { color: Style.TextColor.Cyan })} Slash Commands.`);
99
+ this.emit({
100
+ name: 'interactionCreate',
101
+ filetype: 'SlashCommand',
102
+ run: (interaction) => this.slashCommandRun(interaction),
103
+ });
104
+ }
105
+ loadContextCommands(options) {
106
+ if (!this.client.settings.local)
107
+ new XernerxLog(this.client).warn(`Context commands might not work as you haven't specified a local guild ID.`);
108
+ options = z
109
+ .object({
110
+ directory: z.string(),
111
+ cooldown: z.number().default(0),
112
+ permissions: z
113
+ .object({
114
+ user: z.array(z.string()).default([]),
115
+ client: z.array(z.string()).default([]),
116
+ dm: z.boolean().default(true),
117
+ })
118
+ .default({}),
119
+ logging: z.boolean().default(false),
120
+ defer: z
121
+ .object({
122
+ reply: z.boolean().default(false),
123
+ ephemeral: z.boolean().default(false),
124
+ fetchReply: z.boolean().default(false),
125
+ })
126
+ .default({}),
127
+ })
128
+ .parse(options);
129
+ this.client.modules.options.context = options;
130
+ const files = this.readdir(options.directory);
131
+ for (const file of files) {
132
+ const filepath = `${path.resolve(options.directory)}\\${file}`;
133
+ this.load(filepath, 'ContextCommand');
134
+ }
135
+ new XernerxLog(this.client).info(`Loaded ${Style.log(String(files.length), { color: Style.TextColor.Cyan })} Context Commands.`);
136
+ this.emit({
137
+ name: 'interactionCreate',
138
+ filetype: 'ContextCommand',
139
+ run: (interaction) => this.contextCommandRun(interaction),
140
+ });
141
+ }
142
+ async messageCommandRun(message, message2) {
143
+ const filetype = 'MessageCommand';
144
+ if (message.author.id === this.client.user?.id && this.client.settings.ignore?.self)
145
+ return;
146
+ else if (message.author.bot && this.client.settings.ignore?.bots)
147
+ return;
148
+ if (message.system && this.client.settings.ignore?.system)
149
+ return;
150
+ message.util = new MessageUtil(this.client, message);
151
+ message.user = await xernerxUser(message, this.client);
152
+ if (typeof message2 === 'object')
153
+ message = message2;
154
+ if (message2 === 'delete' && this.client.modules.options.message?.handleDeletes) {
155
+ if (!this.client.cache.messages.has(message.id))
156
+ return;
157
+ const id = this.client.cache.messages.get(message.id);
158
+ if (!id)
159
+ return;
160
+ (async () => {
161
+ const msg = await message.channel.messages.fetch(id);
162
+ await msg.delete();
163
+ this.client.cache.messages.delete(message.id);
164
+ })();
165
+ return;
166
+ }
167
+ if (message.content && this.client.modules.options.message) {
168
+ const commands = this.client.commands.message;
169
+ const prefixes = Array.isArray(this.client.modules.options.message.prefix) ? this.client.modules.options.message.prefix : [this.client.modules.options.message.prefix];
170
+ let commandName = null, cmd, commandAlias = null, commandPrefix = null;
171
+ commands.map((command) => {
172
+ let prefix = null;
173
+ if (command.regex && message.content.match(command.regex)) {
174
+ const [match] = message.content.match(command.regex) || [null];
175
+ if (match)
176
+ commandName = command.name;
177
+ }
178
+ const cp = Array.isArray(command.prefix) ? command.prefix : [command.prefix];
179
+ prefixes.map((p) => {
180
+ if (message.content.startsWith(p))
181
+ prefix = p;
182
+ });
183
+ cp.map((p) => {
184
+ if (message.content.startsWith(p))
185
+ prefix = p;
186
+ });
187
+ if (!prefix)
188
+ return;
189
+ if (!commandName)
190
+ commandName =
191
+ message.content
192
+ .replace(prefix, '')
193
+ .split(command.separator || / +/)
194
+ .shift()
195
+ ?.trim()
196
+ ?.toLowerCase() || '';
197
+ if (!this.client.commands.message.has(commandName) && command.aliases?.includes(commandName)) {
198
+ commandAlias = commandName;
199
+ commandName = command.name;
200
+ }
201
+ commandAlias = commandAlias ? commandAlias : commandName;
202
+ commandPrefix = prefix;
203
+ });
204
+ if (!cmd && this.client.modules.options.message.allowMention) {
205
+ if (message.mentions.users.has(this.client.user?.id) || message.mentions.repliedUser?.id === this.client.user?.id) {
206
+ commandName =
207
+ message.content
208
+ .replace(`<@${this.client.user?.id}>`, '')
209
+ .trim()
210
+ .split(/ +/)
211
+ .shift()
212
+ ?.toLowerCase() || null;
213
+ commands.map((command) => {
214
+ if (command.aliases?.includes(commandName)) {
215
+ commandName = command.name;
216
+ return (commandAlias = commandName);
217
+ }
218
+ });
219
+ commandPrefix = `<@${this.client.user?.id}>`;
220
+ }
221
+ }
222
+ if (this.client.commands.message.has(commandName)) {
223
+ if (this.client.modules.options.message?.handleTyping)
224
+ message.channel.sendTyping();
225
+ cmd = this.client.commands.message.get(commandName);
226
+ }
227
+ if (!commandPrefix || !commandName)
228
+ return;
229
+ if (!cmd)
230
+ return await this.client.emit('commandNotFound', message, commandName, filetype);
231
+ if (await inhibitorValidation(message, cmd))
232
+ return;
233
+ message.util.parsed = {
234
+ alias: commandAlias,
235
+ prefix: commandPrefix,
236
+ };
237
+ this.client.emit('commandStart', message, cmd, filetype);
238
+ return await this.exec(cmd, message, await messageArguments(message, cmd, commandPrefix), filetype);
239
+ }
240
+ }
241
+ async slashCommandRun(interaction) {
242
+ const filetype = 'SlashCommand';
243
+ interaction.util = new InteractionUtil(this.client, interaction);
244
+ interaction.user = await xernerxUser(interaction, this.client);
245
+ let cmd = null;
246
+ if (this.client.commands.slash.has(interaction.commandName))
247
+ cmd = this.client.commands.slash.get(interaction.commandName);
248
+ if (await inhibitorValidation(interaction, cmd))
249
+ return;
250
+ if (!cmd)
251
+ return this.client.emit('commandNotFound', interaction, interaction.commandName, filetype);
252
+ new Promise(async (resolve) => {
253
+ if (interaction.isAutocomplete()) {
254
+ const focused = interaction.options.getFocused(true);
255
+ const options = interaction.options;
256
+ await cmd.autocomplete(interaction, focused, options);
257
+ }
258
+ else
259
+ resolve(true);
260
+ })
261
+ .then(async () => {
262
+ this.client.emit('commandStart', interaction, filetype);
263
+ return await this.exec(cmd, interaction, await interactionArguments(interaction, cmd), filetype);
264
+ })
265
+ .catch((error) => this.client.emit('commandError', interaction, error, cmd, filetype));
266
+ }
267
+ async contextCommandRun(interaction) {
268
+ const filetype = 'ContextCommand';
269
+ interaction.util = new InteractionUtil(this.client, interaction);
270
+ interaction.user = await xernerxUser(interaction, this.client);
271
+ let cmd;
272
+ if (this.client.commands.context.has(interaction.commandName))
273
+ cmd = this.client.commands.context.get(interaction.commandName);
274
+ if (await inhibitorValidation(interaction, cmd))
275
+ return;
276
+ if (!cmd)
277
+ return this.client.emit('commandNotFound', interaction, interaction.commandName, filetype);
278
+ this.client.emit('commandStart', interaction, filetype);
279
+ return await this.exec(cmd, interaction, await interactionArguments(interaction, cmd), filetype);
280
+ }
281
+ async exec(cmd, event, args, type) {
282
+ try {
283
+ if (await commandValidation(event, cmd))
284
+ return;
285
+ if (cmd.conditions && (await cmd.conditions(event, args)))
286
+ return;
287
+ await cmd.exec(event, args);
288
+ return await this.client.emit('commandFinish', event, type);
289
+ }
290
+ catch (error) {
291
+ new XernerxLog(this.client).error(`An error occurred executing ${Style.log(cmd.name, { color: Style.TextColor.Blue })}`, error);
292
+ return await this.client.emit('commandError', event, error, cmd, type);
293
+ }
294
+ }
263
295
  }
264
- //# sourceMappingURL=CommandHandler.js.map
296
+ //# sourceMappingURL=CommandHandler.js.map