reciple 6.0.0-dev.26 → 6.0.0-dev.27

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 (46) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +183 -183
  3. package/dist/lib/bin.mjs +67 -67
  4. package/dist/lib/esm.mjs +1 -1
  5. package/dist/lib/index.js +33 -33
  6. package/dist/lib/reciple/classes/RecipleClient.js +307 -307
  7. package/dist/lib/reciple/classes/RecipleConfig.js +106 -106
  8. package/dist/lib/reciple/classes/RecipleModule.js +94 -94
  9. package/dist/lib/reciple/classes/builders/MessageCommandBuilder.js +309 -309
  10. package/dist/lib/reciple/classes/builders/MessageCommandOptionBuilder.js +126 -126
  11. package/dist/lib/reciple/classes/builders/SlashCommandBuilder.js +246 -246
  12. package/dist/lib/reciple/classes/managers/ApplicationCommandManager.js +178 -178
  13. package/dist/lib/reciple/classes/managers/CommandCooldownManager.js +99 -99
  14. package/dist/lib/reciple/classes/managers/CommandManager.js +60 -60
  15. package/dist/lib/reciple/classes/managers/MessageCommandOptionManager.js +25 -25
  16. package/dist/lib/reciple/classes/managers/ModuleManager.js +180 -176
  17. package/dist/lib/reciple/flags.js +31 -31
  18. package/dist/lib/reciple/permissions.js +30 -30
  19. package/dist/lib/reciple/types/builders.js +11 -11
  20. package/dist/lib/reciple/types/commands.js +15 -15
  21. package/dist/lib/reciple/types/paramOptions.js +2 -2
  22. package/dist/lib/reciple/util.js +71 -71
  23. package/dist/lib/reciple/version.js +47 -47
  24. package/dist/types/bin.d.mts +2 -2
  25. package/dist/types/esm.d.mts +1 -1
  26. package/dist/types/index.d.ts +17 -17
  27. package/dist/types/reciple/classes/RecipleClient.d.ts +114 -114
  28. package/dist/types/reciple/classes/RecipleConfig.d.ts +100 -100
  29. package/dist/types/reciple/classes/RecipleModule.d.ts +56 -56
  30. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +189 -189
  31. package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +53 -53
  32. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +98 -98
  33. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +53 -53
  34. package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +70 -70
  35. package/dist/types/reciple/classes/managers/CommandManager.d.ts +34 -34
  36. package/dist/types/reciple/classes/managers/MessageCommandOptionManager.d.ts +22 -22
  37. package/dist/types/reciple/classes/managers/ModuleManager.d.ts +49 -49
  38. package/dist/types/reciple/flags.d.ts +17 -17
  39. package/dist/types/reciple/permissions.d.ts +15 -15
  40. package/dist/types/reciple/types/builders.d.ts +205 -205
  41. package/dist/types/reciple/types/commands.d.ts +81 -81
  42. package/dist/types/reciple/types/paramOptions.d.ts +101 -101
  43. package/dist/types/reciple/util.d.ts +26 -26
  44. package/dist/types/reciple/version.d.ts +25 -25
  45. package/package.json +1 -1
  46. package/resource/reciple.yml +120 -120
@@ -1,307 +1,307 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RecipleClient = exports.RecipleEvents = void 0;
4
- const discord_js_1 = require("discord.js");
5
- const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
6
- const SlashCommandBuilder_1 = require("./builders/SlashCommandBuilder");
7
- const commands_1 = require("../types/commands");
8
- const CommandCooldownManager_1 = require("./managers/CommandCooldownManager");
9
- const builders_1 = require("../types/builders");
10
- const permissions_1 = require("../permissions");
11
- const MessageCommandOptionManager_1 = require("./managers/MessageCommandOptionManager");
12
- const ApplicationCommandManager_1 = require("./managers/ApplicationCommandManager");
13
- const CommandManager_1 = require("./managers/CommandManager");
14
- const ModuleManager_1 = require("./managers/ModuleManager");
15
- const RecipleConfig_1 = require("./RecipleConfig");
16
- const fallout_utility_1 = require("fallout-utility");
17
- const util_1 = require("../util");
18
- const version_js_1 = require("../version.js");
19
- const flags_1 = require("../flags");
20
- var RecipleEvents;
21
- (function (RecipleEvents) {
22
- RecipleEvents["RecipleCommandExecute"] = "recipleCommandExecute";
23
- RecipleEvents["RecipleCommandHalt"] = "recipleCommandHalt";
24
- RecipleEvents["RecipleRegisterApplicationCommands"] = "recipleRegisterApplicationCommands";
25
- RecipleEvents["RecipleReplyError"] = "recipleReplyError";
26
- RecipleEvents["CommandExecute"] = "recipleCommandExecute";
27
- RecipleEvents["CommandHalt"] = "recipleCommandHalt";
28
- RecipleEvents["RegisterApplicationCommands"] = "recipleRegisterApplicationCommands";
29
- RecipleEvents["ReplyError"] = "recipleReplyError";
30
- })(RecipleEvents = exports.RecipleEvents || (exports.RecipleEvents = {}));
31
- class RecipleClient extends discord_js_1.Client {
32
- /**
33
- * @param options Client options
34
- */
35
- constructor(options) {
36
- super(options);
37
- this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
38
- this.commands = new CommandManager_1.CommandManager({
39
- client: this,
40
- });
41
- this.cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
42
- this.modules = new ModuleManager_1.ModuleManager({
43
- client: this,
44
- });
45
- this.version = version_js_1.version;
46
- this.logger = (0, util_1.createLogger)(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
47
- this.config = { ...this.config, ...(options.config ?? {}) };
48
- if (this.config.fileLogging.enabled)
49
- this.logger.logFile(util_1.path.join(flags_1.cwd, this.config.fileLogging.logFilePath ?? 'logs/latest.log'), false);
50
- this.cwd = options.cwd ?? process.cwd();
51
- this.applicationCommands = new ApplicationCommandManager_1.ApplicationCommandManager(this);
52
- }
53
- get isClientLogsSilent() {
54
- return !this.config.fileLogging.clientLogs;
55
- }
56
- /**
57
- * Listed to command executions
58
- */
59
- addCommandListeners() {
60
- this.on(discord_js_1.Events.MessageCreate, message => {
61
- if (this.config.commands.messageCommand.enabled)
62
- this.messageCommandExecute(message);
63
- });
64
- this.on(discord_js_1.Events.InteractionCreate, interaction => {
65
- if (this.config.commands.slashCommand.enabled)
66
- this.slashCommandExecute(interaction);
67
- });
68
- return this;
69
- }
70
- /**
71
- * Execute a slash command
72
- * @param interaction Slash command interaction
73
- */
74
- async slashCommandExecute(interaction) {
75
- if (!interaction || !interaction.isChatInputCommand() || !this.isReady())
76
- return;
77
- if (!this.config.commands.slashCommand.acceptRepliedInteractions && (interaction.replied || interaction.deferred))
78
- return;
79
- const command = this.commands.get(interaction.commandName, builders_1.CommandType.SlashCommand);
80
- if (!command)
81
- return;
82
- const executeData = {
83
- interaction,
84
- builder: command,
85
- client: this,
86
- };
87
- if ((0, permissions_1.userHasCommandPermissions)({
88
- builder: command,
89
- memberPermissions: interaction.memberPermissions ?? undefined,
90
- commandPermissions: this.config.commands.slashCommand.permissions,
91
- })) {
92
- if (!command)
93
- return;
94
- if (interaction.inCachedGuild() && !(0, permissions_1.botHasExecutePermissions)(interaction.channel || interaction.guild, command.requiredBotPermissions)) {
95
- if (!(await this._haltCommand(command, {
96
- executeData,
97
- reason: commands_1.CommandHaltReason.MissingBotPermissions,
98
- }))) {
99
- await interaction.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
100
- }
101
- return;
102
- }
103
- const userCooldown = {
104
- user: interaction.user,
105
- command: command.name,
106
- channel: interaction.channel ?? undefined,
107
- guild: interaction.guild,
108
- type: builders_1.CommandType.SlashCommand,
109
- };
110
- if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
111
- this.cooldowns.add({
112
- ...userCooldown,
113
- expireTime: Date.now() + command.cooldown,
114
- });
115
- }
116
- else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
117
- if (!(await this._haltCommand(command, {
118
- executeData,
119
- reason: commands_1.CommandHaltReason.Cooldown,
120
- ...this.cooldowns.get(userCooldown),
121
- }))) {
122
- await interaction.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
123
- }
124
- return;
125
- }
126
- return this._executeCommand(command, executeData);
127
- }
128
- else if (!(await this._haltCommand(command, {
129
- executeData,
130
- reason: commands_1.CommandHaltReason.MissingMemberPermissions,
131
- }))) {
132
- await interaction.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
133
- }
134
- }
135
- /**
136
- * Execute a Message command
137
- * @param message Message command executor
138
- * @param prefix Message command prefix
139
- */
140
- async messageCommandExecute(message, prefix) {
141
- if (!message.content || !this.isReady())
142
- return;
143
- const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
144
- if (!parseCommand || !parseCommand?.command)
145
- return;
146
- const command = this.commands.get(parseCommand.command, builders_1.CommandType.MessageCommand);
147
- if (!command)
148
- return;
149
- const commandOptions = await MessageCommandBuilder_1.MessageCommandBuilder.validateOptions(command, parseCommand);
150
- const executeData = {
151
- message: message,
152
- options: commandOptions,
153
- command: parseCommand,
154
- builder: command,
155
- client: this,
156
- };
157
- if ((0, permissions_1.userHasCommandPermissions)({
158
- builder: command,
159
- memberPermissions: message.member?.permissions,
160
- commandPermissions: this.config.commands.messageCommand.permissions,
161
- })) {
162
- if ((!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM) || (!command.allowExecuteByBots && (message.author.bot || message.author.system)))
163
- return;
164
- if (command.validateOptions) {
165
- if (commandOptions.some(o => o.invalid)) {
166
- if (!(await this._haltCommand(command, {
167
- executeData,
168
- reason: commands_1.CommandHaltReason.InvalidArguments,
169
- invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)),
170
- }))) {
171
- message.reply(this.getConfigMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
172
- }
173
- return;
174
- }
175
- if (commandOptions.some(o => o.missing)) {
176
- if (!(await this._haltCommand(command, {
177
- executeData,
178
- reason: commands_1.CommandHaltReason.MissingArguments,
179
- missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)),
180
- }))) {
181
- message.reply(this.getConfigMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
182
- }
183
- return;
184
- }
185
- }
186
- if (message.inGuild() && !(0, permissions_1.botHasExecutePermissions)(message.channel || message.guild, command.requiredBotPermissions)) {
187
- if (!(await this._haltCommand(command, {
188
- executeData,
189
- reason: commands_1.CommandHaltReason.MissingBotPermissions,
190
- }))) {
191
- message.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
192
- }
193
- return;
194
- }
195
- const userCooldown = {
196
- user: message.author,
197
- command: command.name,
198
- channel: message.channel,
199
- guild: message.guild,
200
- type: builders_1.CommandType.MessageCommand,
201
- };
202
- if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
203
- this.cooldowns.add({
204
- ...userCooldown,
205
- expireTime: Date.now() + command.cooldown,
206
- });
207
- }
208
- else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
209
- if (!(await this._haltCommand(command, {
210
- executeData,
211
- reason: commands_1.CommandHaltReason.Cooldown,
212
- ...this.cooldowns.get(userCooldown),
213
- }))) {
214
- await message.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
215
- }
216
- return;
217
- }
218
- return this._executeCommand(command, executeData);
219
- }
220
- else if (!(await this._haltCommand(command, {
221
- executeData,
222
- reason: commands_1.CommandHaltReason.MissingMemberPermissions,
223
- }))) {
224
- message.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
225
- }
226
- }
227
- /**
228
- * Get a message from config
229
- * @param messageKey Config messages key
230
- * @param defaultMessage Default message when the key does not exists
231
- */
232
- getConfigMessage(messageKey, defaultMessage) {
233
- return this.config.messages[messageKey] ?? defaultMessage ?? messageKey;
234
- }
235
- /**
236
- * Emits the {@link RecipleClientEvents["recipleReplyError"]} event
237
- * @param error Received Error
238
- */
239
- _replyError(error) {
240
- this.emit(RecipleEvents.ReplyError, error);
241
- }
242
- async _haltCommand(command, haltData) {
243
- try {
244
- const haltResolved = (command.halt
245
- ? await Promise.resolve(command.type == builders_1.CommandType.SlashCommand ? command.halt(haltData) : command.halt(haltData)).catch(err => {
246
- console.log(err);
247
- })
248
- : false) || false;
249
- this.emit(RecipleEvents.CommandHalt, haltData);
250
- return haltResolved;
251
- }
252
- catch (err) {
253
- if (!this.isClientLogsSilent) {
254
- this.logger.error(`An error occured executing command halt for "${command.name}"`);
255
- this.logger.error(err);
256
- }
257
- return false;
258
- }
259
- }
260
- async _executeCommand(command, executeData) {
261
- try {
262
- await Promise.resolve(command.type === builders_1.CommandType.SlashCommand ? command.execute(executeData) : command.execute(executeData))
263
- .then(() => this.emit(RecipleEvents.CommandExecute, executeData))
264
- .catch(async (err) => !(await this._haltCommand(command, {
265
- executeData: executeData,
266
- reason: commands_1.CommandHaltReason.Error,
267
- error: err,
268
- }))
269
- ? this._commandExecuteError(err, executeData)
270
- : void 0);
271
- return executeData;
272
- }
273
- catch (err) {
274
- if (await this._haltCommand(command, {
275
- executeData: executeData,
276
- reason: commands_1.CommandHaltReason.Error,
277
- error: err,
278
- }))
279
- return;
280
- await this._commandExecuteError(err, executeData);
281
- }
282
- }
283
- /**
284
- * Error message when a command fails to execute
285
- * @param err Received error
286
- * @param command Slash/Message command execute data
287
- */
288
- async _commandExecuteError(err, command) {
289
- if (!this.isClientLogsSilent) {
290
- this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
291
- this.logger.error(err);
292
- }
293
- if (!err || !command)
294
- return;
295
- if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
296
- if (!this.config.commands.slashCommand.replyOnError)
297
- return;
298
- await command.interaction.followUp(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
299
- }
300
- else if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
301
- if (!this.config.commands.messageCommand.replyOnError)
302
- return;
303
- await command.message.reply(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
304
- }
305
- }
306
- }
307
- exports.RecipleClient = RecipleClient;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecipleClient = exports.RecipleEvents = void 0;
4
+ const discord_js_1 = require("discord.js");
5
+ const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
6
+ const SlashCommandBuilder_1 = require("./builders/SlashCommandBuilder");
7
+ const commands_1 = require("../types/commands");
8
+ const CommandCooldownManager_1 = require("./managers/CommandCooldownManager");
9
+ const builders_1 = require("../types/builders");
10
+ const permissions_1 = require("../permissions");
11
+ const MessageCommandOptionManager_1 = require("./managers/MessageCommandOptionManager");
12
+ const ApplicationCommandManager_1 = require("./managers/ApplicationCommandManager");
13
+ const CommandManager_1 = require("./managers/CommandManager");
14
+ const ModuleManager_1 = require("./managers/ModuleManager");
15
+ const RecipleConfig_1 = require("./RecipleConfig");
16
+ const fallout_utility_1 = require("fallout-utility");
17
+ const util_1 = require("../util");
18
+ const version_js_1 = require("../version.js");
19
+ const flags_1 = require("../flags");
20
+ var RecipleEvents;
21
+ (function (RecipleEvents) {
22
+ RecipleEvents["RecipleCommandExecute"] = "recipleCommandExecute";
23
+ RecipleEvents["RecipleCommandHalt"] = "recipleCommandHalt";
24
+ RecipleEvents["RecipleRegisterApplicationCommands"] = "recipleRegisterApplicationCommands";
25
+ RecipleEvents["RecipleReplyError"] = "recipleReplyError";
26
+ RecipleEvents["CommandExecute"] = "recipleCommandExecute";
27
+ RecipleEvents["CommandHalt"] = "recipleCommandHalt";
28
+ RecipleEvents["RegisterApplicationCommands"] = "recipleRegisterApplicationCommands";
29
+ RecipleEvents["ReplyError"] = "recipleReplyError";
30
+ })(RecipleEvents = exports.RecipleEvents || (exports.RecipleEvents = {}));
31
+ class RecipleClient extends discord_js_1.Client {
32
+ /**
33
+ * @param options Client options
34
+ */
35
+ constructor(options) {
36
+ super(options);
37
+ this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
38
+ this.commands = new CommandManager_1.CommandManager({
39
+ client: this,
40
+ });
41
+ this.cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
42
+ this.modules = new ModuleManager_1.ModuleManager({
43
+ client: this,
44
+ });
45
+ this.version = version_js_1.version;
46
+ this.logger = (0, util_1.createLogger)(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
47
+ this.config = { ...this.config, ...(options.config ?? {}) };
48
+ if (this.config.fileLogging.enabled)
49
+ this.logger.logFile(util_1.path.join(flags_1.cwd, this.config.fileLogging.logFilePath ?? 'logs/latest.log'), false);
50
+ this.cwd = options.cwd ?? process.cwd();
51
+ this.applicationCommands = new ApplicationCommandManager_1.ApplicationCommandManager(this);
52
+ }
53
+ get isClientLogsSilent() {
54
+ return !this.config.fileLogging.clientLogs;
55
+ }
56
+ /**
57
+ * Listed to command executions
58
+ */
59
+ addCommandListeners() {
60
+ this.on(discord_js_1.Events.MessageCreate, message => {
61
+ if (this.config.commands.messageCommand.enabled)
62
+ this.messageCommandExecute(message);
63
+ });
64
+ this.on(discord_js_1.Events.InteractionCreate, interaction => {
65
+ if (this.config.commands.slashCommand.enabled)
66
+ this.slashCommandExecute(interaction);
67
+ });
68
+ return this;
69
+ }
70
+ /**
71
+ * Execute a slash command
72
+ * @param interaction Slash command interaction
73
+ */
74
+ async slashCommandExecute(interaction) {
75
+ if (!interaction || !interaction.isChatInputCommand() || !this.isReady())
76
+ return;
77
+ if (!this.config.commands.slashCommand.acceptRepliedInteractions && (interaction.replied || interaction.deferred))
78
+ return;
79
+ const command = this.commands.get(interaction.commandName, builders_1.CommandType.SlashCommand);
80
+ if (!command)
81
+ return;
82
+ const executeData = {
83
+ interaction,
84
+ builder: command,
85
+ client: this,
86
+ };
87
+ if ((0, permissions_1.userHasCommandPermissions)({
88
+ builder: command,
89
+ memberPermissions: interaction.memberPermissions ?? undefined,
90
+ commandPermissions: this.config.commands.slashCommand.permissions,
91
+ })) {
92
+ if (!command)
93
+ return;
94
+ if (interaction.inCachedGuild() && !(0, permissions_1.botHasExecutePermissions)(interaction.channel || interaction.guild, command.requiredBotPermissions)) {
95
+ if (!(await this._haltCommand(command, {
96
+ executeData,
97
+ reason: commands_1.CommandHaltReason.MissingBotPermissions,
98
+ }))) {
99
+ await interaction.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
100
+ }
101
+ return;
102
+ }
103
+ const userCooldown = {
104
+ user: interaction.user,
105
+ command: command.name,
106
+ channel: interaction.channel ?? undefined,
107
+ guild: interaction.guild,
108
+ type: builders_1.CommandType.SlashCommand,
109
+ };
110
+ if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
111
+ this.cooldowns.add({
112
+ ...userCooldown,
113
+ expireTime: Date.now() + command.cooldown,
114
+ });
115
+ }
116
+ else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
117
+ if (!(await this._haltCommand(command, {
118
+ executeData,
119
+ reason: commands_1.CommandHaltReason.Cooldown,
120
+ ...this.cooldowns.get(userCooldown),
121
+ }))) {
122
+ await interaction.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
123
+ }
124
+ return;
125
+ }
126
+ return this._executeCommand(command, executeData);
127
+ }
128
+ else if (!(await this._haltCommand(command, {
129
+ executeData,
130
+ reason: commands_1.CommandHaltReason.MissingMemberPermissions,
131
+ }))) {
132
+ await interaction.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
133
+ }
134
+ }
135
+ /**
136
+ * Execute a Message command
137
+ * @param message Message command executor
138
+ * @param prefix Message command prefix
139
+ */
140
+ async messageCommandExecute(message, prefix) {
141
+ if (!message.content || !this.isReady())
142
+ return;
143
+ const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
144
+ if (!parseCommand || !parseCommand?.command)
145
+ return;
146
+ const command = this.commands.get(parseCommand.command, builders_1.CommandType.MessageCommand);
147
+ if (!command)
148
+ return;
149
+ const commandOptions = await MessageCommandBuilder_1.MessageCommandBuilder.validateOptions(command, parseCommand);
150
+ const executeData = {
151
+ message: message,
152
+ options: commandOptions,
153
+ command: parseCommand,
154
+ builder: command,
155
+ client: this,
156
+ };
157
+ if ((0, permissions_1.userHasCommandPermissions)({
158
+ builder: command,
159
+ memberPermissions: message.member?.permissions,
160
+ commandPermissions: this.config.commands.messageCommand.permissions,
161
+ })) {
162
+ if ((!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM) || (!command.allowExecuteByBots && (message.author.bot || message.author.system)))
163
+ return;
164
+ if (command.validateOptions) {
165
+ if (commandOptions.some(o => o.invalid)) {
166
+ if (!(await this._haltCommand(command, {
167
+ executeData,
168
+ reason: commands_1.CommandHaltReason.InvalidArguments,
169
+ invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)),
170
+ }))) {
171
+ message.reply(this.getConfigMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
172
+ }
173
+ return;
174
+ }
175
+ if (commandOptions.some(o => o.missing)) {
176
+ if (!(await this._haltCommand(command, {
177
+ executeData,
178
+ reason: commands_1.CommandHaltReason.MissingArguments,
179
+ missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)),
180
+ }))) {
181
+ message.reply(this.getConfigMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
182
+ }
183
+ return;
184
+ }
185
+ }
186
+ if (message.inGuild() && !(0, permissions_1.botHasExecutePermissions)(message.channel || message.guild, command.requiredBotPermissions)) {
187
+ if (!(await this._haltCommand(command, {
188
+ executeData,
189
+ reason: commands_1.CommandHaltReason.MissingBotPermissions,
190
+ }))) {
191
+ message.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
192
+ }
193
+ return;
194
+ }
195
+ const userCooldown = {
196
+ user: message.author,
197
+ command: command.name,
198
+ channel: message.channel,
199
+ guild: message.guild,
200
+ type: builders_1.CommandType.MessageCommand,
201
+ };
202
+ if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
203
+ this.cooldowns.add({
204
+ ...userCooldown,
205
+ expireTime: Date.now() + command.cooldown,
206
+ });
207
+ }
208
+ else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
209
+ if (!(await this._haltCommand(command, {
210
+ executeData,
211
+ reason: commands_1.CommandHaltReason.Cooldown,
212
+ ...this.cooldowns.get(userCooldown),
213
+ }))) {
214
+ await message.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
215
+ }
216
+ return;
217
+ }
218
+ return this._executeCommand(command, executeData);
219
+ }
220
+ else if (!(await this._haltCommand(command, {
221
+ executeData,
222
+ reason: commands_1.CommandHaltReason.MissingMemberPermissions,
223
+ }))) {
224
+ message.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
225
+ }
226
+ }
227
+ /**
228
+ * Get a message from config
229
+ * @param messageKey Config messages key
230
+ * @param defaultMessage Default message when the key does not exists
231
+ */
232
+ getConfigMessage(messageKey, defaultMessage) {
233
+ return this.config.messages[messageKey] ?? defaultMessage ?? messageKey;
234
+ }
235
+ /**
236
+ * Emits the {@link RecipleClientEvents["recipleReplyError"]} event
237
+ * @param error Received Error
238
+ */
239
+ _replyError(error) {
240
+ this.emit(RecipleEvents.ReplyError, error);
241
+ }
242
+ async _haltCommand(command, haltData) {
243
+ try {
244
+ const haltResolved = (command.halt
245
+ ? await Promise.resolve(command.type == builders_1.CommandType.SlashCommand ? command.halt(haltData) : command.halt(haltData)).catch(err => {
246
+ console.log(err);
247
+ })
248
+ : false) || false;
249
+ this.emit(RecipleEvents.CommandHalt, haltData);
250
+ return haltResolved;
251
+ }
252
+ catch (err) {
253
+ if (!this.isClientLogsSilent) {
254
+ this.logger.error(`An error occured executing command halt for "${command.name}"`);
255
+ this.logger.error(err);
256
+ }
257
+ return false;
258
+ }
259
+ }
260
+ async _executeCommand(command, executeData) {
261
+ try {
262
+ await Promise.resolve(command.type === builders_1.CommandType.SlashCommand ? command.execute(executeData) : command.execute(executeData))
263
+ .then(() => this.emit(RecipleEvents.CommandExecute, executeData))
264
+ .catch(async (err) => !(await this._haltCommand(command, {
265
+ executeData: executeData,
266
+ reason: commands_1.CommandHaltReason.Error,
267
+ error: err,
268
+ }))
269
+ ? this._commandExecuteError(err, executeData)
270
+ : void 0);
271
+ return executeData;
272
+ }
273
+ catch (err) {
274
+ if (await this._haltCommand(command, {
275
+ executeData: executeData,
276
+ reason: commands_1.CommandHaltReason.Error,
277
+ error: err,
278
+ }))
279
+ return;
280
+ await this._commandExecuteError(err, executeData);
281
+ }
282
+ }
283
+ /**
284
+ * Error message when a command fails to execute
285
+ * @param err Received error
286
+ * @param command Slash/Message command execute data
287
+ */
288
+ async _commandExecuteError(err, command) {
289
+ if (!this.isClientLogsSilent) {
290
+ this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
291
+ this.logger.error(err);
292
+ }
293
+ if (!err || !command)
294
+ return;
295
+ if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
296
+ if (!this.config.commands.slashCommand.replyOnError)
297
+ return;
298
+ await command.interaction.followUp(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
299
+ }
300
+ else if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
301
+ if (!this.config.commands.messageCommand.replyOnError)
302
+ return;
303
+ await command.message.reply(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
304
+ }
305
+ }
306
+ }
307
+ exports.RecipleClient = RecipleClient;