reciple 5.0.0-pre.3 → 5.0.0-pre.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,8 +1,9 @@
1
1
  import { MessageCommandBuilder, MessageCommandExecuteData } from './builders/MessageCommandBuilder';
2
2
  import { SlashCommandBuilder, SlashCommandExecuteData } from './builders/SlashCommandBuilder';
3
3
  import { ApplicationCommandBuilder } from '../registerApplicationCommands';
4
- import { AnyCommandBuilder, CommandBuilderType } from '../types/builders';
4
+ import { AnyCommandBuilder, CommandBuilderType, AnyCommandExecuteData } from '../types/builders';
5
5
  import { CommandCooldownManager } from './CommandCooldownManager';
6
+ import { AnyCommandHaltData } from '../types/commands';
6
7
  import { RecipleClientAddModuleOptions } from '../types/paramOptions';
7
8
  import { Logger as ILogger } from 'fallout-utility';
8
9
  import { Config } from './RecipleConfig';
@@ -18,19 +19,19 @@ export interface RecipleClientOptions extends ClientOptions {
18
19
  * Reciple client commands object interface
19
20
  */
20
21
  export interface RecipleClientCommands {
21
- messageCommands: {
22
- [commandName: string]: MessageCommandBuilder;
23
- };
24
22
  slashCommands: {
25
23
  [commandName: string]: SlashCommandBuilder;
26
24
  };
25
+ messageCommands: {
26
+ [commandName: string]: MessageCommandBuilder;
27
+ };
27
28
  }
28
29
  /**
29
30
  * Reciple client events
30
31
  */
31
32
  export interface RecipleClientEvents extends ClientEvents {
32
- recipleMessageCommandCreate: [executeData: MessageCommandExecuteData];
33
- recipleInteractionCommandCreate: [executeData: SlashCommandExecuteData];
33
+ recipleCommandExecute: [executeData: AnyCommandExecuteData];
34
+ recipleCommandHalt: [haltData: AnyCommandHaltData];
34
35
  recipleReplyError: [error: unknown];
35
36
  }
36
37
  /**
@@ -52,7 +53,7 @@ export interface RecipleClient<Ready extends boolean = boolean> extends Client<R
52
53
  export declare class RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
53
54
  config: Config;
54
55
  commands: RecipleClientCommands;
55
- otherApplicationCommandData: (ApplicationCommandBuilder | ApplicationCommandData)[];
56
+ additionalApplicationCommands: (ApplicationCommandBuilder | ApplicationCommandData)[];
56
57
  cooldowns: CommandCooldownManager;
57
58
  modules: RecipleModule[];
58
59
  logger: ILogger;
@@ -84,23 +85,23 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
84
85
  * Listed to command executions
85
86
  */
86
87
  addCommandListeners(): RecipleClient<Ready>;
88
+ /**
89
+ * Execute a slash command
90
+ * @param interaction Slash command interaction
91
+ */
92
+ slashCommandExecute(interaction: Interaction | ChatInputCommandInteraction): Promise<void | SlashCommandExecuteData>;
87
93
  /**
88
94
  * Execute a Message command
89
95
  * @param message Message command executor
90
96
  * @param prefix Message command prefix
91
97
  */
92
98
  messageCommandExecute(message: Message, prefix?: string): Promise<void | MessageCommandExecuteData>;
93
- /**
94
- * Execute a slash command
95
- * @param interaction Slash command interaction
96
- */
97
- slashCommandExecute(interaction: Interaction | ChatInputCommandInteraction): Promise<void | SlashCommandExecuteData>;
98
99
  /**
99
100
  * Get a message from config
100
101
  * @param messageKey Config messages key
101
102
  * @param defaultMessage Default message when the key does not exists
102
103
  */
103
- getMessage<T = unknown>(messageKey: string, defaultMessage?: T): T;
104
+ getConfigMessage<T = unknown>(messageKey: string, defaultMessage?: T): T;
104
105
  /**
105
106
  * Get command builder by name or alias if it's a message command
106
107
  * @param command Command name
@@ -32,8 +32,8 @@ class RecipleClient extends discord_js_1.Client {
32
32
  var _a, _b, _c;
33
33
  super(options);
34
34
  this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
35
- this.commands = { messageCommands: {}, slashCommands: {} };
36
- this.otherApplicationCommandData = [];
35
+ this.commands = { slashCommands: {}, messageCommands: {} };
36
+ this.additionalApplicationCommands = [];
37
37
  this.cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
38
38
  this.modules = [];
39
39
  this.version = version_1.version;
@@ -91,7 +91,7 @@ class RecipleClient extends discord_js_1.Client {
91
91
  if (this.config.commands.slashCommand.registerCommands) {
92
92
  yield (0, registerApplicationCommands_1.registerApplicationCommands)({
93
93
  client: this,
94
- commands: [...Object.values(this.commands.slashCommands), ...this.otherApplicationCommandData],
94
+ commands: [...Object.values(this.commands.slashCommands), ...this.additionalApplicationCommands],
95
95
  guilds: this.config.commands.slashCommand.guilds
96
96
  });
97
97
  }
@@ -124,7 +124,7 @@ class RecipleClient extends discord_js_1.Client {
124
124
  if (registerCommands)
125
125
  yield (0, registerApplicationCommands_1.registerApplicationCommands)({
126
126
  client: this,
127
- commands: [...Object.values(this.commands.slashCommands), ...this.otherApplicationCommandData],
127
+ commands: [...Object.values(this.commands.slashCommands), ...this.additionalApplicationCommands],
128
128
  guilds: this.config.commands.slashCommand.guilds
129
129
  });
130
130
  });
@@ -157,75 +157,54 @@ class RecipleClient extends discord_js_1.Client {
157
157
  return this;
158
158
  }
159
159
  /**
160
- * Execute a Message command
161
- * @param message Message command executor
162
- * @param prefix Message command prefix
160
+ * Execute a slash command
161
+ * @param interaction Slash command interaction
163
162
  */
164
- messageCommandExecute(message, prefix) {
165
- var _a;
163
+ slashCommandExecute(interaction) {
164
+ var _a, _b;
166
165
  return __awaiter(this, void 0, void 0, function* () {
167
- if (!message.content || !this.isReady())
168
- return;
169
- const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
170
- if (!parseCommand || !(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command))
166
+ if (!interaction || !interaction.isChatInputCommand() || !this.isReady())
171
167
  return;
172
- const command = this.findCommand(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
168
+ const command = this.findCommand(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
173
169
  if (!command)
174
170
  return;
175
- const commandOptions = yield (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
176
171
  const executeData = {
177
- message: message,
178
- options: commandOptions,
179
- command: parseCommand,
172
+ interaction,
180
173
  builder: command,
181
174
  client: this
182
175
  };
183
176
  if ((0, permissions_1.userHasCommandPermissions)({
184
177
  builder: command,
185
- memberPermissions: (_a = message.member) === null || _a === void 0 ? void 0 : _a.permissions,
186
- commandPermissions: this.config.commands.messageCommand.permissions
178
+ memberPermissions: (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined,
179
+ commandPermissions: this.config.commands.slashCommand.permissions
187
180
  })) {
188
- if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM || !command.allowExecuteByBots && (message.author.bot || message.author.system))
181
+ if (!command)
189
182
  return;
190
- if (command.validateOptions) {
191
- if (commandOptions.some(o => o.invalid)) {
192
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)) }))) {
193
- message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
194
- }
195
- return;
196
- }
197
- if (commandOptions.some(o => o.missing)) {
198
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)) }))) {
199
- message.reply(this.getMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
200
- }
201
- return;
202
- }
203
- }
204
- if (message.guild && !(0, permissions_1.botHasExecutePermissions)(message.guild, command.requiredBotPermissions)) {
183
+ if (interaction.guild && !(0, permissions_1.botHasExecutePermissions)(interaction.guild, command.requiredBotPermissions)) {
205
184
  if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
206
- message.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
185
+ yield interaction.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
207
186
  }
208
187
  return;
209
188
  }
210
189
  const userCooldown = {
211
- user: message.author,
190
+ user: interaction.user,
212
191
  command: command.name,
213
- channel: message.channel,
214
- guild: message.guild,
215
- type: builders_1.CommandBuilderType.MessageCommand
192
+ channel: (_b = interaction.channel) !== null && _b !== void 0 ? _b : undefined,
193
+ guild: interaction.guild,
194
+ type: builders_1.CommandBuilderType.SlashCommand
216
195
  };
217
- if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
196
+ if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
218
197
  this.cooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
219
198
  }
220
- else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
199
+ else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
221
200
  if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.cooldowns.get(userCooldown))))) {
222
- yield message.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
201
+ yield interaction.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
223
202
  }
224
203
  return;
225
204
  }
226
205
  try {
227
206
  yield Promise.resolve(command.execute(executeData))
228
- .then(() => this.emit('recipleMessageCommandCreate', executeData))
207
+ .then(() => this.emit('recipleCommandExecute', executeData))
229
208
  .catch((err) => __awaiter(this, void 0, void 0, function* () { return (yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Error, error: err })) ? this._commandExecuteError(err, executeData) : void 0; }));
230
209
  return executeData;
231
210
  }
@@ -236,59 +215,80 @@ class RecipleClient extends discord_js_1.Client {
236
215
  }
237
216
  }
238
217
  else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
239
- message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
218
+ yield interaction.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
240
219
  }
241
220
  });
242
221
  }
243
222
  /**
244
- * Execute a slash command
245
- * @param interaction Slash command interaction
223
+ * Execute a Message command
224
+ * @param message Message command executor
225
+ * @param prefix Message command prefix
246
226
  */
247
- slashCommandExecute(interaction) {
248
- var _a, _b;
227
+ messageCommandExecute(message, prefix) {
228
+ var _a;
249
229
  return __awaiter(this, void 0, void 0, function* () {
250
- if (!interaction || !interaction.isChatInputCommand() || !this.isReady())
230
+ if (!message.content || !this.isReady())
251
231
  return;
252
- const command = this.findCommand(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
232
+ const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
233
+ if (!parseCommand || !(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command))
234
+ return;
235
+ const command = this.findCommand(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
253
236
  if (!command)
254
237
  return;
238
+ const commandOptions = yield (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
255
239
  const executeData = {
256
- interaction,
240
+ message: message,
241
+ options: commandOptions,
242
+ command: parseCommand,
257
243
  builder: command,
258
244
  client: this
259
245
  };
260
246
  if ((0, permissions_1.userHasCommandPermissions)({
261
247
  builder: command,
262
- memberPermissions: (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined,
263
- commandPermissions: this.config.commands.slashCommand.permissions
248
+ memberPermissions: (_a = message.member) === null || _a === void 0 ? void 0 : _a.permissions,
249
+ commandPermissions: this.config.commands.messageCommand.permissions
264
250
  })) {
265
- if (!command)
251
+ if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM || !command.allowExecuteByBots && (message.author.bot || message.author.system))
266
252
  return;
267
- if (interaction.guild && !(0, permissions_1.botHasExecutePermissions)(interaction.guild, command.requiredBotPermissions)) {
253
+ if (command.validateOptions) {
254
+ if (commandOptions.some(o => o.invalid)) {
255
+ if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)) }))) {
256
+ message.reply(this.getConfigMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
257
+ }
258
+ return;
259
+ }
260
+ if (commandOptions.some(o => o.missing)) {
261
+ if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)) }))) {
262
+ message.reply(this.getConfigMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
263
+ }
264
+ return;
265
+ }
266
+ }
267
+ if (message.guild && !(0, permissions_1.botHasExecutePermissions)(message.guild, command.requiredBotPermissions)) {
268
268
  if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
269
- yield interaction.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
269
+ message.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
270
270
  }
271
271
  return;
272
272
  }
273
273
  const userCooldown = {
274
- user: interaction.user,
274
+ user: message.author,
275
275
  command: command.name,
276
- channel: (_b = interaction.channel) !== null && _b !== void 0 ? _b : undefined,
277
- guild: interaction.guild,
278
- type: builders_1.CommandBuilderType.SlashCommand
276
+ channel: message.channel,
277
+ guild: message.guild,
278
+ type: builders_1.CommandBuilderType.MessageCommand
279
279
  };
280
- if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
280
+ if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
281
281
  this.cooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
282
282
  }
283
- else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
283
+ else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
284
284
  if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.cooldowns.get(userCooldown))))) {
285
- yield interaction.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
285
+ yield message.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
286
286
  }
287
287
  return;
288
288
  }
289
289
  try {
290
290
  yield Promise.resolve(command.execute(executeData))
291
- .then(() => this.emit('recipleInteractionCommandCreate', executeData))
291
+ .then(() => this.emit('recipleCommandExecute', executeData))
292
292
  .catch((err) => __awaiter(this, void 0, void 0, function* () { return (yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Error, error: err })) ? this._commandExecuteError(err, executeData) : void 0; }));
293
293
  return executeData;
294
294
  }
@@ -299,7 +299,7 @@ class RecipleClient extends discord_js_1.Client {
299
299
  }
300
300
  }
301
301
  else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
302
- yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
302
+ message.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
303
303
  }
304
304
  });
305
305
  }
@@ -308,7 +308,7 @@ class RecipleClient extends discord_js_1.Client {
308
308
  * @param messageKey Config messages key
309
309
  * @param defaultMessage Default message when the key does not exists
310
310
  */
311
- getMessage(messageKey, defaultMessage) {
311
+ getConfigMessage(messageKey, defaultMessage) {
312
312
  var _a, _b;
313
313
  return (_b = (_a = this.config.messages[messageKey]) !== null && _a !== void 0 ? _a : defaultMessage) !== null && _b !== void 0 ? _b : messageKey;
314
314
  }
@@ -342,11 +342,13 @@ class RecipleClient extends discord_js_1.Client {
342
342
  var _a;
343
343
  return __awaiter(this, void 0, void 0, function* () {
344
344
  try {
345
- return (_a = (command.halt
345
+ const haltResolved = (_a = (command.halt
346
346
  ? yield (command.type == builders_1.CommandBuilderType.SlashCommand
347
347
  ? Promise.resolve(command.halt(haltData))
348
348
  : Promise.resolve(command.halt(haltData))).catch(err => { throw err; })
349
349
  : false)) !== null && _a !== void 0 ? _a : false;
350
+ this.emit('recipleCommandHalt', haltData);
351
+ return haltResolved;
350
352
  }
351
353
  catch (err) {
352
354
  if (this.isClientLogsEnabled()) {
@@ -370,15 +372,15 @@ class RecipleClient extends discord_js_1.Client {
370
372
  }
371
373
  if (!err || !command)
372
374
  return;
373
- if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
374
- if (!this.config.commands.messageCommand.replyOnError)
375
+ if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
376
+ if (!this.config.commands.slashCommand.replyOnError)
375
377
  return;
376
- yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
378
+ yield command.interaction.followUp(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
377
379
  }
378
- else if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
379
- if (!this.config.commands.slashCommand.replyOnError)
380
+ else if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
381
+ if (!this.config.commands.messageCommand.replyOnError)
380
382
  return;
381
- yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
383
+ yield command.message.reply(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
382
384
  }
383
385
  });
384
386
  }
@@ -12,25 +12,25 @@ export interface ConfigCommandPermissions {
12
12
  export interface Config {
13
13
  token: string;
14
14
  commands: {
15
- messageCommand: {
15
+ slashCommand: {
16
16
  enabled: boolean;
17
- prefix?: string;
18
17
  replyOnError: boolean;
19
- allowCommandAlias: boolean;
18
+ registerCommands: boolean;
20
19
  enableCooldown: boolean;
21
- commandArgumentSeparator: string;
20
+ setRequiredPermissions: boolean;
21
+ guilds?: string[] | string;
22
22
  permissions: {
23
23
  enabled: boolean;
24
24
  commands: ConfigCommandPermissions[];
25
25
  };
26
26
  };
27
- slashCommand: {
27
+ messageCommand: {
28
28
  enabled: boolean;
29
+ prefix?: string;
29
30
  replyOnError: boolean;
30
- registerCommands: boolean;
31
+ allowCommandAlias: boolean;
31
32
  enableCooldown: boolean;
32
- setRequiredPermissions: boolean;
33
- guilds?: string[] | string;
33
+ commandArgumentSeparator: string;
34
34
  permissions: {
35
35
  enabled: boolean;
36
36
  commands: ConfigCommandPermissions[];
@@ -1,8 +1,8 @@
1
- import { CommandBuilderType, AnyCommandExecuteData, CommandHaltFunction, CommandExecuteFunction } from '../../types/builders';
1
+ import { CommandBuilderType, AnyCommandExecuteData, CommandHaltFunction, CommandExecuteFunction, SharedCommandBuilderProperties } from '../../types/builders';
2
2
  import { MessageCommandOptionManager } from '../MessageCommandOptionManager';
3
3
  import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
4
4
  import { Command as CommandMessage } from 'fallout-utility';
5
- import { Message, PermissionResolvable } from 'discord.js';
5
+ import { Message, PermissionResolvable, RestOrArray } from 'discord.js';
6
6
  import { CommandHaltData } from '../../types/commands';
7
7
  import { RecipleClient } from '../RecipleClient';
8
8
  /**
@@ -40,14 +40,14 @@ export declare type MessageCommandExecuteFunction = CommandExecuteFunction<Comma
40
40
  /**
41
41
  * Reciple builder for message command
42
42
  */
43
- export declare class MessageCommandBuilder {
43
+ export declare class MessageCommandBuilder implements SharedCommandBuilderProperties {
44
44
  readonly type = CommandBuilderType.MessageCommand;
45
45
  name: string;
46
- cooldown: number;
47
46
  description: string;
47
+ cooldown: number;
48
48
  aliases: string[];
49
- options: MessageCommandOptionBuilder[];
50
49
  validateOptions: boolean;
50
+ options: MessageCommandOptionBuilder[];
51
51
  requiredBotPermissions: PermissionResolvable[];
52
52
  requiredMemberPermissions: PermissionResolvable[];
53
53
  allowExecuteInDM: boolean;
@@ -64,27 +64,11 @@ export declare class MessageCommandBuilder {
64
64
  * @param description Command description
65
65
  */
66
66
  setDescription(description: string): this;
67
- /**
68
- * Sets the execute cooldown for this command.
69
- * - `0` means no cooldown
70
- * @param cooldown Command cooldown in milliseconds
71
- */
72
- setCooldown(cooldown: number): this;
73
67
  /**
74
68
  * Add aliases to the command
75
69
  * @param aliases Command aliases
76
70
  */
77
- addAliases(...aliases: string[]): this;
78
- /**
79
- * Set required bot permissions to execute the command
80
- * @param permissions Bot's required permissions
81
- */
82
- setRequiredBotPermissions(...permissions: PermissionResolvable[]): this;
83
- /**
84
- * Set required permissions to execute the command
85
- * @param permissions User's return permissions
86
- */
87
- setRequiredMemberPermissions(...permissions: PermissionResolvable[]): this;
71
+ addAliases(...aliases: RestOrArray<string>): this;
88
72
  /**
89
73
  * Set if command can be executed in dms
90
74
  * @param allowExecuteInDM `true` if the command can execute in DMs
@@ -95,16 +79,6 @@ export declare class MessageCommandBuilder {
95
79
  * @param allowExecuteByBots `true` if the command can be executed by bots
96
80
  */
97
81
  setAllowExecuteByBots(allowExecuteByBots: boolean): this;
98
- /**
99
- * Function when the command is interupted
100
- * @param halt Function to execute when command is halted
101
- */
102
- setHalt(halt?: this["halt"]): this;
103
- /**
104
- * Function when the command is executed
105
- * @param execute Function to execute when the command is called
106
- */
107
- setExecute(execute: this["execute"]): this;
108
82
  /**
109
83
  * Add option to the command
110
84
  * @param option Message option builder
@@ -115,6 +89,11 @@ export declare class MessageCommandBuilder {
115
89
  * @param validateOptions `true` if the command options needs to be validated before executing
116
90
  */
117
91
  setValidateOptions(validateOptions: boolean): this;
92
+ setCooldown(cooldown: number): this;
93
+ setRequiredBotPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
94
+ setRequiredMemberPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
95
+ setHalt(halt?: this["halt"]): this;
96
+ setExecute(execute: this["execute"]): this;
118
97
  /**
119
98
  * Is a message command builder
120
99
  */
@@ -13,6 +13,7 @@ exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
13
13
  const builders_1 = require("../../types/builders");
14
14
  const MessageCommandOptionManager_1 = require("../MessageCommandOptionManager");
15
15
  const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
16
+ const discord_js_1 = require("discord.js");
16
17
  /**
17
18
  * Reciple builder for message command
18
19
  */
@@ -20,11 +21,11 @@ class MessageCommandBuilder {
20
21
  constructor() {
21
22
  this.type = builders_1.CommandBuilderType.MessageCommand;
22
23
  this.name = '';
23
- this.cooldown = 0;
24
24
  this.description = '';
25
+ this.cooldown = 0;
25
26
  this.aliases = [];
26
- this.options = [];
27
27
  this.validateOptions = false;
28
+ this.options = [];
28
29
  this.requiredBotPermissions = [];
29
30
  this.requiredMemberPermissions = [];
30
31
  this.allowExecuteInDM = true;
@@ -51,20 +52,12 @@ class MessageCommandBuilder {
51
52
  this.description = description;
52
53
  return this;
53
54
  }
54
- /**
55
- * Sets the execute cooldown for this command.
56
- * - `0` means no cooldown
57
- * @param cooldown Command cooldown in milliseconds
58
- */
59
- setCooldown(cooldown) {
60
- this.cooldown = cooldown;
61
- return this;
62
- }
63
55
  /**
64
56
  * Add aliases to the command
65
57
  * @param aliases Command aliases
66
58
  */
67
59
  addAliases(...aliases) {
60
+ aliases = (0, discord_js_1.normalizeArray)(aliases);
68
61
  if (!aliases.length)
69
62
  throw new TypeError('Provide atleast one alias');
70
63
  if (aliases.some(a => !a || typeof a !== 'string' || !a.match(/^[\w-]{1,32}$/)))
@@ -74,22 +67,6 @@ class MessageCommandBuilder {
74
67
  this.aliases = [...new Set(aliases)];
75
68
  return this;
76
69
  }
77
- /**
78
- * Set required bot permissions to execute the command
79
- * @param permissions Bot's required permissions
80
- */
81
- setRequiredBotPermissions(...permissions) {
82
- this.requiredBotPermissions = permissions;
83
- return this;
84
- }
85
- /**
86
- * Set required permissions to execute the command
87
- * @param permissions User's return permissions
88
- */
89
- setRequiredMemberPermissions(...permissions) {
90
- this.requiredMemberPermissions = permissions;
91
- return this;
92
- }
93
70
  /**
94
71
  * Set if command can be executed in dms
95
72
  * @param allowExecuteInDM `true` if the command can execute in DMs
@@ -110,24 +87,6 @@ class MessageCommandBuilder {
110
87
  this.allowExecuteByBots = allowExecuteByBots;
111
88
  return this;
112
89
  }
113
- /**
114
- * Function when the command is interupted
115
- * @param halt Function to execute when command is halted
116
- */
117
- setHalt(halt) {
118
- this.halt = halt ? halt : undefined;
119
- return this;
120
- }
121
- /**
122
- * Function when the command is executed
123
- * @param execute Function to execute when the command is called
124
- */
125
- setExecute(execute) {
126
- if (!execute || typeof execute !== 'function')
127
- throw new TypeError('execute must be a function.');
128
- this.execute = execute;
129
- return this;
130
- }
131
90
  /**
132
91
  * Add option to the command
133
92
  * @param option Message option builder
@@ -153,6 +112,28 @@ class MessageCommandBuilder {
153
112
  this.validateOptions = validateOptions;
154
113
  return this;
155
114
  }
115
+ setCooldown(cooldown) {
116
+ this.cooldown = cooldown;
117
+ return this;
118
+ }
119
+ setRequiredBotPermissions(...permissions) {
120
+ this.requiredBotPermissions = (0, discord_js_1.normalizeArray)(permissions);
121
+ return this;
122
+ }
123
+ setRequiredMemberPermissions(...permissions) {
124
+ this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
125
+ return this;
126
+ }
127
+ setHalt(halt) {
128
+ this.halt = halt ? halt : undefined;
129
+ return this;
130
+ }
131
+ setExecute(execute) {
132
+ if (!execute || typeof execute !== 'function')
133
+ throw new TypeError('execute must be a function.');
134
+ this.execute = execute;
135
+ return this;
136
+ }
156
137
  /**
157
138
  * Is a message command builder
158
139
  */
@@ -1,7 +1,7 @@
1
- import { CommandBuilderType, AnyCommandExecuteData, CommandHaltFunction, CommandExecuteFunction } from '../../types/builders';
1
+ import { CommandBuilderType, AnyCommandExecuteData, CommandHaltFunction, CommandExecuteFunction, SharedCommandBuilderProperties } from '../../types/builders';
2
2
  import { CommandHaltData } from '../../types/commands';
3
3
  import { RecipleClient } from '../RecipleClient';
4
- import { ChatInputCommandInteraction, PermissionResolvable, SlashCommandBuilder as DiscordJsSlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder as DiscordJsSlashCommandSubcommandsOnlyBuilder } from 'discord.js';
4
+ import { ChatInputCommandInteraction, PermissionResolvable, RestOrArray, SlashCommandBuilder as DiscordJsSlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder as DiscordJsSlashCommandSubcommandsOnlyBuilder } from 'discord.js';
5
5
  /**
6
6
  * Execute data for interaction command
7
7
  */
@@ -10,12 +10,6 @@ export interface SlashCommandExecuteData {
10
10
  builder: SlashCommandBuilder;
11
11
  client: RecipleClient<true>;
12
12
  }
13
- export interface SlashCommandSubcommandsOnlyBuilder extends DiscordJsSlashCommandSubcommandsOnlyBuilder, Pick<SlashCommandBuilder, "setCooldown" | "setRequiredBotPermissions" | "setRequiredMemberPermissions" | "setHalt" | "setExecute"> {
14
- }
15
- export interface SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
16
- addSubcommandGroup(input: SlashCommandSubcommandGroupBuilder | ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder)): SlashCommandSubcommandsOnlyBuilder;
17
- addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): SlashCommandSubcommandsOnlyBuilder;
18
- }
19
13
  /**
20
14
  * Slash command halt data
21
15
  */
@@ -28,10 +22,16 @@ export declare type SlashCommandHaltFunction = CommandHaltFunction<CommandBuilde
28
22
  * Slash command execute function
29
23
  */
30
24
  export declare type SlashCommandExecuteFunction = CommandExecuteFunction<CommandBuilderType.SlashCommand>;
25
+ export interface SlashCommandSubcommandsOnlyBuilder extends DiscordJsSlashCommandSubcommandsOnlyBuilder, Pick<SlashCommandBuilder, "setCooldown" | "setRequiredBotPermissions" | "setRequiredMemberPermissions" | "setHalt" | "setExecute"> {
26
+ }
27
+ export interface SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
28
+ addSubcommandGroup(input: SlashCommandSubcommandGroupBuilder | ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder)): SlashCommandSubcommandsOnlyBuilder;
29
+ addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): SlashCommandSubcommandsOnlyBuilder;
30
+ }
31
31
  /**
32
32
  * Reciple builder for interaction/slash command
33
33
  */
34
- export declare class SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
34
+ export declare class SlashCommandBuilder extends DiscordJsSlashCommandBuilder implements SharedCommandBuilderProperties {
35
35
  readonly type = CommandBuilderType.SlashCommand;
36
36
  cooldown: number;
37
37
  requiredBotPermissions: PermissionResolvable[];
@@ -39,31 +39,10 @@ export declare class SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
39
39
  allowExecuteInDM: boolean;
40
40
  halt?: SlashCommandHaltFunction;
41
41
  execute: SlashCommandExecuteFunction;
42
- /**
43
- * Sets the execute cooldown for this command.
44
- * - `0` means no cooldown
45
- * @param cooldown Command cooldown in milliseconds
46
- */
47
42
  setCooldown(cooldown: number): this;
48
- /**
49
- * Set required bot permissions to execute the command
50
- * @param permissions Bot's required permissions
51
- */
52
- setRequiredBotPermissions(...permissions: PermissionResolvable[]): this;
53
- /**
54
- * Set required permissions to execute the command
55
- * @param permissions User's return permissions
56
- */
57
- setRequiredMemberPermissions(...permissions: PermissionResolvable[]): this;
58
- /**
59
- * Function when the command is interupted
60
- * @param halt Function to execute when command is halted
61
- */
43
+ setRequiredBotPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
44
+ setRequiredMemberPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
62
45
  setHalt(halt?: this["halt"]): this;
63
- /**
64
- * Function when the command is executed
65
- * @param execute Function to execute when the command is called
66
- */
67
46
  setExecute(execute: this["execute"]): this;
68
47
  /**
69
48
  * Is a slash command builder
@@ -16,43 +16,22 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
16
16
  this.allowExecuteInDM = true;
17
17
  this.execute = () => { };
18
18
  }
19
- /**
20
- * Sets the execute cooldown for this command.
21
- * - `0` means no cooldown
22
- * @param cooldown Command cooldown in milliseconds
23
- */
24
19
  setCooldown(cooldown) {
25
20
  this.cooldown = cooldown;
26
21
  return this;
27
22
  }
28
- /**
29
- * Set required bot permissions to execute the command
30
- * @param permissions Bot's required permissions
31
- */
32
23
  setRequiredBotPermissions(...permissions) {
33
- this.requiredBotPermissions = permissions;
24
+ this.requiredBotPermissions = (0, discord_js_1.normalizeArray)(permissions);
34
25
  return this;
35
26
  }
36
- /**
37
- * Set required permissions to execute the command
38
- * @param permissions User's return permissions
39
- */
40
27
  setRequiredMemberPermissions(...permissions) {
41
- this.requiredMemberPermissions = permissions;
28
+ this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
42
29
  return this;
43
30
  }
44
- /**
45
- * Function when the command is interupted
46
- * @param halt Function to execute when command is halted
47
- */
48
31
  setHalt(halt) {
49
32
  this.halt = halt ? halt : undefined;
50
33
  return this;
51
34
  }
52
- /**
53
- * Function when the command is executed
54
- * @param execute Function to execute when the command is called
55
- */
56
35
  setExecute(execute) {
57
36
  if (!execute || typeof execute !== 'function')
58
37
  throw new Error('execute must be a function.');
@@ -18,6 +18,7 @@ const version_1 = require("./version");
18
18
  const fs_1 = require("fs");
19
19
  const wildcard_match_1 = __importDefault(require("wildcard-match"));
20
20
  const path_1 = __importDefault(require("path"));
21
+ const discord_js_1 = require("discord.js");
21
22
  /**
22
23
  * Load modules from folder
23
24
  * @param client Reciple client
@@ -40,14 +41,14 @@ function loadModules(client, folder) {
40
41
  let module_;
41
42
  try {
42
43
  const reqMod = require(modulePath);
43
- module_ = typeof (reqMod === null || reqMod === void 0 ? void 0 : reqMod.default) != 'undefined' ? reqMod.default : reqMod;
44
+ module_ = (reqMod === null || reqMod === void 0 ? void 0 : reqMod.default) === undefined ? reqMod.default : reqMod;
45
+ const versions = (0, discord_js_1.normalizeArray)([module_.versions]);
44
46
  if (!((_a = module_.versions) === null || _a === void 0 ? void 0 : _a.length))
45
- throw new Error('Module does not have supported versions.');
46
- const versions = typeof module_.versions === 'object' ? module_.versions : [module_.versions];
47
+ throw new Error(`${modulePath} does not have supported versions.`);
47
48
  if (!client.config.disableVersionCheck && !versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
48
- throw new Error((_b = 'Module versions is not defined or unsupported; supported versions: ' + module_.versions) !== null && _b !== void 0 ? _b : 'none' + '; current version: ' + version_1.version);
49
- if (!(yield Promise.resolve(module_.onStart(client))))
50
- throw new Error(script + ' onStart is not defined or returned false.');
49
+ throw new Error((_b = `${modulePath} is unsupported; current version: ${version_1.version}; module supported versions: ` + versions.join(', ')) !== null && _b !== void 0 ? _b : 'none');
50
+ if (!(yield Promise.resolve(module_.onStart(client)).catch(() => null)))
51
+ throw new Error(script + ' onStart returned false or undefined.');
51
52
  if (module_.commands) {
52
53
  for (const command of module_.commands) {
53
54
  if (command.type === builders_1.CommandBuilderType.MessageCommand || command.type === builders_1.CommandBuilderType.SlashCommand) {
@@ -66,12 +67,12 @@ function loadModules(client, folder) {
66
67
  response.commands.push(...commands.filter((c) => {
67
68
  if (!c.name) {
68
69
  if (client.isClientLogsEnabled())
69
- client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} command name is not defined in ${script}`);
70
+ client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} command name is not defined in ${modulePath}`);
70
71
  return false;
71
72
  }
72
73
  if (c.type === builders_1.CommandBuilderType.MessageCommand && c.options.length && c.options.some(o => !o.name)) {
73
74
  if (client.isClientLogsEnabled())
74
- client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} option name is not defined in ${script}`);
75
+ client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} option name is not defined in ${modulePath}`);
75
76
  return false;
76
77
  }
77
78
  return true;
@@ -80,12 +81,12 @@ function loadModules(client, folder) {
80
81
  script: module_,
81
82
  info: {
82
83
  filename: script,
83
- versions: typeof module_.versions === 'string' ? [module_.versions] : module_.versions,
84
+ versions: (0, discord_js_1.normalizeArray)(module_.versions),
84
85
  path: modulePath
85
86
  }
86
87
  });
87
88
  if (client.isClientLogsEnabled())
88
- client.logger.info(`Loaded module ${script}`);
89
+ client.logger.info(`Loaded module ${modulePath}`);
89
90
  }
90
91
  return response;
91
92
  });
@@ -25,7 +25,7 @@ function registerApplicationCommands(options) {
25
25
  if (typeof (cmd === null || cmd === void 0 ? void 0 : cmd.toJSON) == 'undefined')
26
26
  return cmd;
27
27
  cmd = cmd;
28
- if (cmd instanceof SlashCommandBuilder_1.SlashCommandBuilder && client.config.commands.slashCommand.setRequiredPermissions) {
28
+ if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandBuilder(cmd) && client.config.commands.slashCommand.setRequiredPermissions) {
29
29
  const permissions = client.config.commands.slashCommand.permissions.enabled
30
30
  ? (_a = client.config.commands.slashCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())) === null || _a === void 0 ? void 0 : _a.permissions
31
31
  : undefined;
@@ -35,7 +35,6 @@ function registerApplicationCommands(options) {
35
35
  client.logger.debug(`Set required permissions for ${cmd.name}`);
36
36
  }
37
37
  client.commands.slashCommands[cmd.name] = cmd;
38
- return cmd.toJSON();
39
38
  }
40
39
  return cmd.toJSON();
41
40
  })) !== null && _b !== void 0 ? _b : [];
@@ -1,6 +1,6 @@
1
- import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandHaltData, MessageCommandHaltFunction } from '../classes/builders/MessageCommandBuilder';
2
- import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandHaltData, SlashCommandHaltFunction } from '../classes/builders/SlashCommandBuilder';
3
- import { Awaitable } from 'discord.js';
1
+ import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandExecuteFunction, MessageCommandHaltData, MessageCommandHaltFunction } from '../classes/builders/MessageCommandBuilder';
2
+ import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandExecuteFunction, SlashCommandHaltData, SlashCommandHaltFunction } from '../classes/builders/SlashCommandBuilder';
3
+ import { Awaitable, PermissionResolvable, RestOrArray } from 'discord.js';
4
4
  /**
5
5
  * Any Reciple command builders
6
6
  */
@@ -13,6 +13,10 @@ export declare type AnyCommandExecuteData = SlashCommandExecuteData | MessageCom
13
13
  * Any Reciple command halt functions
14
14
  */
15
15
  export declare type AnyCommandHaltFunction = SlashCommandHaltFunction | MessageCommandHaltFunction;
16
+ /**
17
+ * Any reciple command execute function
18
+ */
19
+ export declare type AnyCommandExecuteFunction = SlashCommandExecuteFunction | MessageCommandExecuteFunction;
16
20
  /**
17
21
  * Reciple command halt function
18
22
  */
@@ -28,3 +32,41 @@ export declare enum CommandBuilderType {
28
32
  MessageCommand = 0,
29
33
  SlashCommand = 1
30
34
  }
35
+ /**
36
+ * Shared command builder methods
37
+ */
38
+ export interface SharedCommandBuilderProperties {
39
+ readonly type: CommandBuilderType;
40
+ cooldown: number;
41
+ requiredBotPermissions: PermissionResolvable[];
42
+ requiredMemberPermissions: PermissionResolvable[];
43
+ allowExecuteInDM: boolean;
44
+ halt?: AnyCommandHaltFunction;
45
+ execute: AnyCommandExecuteFunction;
46
+ /**
47
+ * Sets the execute cooldown for this command.
48
+ * - `0` means no cooldown
49
+ * @param cooldown Command cooldown in milliseconds
50
+ */
51
+ setCooldown(cooldown: number): this;
52
+ /**
53
+ * Set required bot permissions to execute the command
54
+ * @param permissions Bot's required permissions
55
+ */
56
+ setRequiredBotPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
57
+ /**
58
+ * Set required permissions to execute the command
59
+ * @param permissions User's return permissions
60
+ */
61
+ setRequiredMemberPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
62
+ /**
63
+ * Function when the command is interupted
64
+ * @param halt Function to execute when command is halted
65
+ */
66
+ setHalt(halt?: this["halt"]): this;
67
+ /**
68
+ * Function when the command is executed
69
+ * @param execute Function to execute when the command is called
70
+ */
71
+ setExecute(execute: this["execute"]): this;
72
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "5.0.0-pre.3",
3
+ "version": "5.0.0-pre.4",
4
4
  "bin": "bin/bin.js",
5
5
  "license": "GPL-3.0",
6
6
  "main": "bin/index.js",