reciple 6.0.0-dev.18 → 6.0.0-dev.19

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