reciple 5.0.0-pre.1 → 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.
package/bin/bin.js CHANGED
@@ -46,6 +46,9 @@ if (config.fileLogging.clientLogs)
46
46
  var _e;
47
47
  if (client.isClientLogsEnabled())
48
48
  client.logger.warn(`Logged in as ${((_e = client.user) === null || _e === void 0 ? void 0 : _e.tag) || 'Unknown'}!`);
49
+ client.on('cacheSweep', () => {
50
+ client.cooldowns.clean();
51
+ });
49
52
  yield client.loadModules();
50
53
  client.addCommandListeners();
51
54
  }));
@@ -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,8 +53,8 @@ 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
- commandCooldowns: CommandCooldownManager;
56
+ additionalApplicationCommands: (ApplicationCommandBuilder | ApplicationCommandData)[];
57
+ cooldowns: CommandCooldownManager;
57
58
  modules: RecipleModule[];
58
59
  logger: ILogger;
59
60
  version: string;
@@ -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
@@ -13,8 +13,8 @@ exports.RecipleClient = void 0;
13
13
  const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
14
14
  const SlashCommandBuilder_1 = require("./builders/SlashCommandBuilder");
15
15
  const registerApplicationCommands_1 = require("../registerApplicationCommands");
16
- const permissions_1 = require("../permissions");
17
16
  const builders_1 = require("../types/builders");
17
+ const permissions_1 = require("../permissions");
18
18
  const CommandCooldownManager_1 = require("./CommandCooldownManager");
19
19
  const MessageCommandOptionManager_1 = require("./MessageCommandOptionManager");
20
20
  const commands_1 = require("../types/commands");
@@ -32,9 +32,9 @@ 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 = [];
37
- this.commandCooldowns = new CommandCooldownManager_1.CommandCooldownManager();
35
+ this.commands = { slashCommands: {}, messageCommands: {} };
36
+ this.additionalApplicationCommands = [];
37
+ this.cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
38
38
  this.modules = [];
39
39
  this.version = version_1.version;
40
40
  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);
@@ -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,78 +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
189
- || !command.allowExecuteByBots
190
- && (message.author.bot || message.author.system)
191
- || (0, permissions_1.isIgnoredChannel)(message.channelId, this.config.ignoredChannels))
181
+ if (!command)
192
182
  return;
193
- if (command.validateOptions) {
194
- if (commandOptions.some(o => o.invalid)) {
195
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)) }))) {
196
- message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
197
- }
198
- return;
199
- }
200
- if (commandOptions.some(o => o.missing)) {
201
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)) }))) {
202
- message.reply(this.getMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
203
- }
204
- return;
205
- }
206
- }
207
- if (message.guild && !(0, permissions_1.botHasExecutePermissions)(message.guild, command.requiredBotPermissions)) {
183
+ if (interaction.guild && !(0, permissions_1.botHasExecutePermissions)(interaction.guild, command.requiredBotPermissions)) {
208
184
  if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
209
- 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));
210
186
  }
211
187
  return;
212
188
  }
213
189
  const userCooldown = {
214
- user: message.author,
190
+ user: interaction.user,
215
191
  command: command.name,
216
- channel: message.channel,
217
- guild: message.guild,
218
- 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
219
195
  };
220
- if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.commandCooldowns.isCooledDown(userCooldown)) {
221
- this.commandCooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
196
+ if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
197
+ this.cooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
222
198
  }
223
- else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
224
- if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.commandCooldowns.get(userCooldown))))) {
225
- yield message.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
199
+ else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
200
+ if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.cooldowns.get(userCooldown))))) {
201
+ yield interaction.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
226
202
  }
227
203
  return;
228
204
  }
229
205
  try {
230
206
  yield Promise.resolve(command.execute(executeData))
231
- .then(() => this.emit('recipleMessageCommandCreate', executeData))
207
+ .then(() => this.emit('recipleCommandExecute', executeData))
232
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; }));
233
209
  return executeData;
234
210
  }
@@ -239,59 +215,80 @@ class RecipleClient extends discord_js_1.Client {
239
215
  }
240
216
  }
241
217
  else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
242
- 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));
243
219
  }
244
220
  });
245
221
  }
246
222
  /**
247
- * Execute a slash command
248
- * @param interaction Slash command interaction
223
+ * Execute a Message command
224
+ * @param message Message command executor
225
+ * @param prefix Message command prefix
249
226
  */
250
- slashCommandExecute(interaction) {
251
- var _a, _b;
227
+ messageCommandExecute(message, prefix) {
228
+ var _a;
252
229
  return __awaiter(this, void 0, void 0, function* () {
253
- if (!interaction || !interaction.isChatInputCommand() || !this.isReady())
230
+ if (!message.content || !this.isReady())
254
231
  return;
255
- 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);
256
236
  if (!command)
257
237
  return;
238
+ const commandOptions = yield (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
258
239
  const executeData = {
259
- interaction,
240
+ message: message,
241
+ options: commandOptions,
242
+ command: parseCommand,
260
243
  builder: command,
261
244
  client: this
262
245
  };
263
246
  if ((0, permissions_1.userHasCommandPermissions)({
264
247
  builder: command,
265
- memberPermissions: (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined,
266
- 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
267
250
  })) {
268
- if (!command || (0, permissions_1.isIgnoredChannel)(interaction.channelId, this.config.ignoredChannels))
251
+ if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM || !command.allowExecuteByBots && (message.author.bot || message.author.system))
269
252
  return;
270
- 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)) {
271
268
  if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
272
- 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));
273
270
  }
274
271
  return;
275
272
  }
276
273
  const userCooldown = {
277
- user: interaction.user,
274
+ user: message.author,
278
275
  command: command.name,
279
- channel: (_b = interaction.channel) !== null && _b !== void 0 ? _b : undefined,
280
- guild: interaction.guild,
281
- type: builders_1.CommandBuilderType.SlashCommand
276
+ channel: message.channel,
277
+ guild: message.guild,
278
+ type: builders_1.CommandBuilderType.MessageCommand
282
279
  };
283
- if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.commandCooldowns.isCooledDown(userCooldown)) {
284
- this.commandCooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
280
+ if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
281
+ this.cooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
285
282
  }
286
- else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
287
- if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.commandCooldowns.get(userCooldown))))) {
288
- yield interaction.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
283
+ else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
284
+ if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.cooldowns.get(userCooldown))))) {
285
+ yield message.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
289
286
  }
290
287
  return;
291
288
  }
292
289
  try {
293
290
  yield Promise.resolve(command.execute(executeData))
294
- .then(() => this.emit('recipleInteractionCommandCreate', executeData))
291
+ .then(() => this.emit('recipleCommandExecute', executeData))
295
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; }));
296
293
  return executeData;
297
294
  }
@@ -302,7 +299,7 @@ class RecipleClient extends discord_js_1.Client {
302
299
  }
303
300
  }
304
301
  else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
305
- 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));
306
303
  }
307
304
  });
308
305
  }
@@ -311,7 +308,7 @@ class RecipleClient extends discord_js_1.Client {
311
308
  * @param messageKey Config messages key
312
309
  * @param defaultMessage Default message when the key does not exists
313
310
  */
314
- getMessage(messageKey, defaultMessage) {
311
+ getConfigMessage(messageKey, defaultMessage) {
315
312
  var _a, _b;
316
313
  return (_b = (_a = this.config.messages[messageKey]) !== null && _a !== void 0 ? _a : defaultMessage) !== null && _b !== void 0 ? _b : messageKey;
317
314
  }
@@ -345,11 +342,13 @@ class RecipleClient extends discord_js_1.Client {
345
342
  var _a;
346
343
  return __awaiter(this, void 0, void 0, function* () {
347
344
  try {
348
- return (_a = (command.halt
345
+ const haltResolved = (_a = (command.halt
349
346
  ? yield (command.type == builders_1.CommandBuilderType.SlashCommand
350
347
  ? Promise.resolve(command.halt(haltData))
351
348
  : Promise.resolve(command.halt(haltData))).catch(err => { throw err; })
352
349
  : false)) !== null && _a !== void 0 ? _a : false;
350
+ this.emit('recipleCommandHalt', haltData);
351
+ return haltResolved;
353
352
  }
354
353
  catch (err) {
355
354
  if (this.isClientLogsEnabled()) {
@@ -373,15 +372,15 @@ class RecipleClient extends discord_js_1.Client {
373
372
  }
374
373
  if (!err || !command)
375
374
  return;
376
- if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
377
- if (!this.config.commands.messageCommand.replyOnError)
375
+ if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
376
+ if (!this.config.commands.slashCommand.replyOnError)
378
377
  return;
379
- 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));
380
379
  }
381
- else if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
382
- if (!this.config.commands.slashCommand.replyOnError)
380
+ else if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
381
+ if (!this.config.commands.messageCommand.replyOnError)
383
382
  return;
384
- 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));
385
384
  }
386
385
  });
387
386
  }
@@ -12,36 +12,31 @@ 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[];
37
37
  };
38
38
  };
39
39
  };
40
- ignoredChannels: {
41
- enabled: boolean;
42
- convertToAllowList: boolean;
43
- channels: string[];
44
- };
45
40
  fileLogging: {
46
41
  enabled: boolean;
47
42
  debugmode: boolean;
@@ -1,9 +1,9 @@
1
- import { CommandBuilderType, AnyCommandExecuteData, AnyCommandExecuteFunction, AnyCommandHaltFunction } 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';
6
- import { AnyCommandHaltData } from '../../types/commands';
5
+ import { Message, PermissionResolvable, RestOrArray } from 'discord.js';
6
+ import { CommandHaltData } from '../../types/commands';
7
7
  import { RecipleClient } from '../RecipleClient';
8
8
  /**
9
9
  * Execute data for message command
@@ -28,26 +28,26 @@ export interface MessageCommandValidatedOption {
28
28
  /**
29
29
  * Message command halt data
30
30
  */
31
- export declare type MessageCommandHaltData = AnyCommandHaltData<CommandBuilderType.MessageCommand>;
31
+ export declare type MessageCommandHaltData = CommandHaltData<CommandBuilderType.MessageCommand>;
32
32
  /**
33
33
  * Message command halt function
34
34
  */
35
- export declare type MessageCommandHaltFunction = AnyCommandHaltFunction<CommandBuilderType.MessageCommand>;
35
+ export declare type MessageCommandHaltFunction = CommandHaltFunction<CommandBuilderType.MessageCommand>;
36
36
  /**
37
37
  * Message command execute function
38
38
  */
39
- export declare type MessageCommandExecuteFunction = AnyCommandExecuteFunction<CommandBuilderType.MessageCommand>;
39
+ export declare type MessageCommandExecuteFunction = CommandExecuteFunction<CommandBuilderType.MessageCommand>;
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,10 +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;
118
- /**
119
- * True if this is a message command builder
120
- */
121
- isMessageCommand(): this is MessageCommandBuilder;
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;
122
97
  /**
123
98
  * Is a message command builder
124
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,11 +112,27 @@ class MessageCommandBuilder {
153
112
  this.validateOptions = validateOptions;
154
113
  return this;
155
114
  }
156
- /**
157
- * True if this is a message command builder
158
- */
159
- isMessageCommand() {
160
- return this instanceof MessageCommandBuilder;
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;
161
136
  }
162
137
  /**
163
138
  * Is a message command builder
@@ -1,7 +1,7 @@
1
- import { CommandBuilderType, AnyCommandExecuteData, AnyCommandExecuteFunction, AnyCommandHaltFunction } from '../../types/builders';
2
- import { AnyCommandHaltData } from '../../types/commands';
1
+ import { CommandBuilderType, AnyCommandExecuteData, CommandHaltFunction, CommandExecuteFunction, SharedCommandBuilderProperties } from '../../types/builders';
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,28 +10,28 @@ 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
  */
22
- export declare type SlashCommandHaltData = AnyCommandHaltData<CommandBuilderType.SlashCommand>;
16
+ export declare type SlashCommandHaltData = CommandHaltData<CommandBuilderType.SlashCommand>;
23
17
  /**
24
18
  * Slash command halt function
25
19
  */
26
- export declare type SlashCommandHaltFunction = AnyCommandHaltFunction<CommandBuilderType.SlashCommand>;
20
+ export declare type SlashCommandHaltFunction = CommandHaltFunction<CommandBuilderType.SlashCommand>;
27
21
  /**
28
22
  * Slash command execute function
29
23
  */
30
- export declare type SlashCommandExecuteFunction = AnyCommandExecuteFunction<CommandBuilderType.SlashCommand>;
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,36 +39,11 @@ 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
- /**
69
- * True if this is a slash command builder
70
- */
71
- isSlashCommand(): this is SlashCommandBuilder;
72
47
  /**
73
48
  * Is a slash command builder
74
49
  */
@@ -16,55 +16,28 @@ 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.');
59
38
  this.execute = execute;
60
39
  return this;
61
40
  }
62
- /**
63
- * True if this is a slash command builder
64
- */
65
- isSlashCommand() {
66
- return this instanceof SlashCommandBuilder;
67
- }
68
41
  /**
69
42
  * Is a slash command builder
70
43
  */
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.token = exports.flags = void 0;
4
+ const version_1 = require("./version");
4
5
  const commander_1 = require("commander");
5
6
  /**
6
7
  * Used flags
@@ -8,7 +9,7 @@ const commander_1 = require("commander");
8
9
  exports.flags = new commander_1.Command()
9
10
  .name('reciple')
10
11
  .description('Reciple.js - Discord.js handler cli')
11
- .version(`v${require('../../package.json').version}`, '-v, --version')
12
+ .version(`v${version_1.rawVersion}`, '-v, --version')
12
13
  .option('-t, --token <token>', 'Replace used bot token')
13
14
  .option('-c, --config <config>', 'Change path to config file')
14
15
  .option('-D, --debugmode', 'Enabled debug mode')
@@ -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
  });
@@ -1,6 +1,5 @@
1
1
  import { UserHasCommandPermissionsOptions } from './types/paramOptions';
2
2
  import { Guild, PermissionResolvable } from 'discord.js';
3
- import { Config } from './classes/RecipleConfig';
4
3
  /**
5
4
  * Check if the user has permissions to execute the given command name
6
5
  * @param options options
@@ -12,9 +11,3 @@ export declare function userHasCommandPermissions(options: UserHasCommandPermiss
12
11
  * @param requiredPermissions Required guild bot permissions
13
12
  */
14
13
  export declare function botHasExecutePermissions(guild?: Guild, requiredPermissions?: PermissionResolvable[]): boolean;
15
- /**
16
- * Check if the channel id is ignored in config file
17
- * @param channelId Check if channel id is in ignore list
18
- * @param ignoredChannelsConfig Ignored channels config
19
- */
20
- export declare function isIgnoredChannel(channelId: string, ignoredChannelsConfig?: Config["ignoredChannels"]): boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isIgnoredChannel = exports.botHasExecutePermissions = exports.userHasCommandPermissions = void 0;
3
+ exports.botHasExecutePermissions = exports.userHasCommandPermissions = void 0;
4
4
  /**
5
5
  * Check if the user has permissions to execute the given command name
6
6
  * @param options options
@@ -26,18 +26,3 @@ function botHasExecutePermissions(guild, requiredPermissions) {
26
26
  return (guild === null || guild === void 0 ? void 0 : guild.members.me) ? guild.members.me.permissions.has(requiredPermissions) : false;
27
27
  }
28
28
  exports.botHasExecutePermissions = botHasExecutePermissions;
29
- /**
30
- * Check if the channel id is ignored in config file
31
- * @param channelId Check if channel id is in ignore list
32
- * @param ignoredChannelsConfig Ignored channels config
33
- */
34
- function isIgnoredChannel(channelId, ignoredChannelsConfig) {
35
- if (!(ignoredChannelsConfig === null || ignoredChannelsConfig === void 0 ? void 0 : ignoredChannelsConfig.enabled))
36
- return false;
37
- if (ignoredChannelsConfig.channels.includes(channelId) && !ignoredChannelsConfig.convertToAllowList)
38
- return true;
39
- if (!ignoredChannelsConfig.channels.includes(channelId) && ignoredChannelsConfig.convertToAllowList)
40
- return true;
41
- return false;
42
- }
43
- exports.isIgnoredChannel = isIgnoredChannel;
@@ -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,22 +1,30 @@
1
- import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandHaltData } from '../classes/builders/MessageCommandBuilder';
2
- import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandHaltData } 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
- * Reciple command builders
5
+ * Any Reciple command builders
6
6
  */
7
- export declare type AnyCommandBuilder = MessageCommandBuilder | SlashCommandBuilder;
7
+ export declare type AnyCommandBuilder = SlashCommandBuilder | MessageCommandBuilder;
8
8
  /**
9
- * Reciple command execute data
9
+ * Any Reciple command execute data
10
10
  */
11
11
  export declare type AnyCommandExecuteData = SlashCommandExecuteData | MessageCommandExecuteData;
12
+ /**
13
+ * Any Reciple command halt functions
14
+ */
15
+ export declare type AnyCommandHaltFunction = SlashCommandHaltFunction | MessageCommandHaltFunction;
16
+ /**
17
+ * Any reciple command execute function
18
+ */
19
+ export declare type AnyCommandExecuteFunction = SlashCommandExecuteFunction | MessageCommandExecuteFunction;
12
20
  /**
13
21
  * Reciple command halt function
14
22
  */
15
- export declare type AnyCommandHaltFunction<T extends CommandBuilderType> = (haltData: T extends CommandBuilderType.SlashCommand ? SlashCommandHaltData : MessageCommandHaltData) => Awaitable<boolean | null | undefined | void>;
23
+ export declare type CommandHaltFunction<T extends CommandBuilderType> = (haltData: T extends CommandBuilderType.SlashCommand ? SlashCommandHaltData : MessageCommandHaltData) => Awaitable<boolean | null | undefined | void>;
16
24
  /**
17
25
  * Reciple command execute function
18
26
  */
19
- export declare type AnyCommandExecuteFunction<T extends CommandBuilderType> = (executeData: T extends CommandBuilderType.SlashCommand ? SlashCommandExecuteData : MessageCommandExecuteData) => Awaitable<void>;
27
+ export declare type CommandExecuteFunction<T extends CommandBuilderType> = (executeData: T extends CommandBuilderType.SlashCommand ? SlashCommandExecuteData : MessageCommandExecuteData) => Awaitable<void>;
20
28
  /**
21
29
  * Types of Reciple command builders
22
30
  */
@@ -24,3 +32,41 @@ export declare enum CommandBuilderType {
24
32
  MessageCommand = 0,
25
33
  SlashCommand = 1
26
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
+ }
@@ -1,12 +1,16 @@
1
- import { MessageCommandExecuteData } from '../classes/builders/MessageCommandBuilder';
1
+ import { MessageCommandExecuteData, MessageCommandHaltData } from '../classes/builders/MessageCommandBuilder';
2
+ import { SlashCommandExecuteData, SlashCommandHaltData } from '../classes/builders/SlashCommandBuilder';
2
3
  import { MessageCommandOptionManager } from '../classes/MessageCommandOptionManager';
3
- import { SlashCommandExecuteData } from '../classes/builders/SlashCommandBuilder';
4
4
  import { CommandBuilderType, AnyCommandExecuteData } from '../types/builders';
5
5
  import { CooledDownUser } from '../classes/CommandCooldownManager';
6
6
  /**
7
- * Any Halted command's data
7
+ * Any reciple halted command data
8
8
  */
9
- export declare type AnyCommandHaltData<T extends CommandBuilderType = CommandBuilderType> = CommandErrorData<T> | CommandCooldownData<T> | (T extends CommandBuilderType.SlashCommand ? never : CommandInvalidArguments<T> | CommandMissingArguments<T>) | CommandMissingMemberPermissions<T> | CommandMissingBotPermissions<T>;
9
+ export declare type AnyCommandHaltData = SlashCommandHaltData | MessageCommandHaltData;
10
+ /**
11
+ * Halted command data
12
+ */
13
+ export declare type CommandHaltData<T extends CommandBuilderType> = CommandErrorData<T> | CommandCooldownData<T> | (T extends CommandBuilderType.SlashCommand ? never : CommandInvalidArguments<T> | CommandMissingArguments<T>) | CommandMissingMemberPermissions<T> | CommandMissingBotPermissions<T>;
10
14
  /**
11
15
  * Command halt reason base interface
12
16
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "5.0.0-pre.1",
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",
@@ -49,16 +49,6 @@ commands:
49
49
  permissions: ['Administrator']
50
50
 
51
51
 
52
- # Ignored channel IDs
53
- ignoredChannels:
54
- # enable ignored channels
55
- enabled: false
56
- # convert to only allowed channels
57
- convertToAllowList: false
58
- # channel IDs
59
- channels: []
60
-
61
-
62
52
  # Logger options
63
53
  fileLogging:
64
54
  # enable console output to file