reciple 6.0.0-dev.22 → 6.0.0-dev.25

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