reciple 5.4.1 → 5.4.4

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.
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -30,122 +21,117 @@ const flags_1 = require("../flags");
30
21
  const path_1 = __importDefault(require("path"));
31
22
  const discord_js_1 = require("discord.js");
32
23
  class RecipleClient extends discord_js_1.Client {
24
+ config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
25
+ commands = { slashCommands: {}, messageCommands: {} };
26
+ additionalApplicationCommands = [];
27
+ cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
28
+ modules = [];
29
+ logger;
30
+ version = version_1.version;
33
31
  /**
34
32
  * @param options Client options
35
33
  */
36
34
  constructor(options) {
37
- var _a, _b, _c, _d;
38
35
  super(options);
39
- this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
40
- this.commands = { slashCommands: {}, messageCommands: {} };
41
- this.additionalApplicationCommands = [];
42
- this.cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
43
- this.modules = [];
44
- this.version = version_1.version;
45
- this.logger = (0, logger_1.createLogger)(!!((_a = options.config) === null || _a === void 0 ? void 0 : _a.fileLogging.stringifyLoggedJSON), (_b = options.config) === null || _b === void 0 ? void 0 : _b.fileLogging.debugmode);
36
+ this.logger = (0, logger_1.createLogger)(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
46
37
  if (!options.config)
47
38
  throw new Error('Config is not defined.');
48
- this.config = Object.assign(Object.assign({}, this.config), ((_c = options.config) !== null && _c !== void 0 ? _c : {}));
39
+ this.config = { ...this.config, ...(options.config ?? {}) };
49
40
  if (this.config.fileLogging.enabled)
50
- this.logger.logFile(path_1.default.join(flags_1.cwd, (_d = this.config.fileLogging.logFilePath) !== null && _d !== void 0 ? _d : 'logs/latest.log'), false);
41
+ this.logger.logFile(path_1.default.join(flags_1.cwd, this.config.fileLogging.logFilePath ?? 'logs/latest.log'), false);
51
42
  }
52
43
  /**
53
44
  * Load modules from modules folder
54
45
  * @param folders List of folders that contains the modules you want to load
55
46
  */
56
- startModules(...folders) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- folders = (0, discord_js_1.normalizeArray)(folders).map(f => path_1.default.join(flags_1.cwd, f));
59
- for (const folder of folders) {
47
+ async startModules(...folders) {
48
+ folders = (0, discord_js_1.normalizeArray)(folders).map(f => path_1.default.join(flags_1.cwd, f));
49
+ for (const folder of folders) {
50
+ if (this.isClientLogsEnabled())
51
+ this.logger.info(`Loading Modules from ${folder}`);
52
+ const modules = await (0, modules_1.getModules)(this, folder).catch(() => null);
53
+ if (!modules) {
60
54
  if (this.isClientLogsEnabled())
61
- this.logger.info(`Loading Modules from ${folder}`);
62
- const modules = yield (0, modules_1.getModules)(this, folder).catch(() => null);
63
- if (!modules) {
64
- if (this.isClientLogsEnabled())
65
- this.logger.error(`Failed to load modules from ${folder}`);
66
- continue;
67
- }
68
- this.modules.push(...modules.modules);
55
+ this.logger.error(`Failed to load modules from ${folder}`);
56
+ continue;
69
57
  }
70
- return this;
71
- });
58
+ this.modules.push(...modules.modules);
59
+ }
60
+ return this;
72
61
  }
73
62
  /**
74
63
  * Execute `onLoad()` from client modules and register application commands if enabled
75
64
  */
76
- loadModules() {
77
- var _a, _b;
78
- return __awaiter(this, void 0, void 0, function* () {
79
- for (const m in this.modules) {
80
- const module_ = this.modules[m];
81
- if (typeof ((_a = module_.script) === null || _a === void 0 ? void 0 : _a.onLoad) === 'function') {
82
- yield Promise.resolve(module_.script.onLoad(this)).catch(err => {
83
- var _a;
84
- if (this.isClientLogsEnabled()) {
85
- this.logger.error(`Error loading ${(_a = module_.info.filename) !== null && _a !== void 0 ? _a : 'unknown module'}:`);
86
- this.logger.error(err);
87
- }
88
- this.modules = this.modules.filter((_r, i) => i.toString() !== m.toString());
89
- });
90
- }
91
- if (typeof ((_b = module_.script) === null || _b === void 0 ? void 0 : _b.commands) !== 'undefined') {
92
- for (const command of module_.script.commands) {
93
- this.addCommand(command);
65
+ async loadModules() {
66
+ for (const m in this.modules) {
67
+ const module_ = this.modules[m];
68
+ if (typeof module_.script?.onLoad === 'function') {
69
+ await Promise.resolve(module_.script.onLoad(this)).catch(err => {
70
+ if (this.isClientLogsEnabled()) {
71
+ this.logger.error(`Error loading ${module_.info.filename ?? 'unknown module'}:`);
72
+ this.logger.error(err);
94
73
  }
95
- }
96
- }
97
- if (this.isClientLogsEnabled()) {
98
- this.logger.info(`${this.modules.length} modules loaded.`);
99
- this.logger.info(`${Object.keys(this.commands.messageCommands).length} message commands loaded.`);
100
- this.logger.info(`${Object.keys(this.commands.slashCommands).length} slash commands loaded.`);
101
- }
102
- if (this.config.commands.slashCommand.registerCommands) {
103
- yield (0, registerApplicationCommands_1.registerApplicationCommands)({
104
- client: this,
105
- commands: [...Object.values(this.commands.slashCommands), ...this.additionalApplicationCommands],
106
- guilds: this.config.commands.slashCommand.guilds
74
+ this.modules = this.modules.filter((_r, i) => i.toString() !== m.toString());
107
75
  });
108
76
  }
109
- return this;
110
- });
77
+ if (typeof module_.script?.commands !== 'undefined') {
78
+ for (const command of module_.script.commands) {
79
+ this.addCommand(command);
80
+ }
81
+ }
82
+ }
83
+ if (this.isClientLogsEnabled()) {
84
+ this.logger.info(`${this.modules.length} modules loaded.`);
85
+ this.logger.info(`${Object.keys(this.commands.messageCommands).length} message commands loaded.`);
86
+ this.logger.info(`${Object.keys(this.commands.slashCommands).length} slash commands loaded.`);
87
+ }
88
+ if (this.config.commands.slashCommand.registerCommands) {
89
+ await (0, registerApplicationCommands_1.registerApplicationCommands)({
90
+ client: this,
91
+ commands: [...Object.values(this.commands.slashCommands), ...this.additionalApplicationCommands],
92
+ guilds: this.config.commands.slashCommand.guilds
93
+ });
94
+ }
95
+ return this;
111
96
  }
112
97
  /**
113
98
  * Add module
114
99
  * @param options Module options
115
100
  */
116
- addModule(options) {
117
- var _a;
118
- return __awaiter(this, void 0, void 0, function* () {
119
- const { script } = options;
120
- const registerCommands = options.registerApplicationCommands;
121
- const info = options.moduleInfo;
122
- this.modules.push({
123
- script,
124
- info: Object.assign({ filename: undefined, versions: typeof script.versions == 'string' ? [script.versions] : script.versions, path: undefined }, info)
125
- });
126
- if (typeof (script === null || script === void 0 ? void 0 : script.onLoad) === 'function')
127
- yield Promise.resolve(script.onLoad(this));
128
- if (this.isClientLogsEnabled())
129
- this.logger.info(`${this.modules.length} modules loaded.`);
130
- for (const command of (_a = script.commands) !== null && _a !== void 0 ? _a : []) {
131
- if (!command.name)
132
- continue;
133
- this.addCommand(command);
101
+ async addModule(options) {
102
+ const { script } = options;
103
+ const registerCommands = options.registerApplicationCommands;
104
+ const info = options.moduleInfo;
105
+ this.modules.push({
106
+ script,
107
+ info: {
108
+ filename: undefined,
109
+ versions: typeof script.versions == 'string' ? [script.versions] : script.versions,
110
+ path: undefined,
111
+ ...info
134
112
  }
135
- if (registerCommands)
136
- yield (0, registerApplicationCommands_1.registerApplicationCommands)({
137
- client: this,
138
- commands: [...Object.values(this.commands.slashCommands), ...this.additionalApplicationCommands],
139
- guilds: this.config.commands.slashCommand.guilds
140
- });
141
113
  });
114
+ if (typeof script?.onLoad === 'function')
115
+ await Promise.resolve(script.onLoad(this));
116
+ if (this.isClientLogsEnabled())
117
+ this.logger.info(`${this.modules.length} modules loaded.`);
118
+ for (const command of script.commands ?? []) {
119
+ if (!command.name)
120
+ continue;
121
+ this.addCommand(command);
122
+ }
123
+ if (registerCommands)
124
+ await (0, registerApplicationCommands_1.registerApplicationCommands)({
125
+ client: this,
126
+ commands: [...Object.values(this.commands.slashCommands), ...this.additionalApplicationCommands],
127
+ guilds: this.config.commands.slashCommand.guilds
128
+ });
142
129
  }
143
130
  /**
144
131
  * Add slash or message command to client
145
132
  * @param command Slash/Message command builder
146
133
  */
147
134
  addCommand(command) {
148
- var _a;
149
135
  if (command.type === builders_1.CommandBuilderType.SlashCommand) {
150
136
  this.commands.slashCommands[command.name] = SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command);
151
137
  }
@@ -153,7 +139,7 @@ class RecipleClient extends discord_js_1.Client {
153
139
  this.commands.messageCommands[command.name] = MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command);
154
140
  }
155
141
  else if (this.isClientLogsEnabled()) {
156
- this.logger.error(`Unknow command "${(_a = typeof command) !== null && _a !== void 0 ? _a : 'unknown'}".`);
142
+ this.logger.error(`Unknow command "${typeof command ?? 'unknown'}".`);
157
143
  }
158
144
  return this;
159
145
  }
@@ -171,128 +157,122 @@ class RecipleClient extends discord_js_1.Client {
171
157
  * Execute a slash command
172
158
  * @param interaction Slash command interaction
173
159
  */
174
- slashCommandExecute(interaction) {
175
- var _a, _b;
176
- return __awaiter(this, void 0, void 0, function* () {
177
- if (!interaction || !interaction.isChatInputCommand() || !this.isReady())
178
- return;
179
- const command = this.findCommand(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
160
+ async slashCommandExecute(interaction) {
161
+ if (!interaction || !interaction.isChatInputCommand() || !this.isReady())
162
+ return;
163
+ const command = this.findCommand(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
164
+ if (!command)
165
+ return;
166
+ const executeData = {
167
+ interaction,
168
+ builder: command,
169
+ client: this
170
+ };
171
+ if ((0, permissions_1.userHasCommandPermissions)({
172
+ builder: command,
173
+ memberPermissions: interaction.memberPermissions ?? undefined,
174
+ commandPermissions: this.config.commands.slashCommand.permissions
175
+ })) {
180
176
  if (!command)
181
177
  return;
182
- const executeData = {
183
- interaction,
184
- builder: command,
185
- client: this
186
- };
187
- if ((0, permissions_1.userHasCommandPermissions)({
188
- builder: command,
189
- memberPermissions: (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined,
190
- commandPermissions: this.config.commands.slashCommand.permissions
191
- })) {
192
- if (!command)
193
- return;
194
- if (interaction.guild && !(0, permissions_1.botHasExecutePermissions)(interaction.guild, command.requiredBotPermissions)) {
195
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
196
- yield interaction.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
197
- }
198
- return;
199
- }
200
- const userCooldown = {
201
- user: interaction.user,
202
- command: command.name,
203
- channel: (_b = interaction.channel) !== null && _b !== void 0 ? _b : undefined,
204
- guild: interaction.guild,
205
- type: builders_1.CommandBuilderType.SlashCommand
206
- };
207
- if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
208
- this.cooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
178
+ if (interaction.inCachedGuild() && !(0, permissions_1.botHasExecutePermissions)(interaction.channel || interaction.guild, command.requiredBotPermissions)) {
179
+ if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions })) {
180
+ await interaction.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
209
181
  }
210
- else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
211
- if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.cooldowns.get(userCooldown))))) {
212
- yield interaction.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
213
- }
214
- return;
215
- }
216
- return this._executeCommand(command, executeData);
182
+ return;
217
183
  }
218
- else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
219
- yield interaction.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
184
+ const userCooldown = {
185
+ user: interaction.user,
186
+ command: command.name,
187
+ channel: interaction.channel ?? undefined,
188
+ guild: interaction.guild,
189
+ type: builders_1.CommandBuilderType.SlashCommand
190
+ };
191
+ if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
192
+ this.cooldowns.add({ ...userCooldown, expireTime: Date.now() + command.cooldown });
220
193
  }
221
- });
194
+ else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
195
+ if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Cooldown, ...this.cooldowns.get(userCooldown) })) {
196
+ await interaction.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
197
+ }
198
+ return;
199
+ }
200
+ return this._executeCommand(command, executeData);
201
+ }
202
+ else if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions })) {
203
+ await interaction.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
204
+ }
222
205
  }
223
206
  /**
224
207
  * Execute a Message command
225
208
  * @param message Message command executor
226
209
  * @param prefix Message command prefix
227
210
  */
228
- messageCommandExecute(message, prefix) {
229
- var _a;
230
- return __awaiter(this, void 0, void 0, function* () {
231
- if (!message.content || !this.isReady())
232
- return;
233
- const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
234
- if (!parseCommand || !(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command))
211
+ async messageCommandExecute(message, prefix) {
212
+ if (!message.content || !this.isReady())
213
+ return;
214
+ const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
215
+ if (!parseCommand || !parseCommand?.command)
216
+ return;
217
+ const command = this.findCommand(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
218
+ if (!command)
219
+ return;
220
+ const commandOptions = await (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
221
+ const executeData = {
222
+ message: message,
223
+ options: commandOptions,
224
+ command: parseCommand,
225
+ builder: command,
226
+ client: this
227
+ };
228
+ if ((0, permissions_1.userHasCommandPermissions)({
229
+ builder: command,
230
+ memberPermissions: message.member?.permissions,
231
+ commandPermissions: this.config.commands.messageCommand.permissions
232
+ })) {
233
+ if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM || !command.allowExecuteByBots && (message.author.bot || message.author.system))
235
234
  return;
236
- const command = this.findCommand(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
237
- if (!command)
238
- return;
239
- const commandOptions = yield (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
240
- const executeData = {
241
- message: message,
242
- options: commandOptions,
243
- command: parseCommand,
244
- builder: command,
245
- client: this
246
- };
247
- if ((0, permissions_1.userHasCommandPermissions)({
248
- builder: command,
249
- memberPermissions: (_a = message.member) === null || _a === void 0 ? void 0 : _a.permissions,
250
- commandPermissions: this.config.commands.messageCommand.permissions
251
- })) {
252
- if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM || !command.allowExecuteByBots && (message.author.bot || message.author.system))
253
- return;
254
- if (command.validateOptions) {
255
- if (commandOptions.some(o => o.invalid)) {
256
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)) }))) {
257
- message.reply(this.getConfigMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
258
- }
259
- return;
260
- }
261
- if (commandOptions.some(o => o.missing)) {
262
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)) }))) {
263
- message.reply(this.getConfigMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
264
- }
265
- return;
266
- }
267
- }
268
- if (message.guild && !(0, permissions_1.botHasExecutePermissions)(message.guild, command.requiredBotPermissions)) {
269
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
270
- message.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
235
+ if (command.validateOptions) {
236
+ if (commandOptions.some(o => o.invalid)) {
237
+ if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)) })) {
238
+ message.reply(this.getConfigMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
271
239
  }
272
240
  return;
273
241
  }
274
- const userCooldown = {
275
- user: message.author,
276
- command: command.name,
277
- channel: message.channel,
278
- guild: message.guild,
279
- type: builders_1.CommandBuilderType.MessageCommand
280
- };
281
- if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
282
- this.cooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
283
- }
284
- else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
285
- if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.cooldowns.get(userCooldown))))) {
286
- yield message.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
242
+ if (commandOptions.some(o => o.missing)) {
243
+ if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)) })) {
244
+ message.reply(this.getConfigMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
287
245
  }
288
246
  return;
289
247
  }
290
- return this._executeCommand(command, executeData);
291
248
  }
292
- else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
293
- message.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
249
+ if (message.inGuild() && !(0, permissions_1.botHasExecutePermissions)(message.channel || message.guild, command.requiredBotPermissions)) {
250
+ if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions })) {
251
+ message.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
252
+ }
253
+ return;
294
254
  }
295
- });
255
+ const userCooldown = {
256
+ user: message.author,
257
+ command: command.name,
258
+ channel: message.channel,
259
+ guild: message.guild,
260
+ type: builders_1.CommandBuilderType.MessageCommand
261
+ };
262
+ if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
263
+ this.cooldowns.add({ ...userCooldown, expireTime: Date.now() + command.cooldown });
264
+ }
265
+ else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
266
+ if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Cooldown, ...this.cooldowns.get(userCooldown) })) {
267
+ await message.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
268
+ }
269
+ return;
270
+ }
271
+ return this._executeCommand(command, executeData);
272
+ }
273
+ else if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions })) {
274
+ message.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
275
+ }
296
276
  }
297
277
  /**
298
278
  * Get a message from config
@@ -300,18 +280,17 @@ class RecipleClient extends discord_js_1.Client {
300
280
  * @param defaultMessage Default message when the key does not exists
301
281
  */
302
282
  getConfigMessage(messageKey, defaultMessage) {
303
- var _a, _b;
304
- return (_b = (_a = this.config.messages[messageKey]) !== null && _a !== void 0 ? _a : defaultMessage) !== null && _b !== void 0 ? _b : messageKey;
283
+ return this.config.messages[messageKey] ?? defaultMessage ?? messageKey;
305
284
  }
306
285
  findCommand(command, type) {
307
- var _a;
308
286
  switch (type) {
309
287
  case builders_1.CommandBuilderType.SlashCommand:
310
288
  return this.commands.slashCommands[command];
311
289
  case builders_1.CommandBuilderType.MessageCommand:
312
- return (_a = this.commands.messageCommands[command.toLowerCase()]) !== null && _a !== void 0 ? _a : (this.config.commands.messageCommand.allowCommandAlias
313
- ? Object.values(this.commands.messageCommands).find(c => c.aliases.some(a => a == (command === null || command === void 0 ? void 0 : command.toLowerCase())))
314
- : undefined);
290
+ return this.commands.messageCommands[command.toLowerCase()]
291
+ ?? (this.config.commands.messageCommand.allowCommandAlias
292
+ ? Object.values(this.commands.messageCommands).find(c => c.aliases.some(a => a == command?.toLowerCase()))
293
+ : undefined);
315
294
  default:
316
295
  throw new TypeError('Unknown command type');
317
296
  }
@@ -329,72 +308,63 @@ class RecipleClient extends discord_js_1.Client {
329
308
  _replyError(error) {
330
309
  this.emit('recipleReplyError', error);
331
310
  }
332
- _haltCommand(command, haltData) {
333
- var _a;
334
- return __awaiter(this, void 0, void 0, function* () {
335
- try {
336
- const haltResolved = (_a = (command.halt
337
- ? yield (command.type == builders_1.CommandBuilderType.SlashCommand
338
- ? Promise.resolve(command.halt(haltData))
339
- : Promise.resolve(command.halt(haltData))).catch(err => { throw err; })
340
- : false)) !== null && _a !== void 0 ? _a : false;
341
- this.emit('recipleCommandHalt', haltData);
342
- return haltResolved;
343
- }
344
- catch (err) {
345
- if (this.isClientLogsEnabled()) {
346
- this.logger.error(`An error occured executing command halt for "${command.name}"`);
347
- this.logger.error(err);
348
- }
349
- return false;
311
+ async _haltCommand(command, haltData) {
312
+ try {
313
+ const haltResolved = (command.halt
314
+ ? await Promise.resolve(command.type == builders_1.CommandBuilderType.SlashCommand
315
+ ? command.halt(haltData)
316
+ : command.halt(haltData)).catch(err => { console.log(err); })
317
+ : false) || false;
318
+ this.emit('recipleCommandHalt', haltData);
319
+ return haltResolved;
320
+ }
321
+ catch (err) {
322
+ if (this.isClientLogsEnabled()) {
323
+ this.logger.error(`An error occured executing command halt for "${command.name}"`);
324
+ this.logger.error(err);
350
325
  }
351
- });
326
+ return false;
327
+ }
352
328
  }
353
- _executeCommand(command, executeData) {
354
- return __awaiter(this, void 0, void 0, function* () {
355
- try {
356
- yield Promise.resolve(command.type === builders_1.CommandBuilderType.SlashCommand
357
- ? command.execute(executeData)
358
- : command.execute(executeData))
359
- .then(() => this.emit('recipleCommandExecute', executeData))
360
- .catch((err) => __awaiter(this, void 0, void 0, function* () {
361
- return (yield this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err }))
362
- ? this._commandExecuteError(err, executeData)
363
- : void 0;
364
- }));
365
- return executeData;
366
- }
367
- catch (err) {
368
- if (!(yield this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err }))) {
369
- this._commandExecuteError(err, executeData);
370
- }
329
+ async _executeCommand(command, executeData) {
330
+ try {
331
+ await Promise.resolve(command.type === builders_1.CommandBuilderType.SlashCommand
332
+ ? command.execute(executeData)
333
+ : command.execute(executeData))
334
+ .then(() => this.emit('recipleCommandExecute', executeData))
335
+ .catch(async (err) => !await this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err })
336
+ ? this._commandExecuteError(err, executeData)
337
+ : void 0);
338
+ return executeData;
339
+ }
340
+ catch (err) {
341
+ if (!await this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err })) {
342
+ this._commandExecuteError(err, executeData);
371
343
  }
372
- });
344
+ }
373
345
  }
374
346
  /**
375
347
  * Error message when a command fails to execute
376
348
  * @param err Received error
377
349
  * @param command Slash/Message command execute data
378
350
  */
379
- _commandExecuteError(err, command) {
380
- return __awaiter(this, void 0, void 0, function* () {
381
- if (this.isClientLogsEnabled()) {
382
- this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandBuilderType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
383
- this.logger.error(err);
384
- }
385
- if (!err || !command)
351
+ async _commandExecuteError(err, command) {
352
+ if (this.isClientLogsEnabled()) {
353
+ this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandBuilderType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
354
+ this.logger.error(err);
355
+ }
356
+ if (!err || !command)
357
+ return;
358
+ if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
359
+ if (!this.config.commands.slashCommand.replyOnError)
386
360
  return;
387
- if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
388
- if (!this.config.commands.slashCommand.replyOnError)
389
- return;
390
- yield command.interaction.followUp(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
391
- }
392
- else if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
393
- if (!this.config.commands.messageCommand.replyOnError)
394
- return;
395
- yield command.message.reply(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
396
- }
397
- });
361
+ await command.interaction.followUp(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
362
+ }
363
+ else if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
364
+ if (!this.config.commands.messageCommand.replyOnError)
365
+ return;
366
+ await command.message.reply(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
367
+ }
398
368
  }
399
369
  }
400
370
  exports.RecipleClient = RecipleClient;