reciple 4.0.0 → 5.0.0-pre.1

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,7 +1,7 @@
1
1
  import { MessageCommandBuilder, MessageCommandExecuteData } from './builders/MessageCommandBuilder';
2
- import { ApplicationCommandBuilder } from '../registerApplicationCommands';
3
- import { CommandBuilder, CommandBuilderType } from '../types/builders';
4
2
  import { SlashCommandBuilder, SlashCommandExecuteData } from './builders/SlashCommandBuilder';
3
+ import { ApplicationCommandBuilder } from '../registerApplicationCommands';
4
+ import { AnyCommandBuilder, CommandBuilderType } from '../types/builders';
5
5
  import { CommandCooldownManager } from './CommandCooldownManager';
6
6
  import { RecipleClientAddModuleOptions } from '../types/paramOptions';
7
7
  import { Logger as ILogger } from 'fallout-utility';
@@ -79,7 +79,7 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
79
79
  * Add slash or message command to client
80
80
  * @param command Slash/Message command builder
81
81
  */
82
- addCommand(command: CommandBuilder): RecipleClient<Ready>;
82
+ addCommand(command: AnyCommandBuilder): RecipleClient<Ready>;
83
83
  /**
84
84
  * Listed to command executions
85
85
  */
@@ -11,8 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.RecipleClient = void 0;
13
13
  const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
14
- const permissions_1 = require("../permissions");
14
+ const SlashCommandBuilder_1 = require("./builders/SlashCommandBuilder");
15
15
  const registerApplicationCommands_1 = require("../registerApplicationCommands");
16
+ const permissions_1 = require("../permissions");
16
17
  const builders_1 = require("../types/builders");
17
18
  const CommandCooldownManager_1 = require("./CommandCooldownManager");
18
19
  const MessageCommandOptionManager_1 = require("./MessageCommandOptionManager");
@@ -134,10 +135,10 @@ class RecipleClient extends discord_js_1.Client {
134
135
  */
135
136
  addCommand(command) {
136
137
  var _a;
137
- if (command.builder === builders_1.CommandBuilderType.MessageCommand) {
138
+ if (command.type === builders_1.CommandBuilderType.MessageCommand) {
138
139
  this.commands.messageCommands[command.name] = command;
139
140
  }
140
- else if (command.builder === builders_1.CommandBuilderType.SlashCommand) {
141
+ else if (command.type === builders_1.CommandBuilderType.SlashCommand) {
141
142
  this.commands.slashCommands[command.name] = command;
142
143
  }
143
144
  else if (this.isClientLogsEnabled()) {
@@ -171,7 +172,7 @@ class RecipleClient extends discord_js_1.Client {
171
172
  const command = this.findCommand(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
172
173
  if (!command)
173
174
  return;
174
- const commandOptions = (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
175
+ const commandOptions = yield (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
175
176
  const executeData = {
176
177
  message: message,
177
178
  options: commandOptions,
@@ -191,20 +192,20 @@ class RecipleClient extends discord_js_1.Client {
191
192
  return;
192
193
  if (command.validateOptions) {
193
194
  if (commandOptions.some(o => o.invalid)) {
194
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.HaltedCommandReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(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)) }))) {
195
196
  message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
196
197
  }
197
198
  return;
198
199
  }
199
200
  if (commandOptions.some(o => o.missing)) {
200
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.HaltedCommandReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(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)) }))) {
201
202
  message.reply(this.getMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
202
203
  }
203
204
  return;
204
205
  }
205
206
  }
206
207
  if (message.guild && !(0, permissions_1.botHasExecutePermissions)(message.guild, command.requiredBotPermissions)) {
207
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.HaltedCommandReason.MissingBotPermissions }))) {
208
+ if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
208
209
  message.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
209
210
  }
210
211
  return;
@@ -220,7 +221,7 @@ class RecipleClient extends discord_js_1.Client {
220
221
  this.commandCooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
221
222
  }
222
223
  else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
223
- if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.HaltedCommandReason.Cooldown }, this.commandCooldowns.get(userCooldown))))) {
224
+ if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.commandCooldowns.get(userCooldown))))) {
224
225
  yield message.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
225
226
  }
226
227
  return;
@@ -228,16 +229,16 @@ class RecipleClient extends discord_js_1.Client {
228
229
  try {
229
230
  yield Promise.resolve(command.execute(executeData))
230
231
  .then(() => this.emit('recipleMessageCommandCreate', executeData))
231
- .catch((err) => __awaiter(this, void 0, void 0, function* () { return (yield this._haltCommand(command, { executeData, reason: commands_1.HaltedCommandReason.Error, error: err })) ? this._commandExecuteError(err, executeData) : void 0; }));
232
+ .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; }));
232
233
  return executeData;
233
234
  }
234
235
  catch (err) {
235
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.HaltedCommandReason.Error, error: err }))) {
236
+ if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Error, error: err }))) {
236
237
  this._commandExecuteError(err, executeData);
237
238
  }
238
239
  }
239
240
  }
240
- else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.HaltedCommandReason.MissingMemberPermissions }))) {
241
+ else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
241
242
  message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
242
243
  }
243
244
  });
@@ -249,7 +250,7 @@ class RecipleClient extends discord_js_1.Client {
249
250
  slashCommandExecute(interaction) {
250
251
  var _a, _b;
251
252
  return __awaiter(this, void 0, void 0, function* () {
252
- if (!interaction || interaction.type !== discord_js_1.InteractionType.ApplicationCommand || !interaction.isChatInputCommand() || !this.isReady())
253
+ if (!interaction || !interaction.isChatInputCommand() || !this.isReady())
253
254
  return;
254
255
  const command = this.findCommand(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
255
256
  if (!command)
@@ -267,7 +268,7 @@ class RecipleClient extends discord_js_1.Client {
267
268
  if (!command || (0, permissions_1.isIgnoredChannel)(interaction.channelId, this.config.ignoredChannels))
268
269
  return;
269
270
  if (interaction.guild && !(0, permissions_1.botHasExecutePermissions)(interaction.guild, command.requiredBotPermissions)) {
270
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.HaltedCommandReason.MissingBotPermissions }))) {
271
+ if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
271
272
  yield interaction.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
272
273
  }
273
274
  return;
@@ -283,7 +284,7 @@ class RecipleClient extends discord_js_1.Client {
283
284
  this.commandCooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
284
285
  }
285
286
  else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
286
- if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.HaltedCommandReason.Cooldown }, this.commandCooldowns.get(userCooldown))))) {
287
+ if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.commandCooldowns.get(userCooldown))))) {
287
288
  yield interaction.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
288
289
  }
289
290
  return;
@@ -291,16 +292,16 @@ class RecipleClient extends discord_js_1.Client {
291
292
  try {
292
293
  yield Promise.resolve(command.execute(executeData))
293
294
  .then(() => this.emit('recipleInteractionCommandCreate', executeData))
294
- .catch((err) => __awaiter(this, void 0, void 0, function* () { return (yield this._haltCommand(command, { executeData, reason: commands_1.HaltedCommandReason.Error, error: err })) ? this._commandExecuteError(err, executeData) : void 0; }));
295
+ .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; }));
295
296
  return executeData;
296
297
  }
297
298
  catch (err) {
298
- if (!(yield this._haltCommand(command, { executeData, reason: commands_1.HaltedCommandReason.Error, error: err }))) {
299
+ if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Error, error: err }))) {
299
300
  this._commandExecuteError(err, executeData);
300
301
  }
301
302
  }
302
303
  }
303
- else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.HaltedCommandReason.MissingMemberPermissions }))) {
304
+ else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
304
305
  yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
305
306
  }
306
307
  });
@@ -345,7 +346,7 @@ class RecipleClient extends discord_js_1.Client {
345
346
  return __awaiter(this, void 0, void 0, function* () {
346
347
  try {
347
348
  return (_a = (command.halt
348
- ? yield (command.builder == builders_1.CommandBuilderType.SlashCommand
349
+ ? yield (command.type == builders_1.CommandBuilderType.SlashCommand
349
350
  ? Promise.resolve(command.halt(haltData))
350
351
  : Promise.resolve(command.halt(haltData))).catch(err => { throw err; })
351
352
  : false)) !== null && _a !== void 0 ? _a : false;
@@ -367,17 +368,17 @@ class RecipleClient extends discord_js_1.Client {
367
368
  _commandExecuteError(err, command) {
368
369
  return __awaiter(this, void 0, void 0, function* () {
369
370
  if (this.isClientLogsEnabled()) {
370
- this.logger.error(`An error occured executing ${command.builder.builder == builders_1.CommandBuilderType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
371
+ this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandBuilderType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
371
372
  this.logger.error(err);
372
373
  }
373
374
  if (!err || !command)
374
375
  return;
375
- if (command === null || command === void 0 ? void 0 : command.message) {
376
+ if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
376
377
  if (!this.config.commands.messageCommand.replyOnError)
377
378
  return;
378
379
  yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
379
380
  }
380
- else if (command === null || command === void 0 ? void 0 : command.interaction) {
381
+ else if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
381
382
  if (!this.config.commands.slashCommand.replyOnError)
382
383
  return;
383
384
  yield command.interaction.followUp(this.getMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
@@ -72,7 +72,7 @@ export declare class RecipleConfig {
72
72
  /**
73
73
  * Parse the config file
74
74
  */
75
- parseConfig(): RecipleConfig;
75
+ parseConfig(): this;
76
76
  /**
77
77
  * Returns the parsed config file
78
78
  */
@@ -1,9 +1,9 @@
1
+ import { CommandBuilderType, AnyCommandExecuteData, AnyCommandExecuteFunction, AnyCommandHaltFunction } from '../../types/builders';
1
2
  import { MessageCommandOptionManager } from '../MessageCommandOptionManager';
2
3
  import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
3
- import { Awaitable, Message, PermissionResolvable } from 'discord.js';
4
4
  import { Command as CommandMessage } from 'fallout-utility';
5
- import { CommandBuilderType } from '../../types/builders';
6
- import { HaltedCommandData } from '../../types/commands';
5
+ import { Message, PermissionResolvable } from 'discord.js';
6
+ import { AnyCommandHaltData } from '../../types/commands';
7
7
  import { RecipleClient } from '../RecipleClient';
8
8
  /**
9
9
  * Execute data for message command
@@ -25,11 +25,23 @@ export interface MessageCommandValidatedOption {
25
25
  invalid: boolean;
26
26
  missing: boolean;
27
27
  }
28
+ /**
29
+ * Message command halt data
30
+ */
31
+ export declare type MessageCommandHaltData = AnyCommandHaltData<CommandBuilderType.MessageCommand>;
32
+ /**
33
+ * Message command halt function
34
+ */
35
+ export declare type MessageCommandHaltFunction = AnyCommandHaltFunction<CommandBuilderType.MessageCommand>;
36
+ /**
37
+ * Message command execute function
38
+ */
39
+ export declare type MessageCommandExecuteFunction = AnyCommandExecuteFunction<CommandBuilderType.MessageCommand>;
28
40
  /**
29
41
  * Reciple builder for message command
30
42
  */
31
43
  export declare class MessageCommandBuilder {
32
- readonly builder = CommandBuilderType.MessageCommand;
44
+ readonly type = CommandBuilderType.MessageCommand;
33
45
  name: string;
34
46
  cooldown: number;
35
47
  description: string;
@@ -40,68 +52,80 @@ export declare class MessageCommandBuilder {
40
52
  requiredMemberPermissions: PermissionResolvable[];
41
53
  allowExecuteInDM: boolean;
42
54
  allowExecuteByBots: boolean;
43
- halt?: (haltData: HaltedCommandData<MessageCommandBuilder>) => Awaitable<boolean | void>;
44
- execute: (executeData: MessageCommandExecuteData) => void;
55
+ halt?: MessageCommandHaltFunction;
56
+ execute: MessageCommandExecuteFunction;
45
57
  /**
46
58
  * Sets the command name
47
59
  * @param name Command name
48
60
  */
49
- setName(name: string): MessageCommandBuilder;
61
+ setName(name: string): this;
50
62
  /**
51
63
  * Sets the command description
52
64
  * @param description Command description
53
65
  */
54
- setDescription(description: string): MessageCommandBuilder;
66
+ setDescription(description: string): this;
55
67
  /**
56
68
  * Sets the execute cooldown for this command.
57
69
  * - `0` means no cooldown
58
70
  * @param cooldown Command cooldown in milliseconds
59
71
  */
60
- setCooldown(cooldown: number): MessageCommandBuilder;
72
+ setCooldown(cooldown: number): this;
61
73
  /**
62
74
  * Add aliases to the command
63
75
  * @param aliases Command aliases
64
76
  */
65
- addAliases(...aliases: string[]): MessageCommandBuilder;
77
+ addAliases(...aliases: string[]): this;
66
78
  /**
67
79
  * Set required bot permissions to execute the command
68
80
  * @param permissions Bot's required permissions
69
81
  */
70
- setRequiredBotPermissions(...permissions: PermissionResolvable[]): MessageCommandBuilder;
82
+ setRequiredBotPermissions(...permissions: PermissionResolvable[]): this;
71
83
  /**
72
84
  * Set required permissions to execute the command
73
85
  * @param permissions User's return permissions
74
86
  */
75
- setRequiredMemberPermissions(...permissions: PermissionResolvable[]): MessageCommandBuilder;
87
+ setRequiredMemberPermissions(...permissions: PermissionResolvable[]): this;
76
88
  /**
77
89
  * Set if command can be executed in dms
78
90
  * @param allowExecuteInDM `true` if the command can execute in DMs
79
91
  */
80
- setAllowExecuteInDM(allowExecuteInDM: boolean): MessageCommandBuilder;
92
+ setAllowExecuteInDM(allowExecuteInDM: boolean): this;
81
93
  /**
82
94
  * Allow command to be executed by bots
83
95
  * @param allowExecuteByBots `true` if the command can be executed by bots
84
96
  */
85
- setAllowExecuteByBots(allowExecuteByBots: boolean): MessageCommandBuilder;
97
+ setAllowExecuteByBots(allowExecuteByBots: boolean): this;
86
98
  /**
87
99
  * Function when the command is interupted
88
100
  * @param halt Function to execute when command is halted
89
101
  */
90
- setHalt(halt?: (haltData: HaltedCommandData<MessageCommandBuilder>) => Awaitable<boolean | void>): MessageCommandBuilder;
102
+ setHalt(halt?: this["halt"]): this;
91
103
  /**
92
104
  * Function when the command is executed
93
105
  * @param execute Function to execute when the command is called
94
106
  */
95
- setExecute(execute: (executeData: MessageCommandExecuteData) => void): MessageCommandBuilder;
107
+ setExecute(execute: this["execute"]): this;
96
108
  /**
97
109
  * Add option to the command
98
110
  * @param option Message option builder
99
111
  */
100
- addOption(option: MessageCommandOptionBuilder | ((constructor: MessageCommandOptionBuilder) => MessageCommandOptionBuilder)): MessageCommandBuilder;
112
+ addOption(option: MessageCommandOptionBuilder | ((constructor: MessageCommandOptionBuilder) => MessageCommandOptionBuilder)): this;
101
113
  /**
102
114
  * Validate options before executing
103
115
  * @param validateOptions `true` if the command options needs to be validated before executing
104
116
  */
105
- setValidateOptions(validateOptions: boolean): MessageCommandBuilder;
117
+ setValidateOptions(validateOptions: boolean): this;
118
+ /**
119
+ * True if this is a message command builder
120
+ */
121
+ isMessageCommand(): this is MessageCommandBuilder;
122
+ /**
123
+ * Is a message command builder
124
+ */
125
+ static isMessageCommandBuilder(builder: any): builder is MessageCommandBuilder;
126
+ /**
127
+ * Is a message command execute data
128
+ */
129
+ static isMessageCommandExecuteData(executeData: AnyCommandExecuteData): executeData is MessageCommandExecuteData;
106
130
  }
107
- export declare function validateMessageCommandOptions(builder: MessageCommandBuilder, options: CommandMessage): MessageCommandOptionManager;
131
+ export declare function validateMessageCommandOptions(builder: MessageCommandBuilder, options: CommandMessage): Promise<MessageCommandOptionManager>;
@@ -1,15 +1,24 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
13
+ const builders_1 = require("../../types/builders");
4
14
  const MessageCommandOptionManager_1 = require("../MessageCommandOptionManager");
5
15
  const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
6
- const builders_1 = require("../../types/builders");
7
16
  /**
8
17
  * Reciple builder for message command
9
18
  */
10
19
  class MessageCommandBuilder {
11
20
  constructor() {
12
- this.builder = builders_1.CommandBuilderType.MessageCommand;
21
+ this.type = builders_1.CommandBuilderType.MessageCommand;
13
22
  this.name = '';
14
23
  this.cooldown = 0;
15
24
  this.description = '';
@@ -144,39 +153,59 @@ class MessageCommandBuilder {
144
153
  this.validateOptions = validateOptions;
145
154
  return this;
146
155
  }
156
+ /**
157
+ * True if this is a message command builder
158
+ */
159
+ isMessageCommand() {
160
+ return this instanceof MessageCommandBuilder;
161
+ }
162
+ /**
163
+ * Is a message command builder
164
+ */
165
+ static isMessageCommandBuilder(builder) {
166
+ return builder instanceof MessageCommandBuilder;
167
+ }
168
+ /**
169
+ * Is a message command execute data
170
+ */
171
+ static isMessageCommandExecuteData(executeData) {
172
+ return executeData.builder !== undefined && this.isMessageCommandBuilder(executeData.builder);
173
+ }
147
174
  }
148
175
  exports.MessageCommandBuilder = MessageCommandBuilder;
149
176
  function validateMessageCommandOptions(builder, options) {
150
- const args = options.args || [];
151
- const required = builder.options.filter(o => o.required);
152
- const optional = builder.options.filter(o => !o.required);
153
- const allOptions = [...required, ...optional];
154
- const result = [];
155
- let i = 0;
156
- for (const option of allOptions) {
157
- const arg = args[i];
158
- const value = {
159
- name: option.name,
160
- value: arg !== null && arg !== void 0 ? arg : undefined,
161
- required: option.required,
162
- invalid: false,
163
- missing: false
164
- };
165
- if (arg == undefined && option.required) {
166
- value.missing = true;
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ const args = options.args || [];
179
+ const required = builder.options.filter(o => o.required);
180
+ const optional = builder.options.filter(o => !o.required);
181
+ const allOptions = [...required, ...optional];
182
+ const result = [];
183
+ let i = 0;
184
+ for (const option of allOptions) {
185
+ const arg = args[i];
186
+ const value = {
187
+ name: option.name,
188
+ value: arg !== null && arg !== void 0 ? arg : undefined,
189
+ required: option.required,
190
+ invalid: false,
191
+ missing: false
192
+ };
193
+ if (arg == undefined && option.required) {
194
+ value.missing = true;
195
+ result.push(value);
196
+ continue;
197
+ }
198
+ if (arg == undefined && !option.required) {
199
+ result.push(value);
200
+ continue;
201
+ }
202
+ const validate = option.validator ? yield Promise.resolve(option.validator(arg)) : true;
203
+ if (!validate)
204
+ value.invalid = true;
167
205
  result.push(value);
168
- continue;
206
+ i++;
169
207
  }
170
- if (arg == undefined && !option.required) {
171
- result.push(value);
172
- continue;
173
- }
174
- const validate = option.validator ? option.validator(arg) : true;
175
- if (!validate)
176
- value.invalid = true;
177
- result.push(value);
178
- i++;
179
- }
180
- return new MessageCommandOptionManager_1.MessageCommandOptionManager(...result);
208
+ return new MessageCommandOptionManager_1.MessageCommandOptionManager(...result);
209
+ });
181
210
  }
182
211
  exports.validateMessageCommandOptions = validateMessageCommandOptions;
@@ -1,3 +1,4 @@
1
+ import { Awaitable } from 'discord.js';
1
2
  /**
2
3
  * Option builder for MessageCommandBuilder
3
4
  */
@@ -5,25 +6,25 @@ export declare class MessageCommandOptionBuilder {
5
6
  name: string;
6
7
  description: string;
7
8
  required: boolean;
8
- validator: (value: string) => boolean;
9
+ validator: (value: string) => Awaitable<boolean>;
9
10
  /**
10
11
  * Set command option name
11
12
  * @param name Option name
12
13
  */
13
- setName(name: string): MessageCommandOptionBuilder;
14
+ setName(name: string): this;
14
15
  /**
15
16
  * Set command option description
16
17
  * @param description Option description
17
18
  */
18
- setDescription(description: string): MessageCommandOptionBuilder;
19
+ setDescription(description: string): this;
19
20
  /**
20
21
  * Set if this option is required
21
22
  * @param required `true` if this option is required
22
23
  */
23
- setRequired(required: boolean): MessageCommandOptionBuilder;
24
+ setRequired(required: boolean): this;
24
25
  /**
25
26
  * Set your custom function to validate given value for this option
26
27
  * @param validator Custom function to validate value given for this option
27
28
  */
28
- setValidator(validator: (value: string) => boolean): MessageCommandOptionBuilder;
29
+ setValidator(validator: (value: string) => Awaitable<boolean>): this;
29
30
  }
@@ -1,7 +1,7 @@
1
- import { CommandBuilderType } from '../../types/builders';
2
- import { HaltedCommandData } from '../../types/commands';
1
+ import { CommandBuilderType, AnyCommandExecuteData, AnyCommandExecuteFunction, AnyCommandHaltFunction } from '../../types/builders';
2
+ import { AnyCommandHaltData } from '../../types/commands';
3
3
  import { RecipleClient } from '../RecipleClient';
4
- import { Awaitable, ChatInputCommandInteraction, PermissionResolvable, SlashCommandBuilder as DiscordJsSlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder as DiscordJsSlashCommandSubcommandsOnlyBuilder } from 'discord.js';
4
+ import { ChatInputCommandInteraction, PermissionResolvable, SlashCommandBuilder as DiscordJsSlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder as DiscordJsSlashCommandSubcommandsOnlyBuilder } from 'discord.js';
5
5
  /**
6
6
  * Execute data for interaction command
7
7
  */
@@ -16,41 +16,65 @@ export interface SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
16
16
  addSubcommandGroup(input: SlashCommandSubcommandGroupBuilder | ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder)): SlashCommandSubcommandsOnlyBuilder;
17
17
  addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): SlashCommandSubcommandsOnlyBuilder;
18
18
  }
19
+ /**
20
+ * Slash command halt data
21
+ */
22
+ export declare type SlashCommandHaltData = AnyCommandHaltData<CommandBuilderType.SlashCommand>;
23
+ /**
24
+ * Slash command halt function
25
+ */
26
+ export declare type SlashCommandHaltFunction = AnyCommandHaltFunction<CommandBuilderType.SlashCommand>;
27
+ /**
28
+ * Slash command execute function
29
+ */
30
+ export declare type SlashCommandExecuteFunction = AnyCommandExecuteFunction<CommandBuilderType.SlashCommand>;
19
31
  /**
20
32
  * Reciple builder for interaction/slash command
21
33
  */
22
34
  export declare class SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
23
- readonly builder = CommandBuilderType.SlashCommand;
35
+ readonly type = CommandBuilderType.SlashCommand;
24
36
  cooldown: number;
25
37
  requiredBotPermissions: PermissionResolvable[];
26
38
  requiredMemberPermissions: PermissionResolvable[];
27
39
  allowExecuteInDM: boolean;
28
- halt?: (haltData: HaltedCommandData<SlashCommandBuilder>) => Awaitable<boolean | void>;
29
- execute: (executeData: SlashCommandExecuteData) => Awaitable<void>;
40
+ halt?: SlashCommandHaltFunction;
41
+ execute: SlashCommandExecuteFunction;
30
42
  /**
31
43
  * Sets the execute cooldown for this command.
32
44
  * - `0` means no cooldown
33
45
  * @param cooldown Command cooldown in milliseconds
34
46
  */
35
- setCooldown(cooldown: number): SlashCommandBuilder;
47
+ setCooldown(cooldown: number): this;
36
48
  /**
37
49
  * Set required bot permissions to execute the command
38
50
  * @param permissions Bot's required permissions
39
51
  */
40
- setRequiredBotPermissions(...permissions: PermissionResolvable[]): SlashCommandBuilder;
52
+ setRequiredBotPermissions(...permissions: PermissionResolvable[]): this;
41
53
  /**
42
54
  * Set required permissions to execute the command
43
55
  * @param permissions User's return permissions
44
56
  */
45
- setRequiredMemberPermissions(...permissions: PermissionResolvable[]): SlashCommandBuilder;
57
+ setRequiredMemberPermissions(...permissions: PermissionResolvable[]): this;
46
58
  /**
47
59
  * Function when the command is interupted
48
60
  * @param halt Function to execute when command is halted
49
61
  */
50
- setHalt(halt?: (haltData: HaltedCommandData<SlashCommandBuilder>) => Awaitable<boolean | void>): SlashCommandBuilder;
62
+ setHalt(halt?: this["halt"]): this;
51
63
  /**
52
64
  * Function when the command is executed
53
65
  * @param execute Function to execute when the command is called
54
66
  */
55
- setExecute(execute: (executeData: SlashCommandExecuteData) => void): SlashCommandBuilder;
67
+ setExecute(execute: this["execute"]): this;
68
+ /**
69
+ * True if this is a slash command builder
70
+ */
71
+ isSlashCommand(): this is SlashCommandBuilder;
72
+ /**
73
+ * Is a slash command builder
74
+ */
75
+ static isSlashCommandBuilder(builder: any): builder is SlashCommandBuilder;
76
+ /**
77
+ * Is a slash command execute data
78
+ */
79
+ static isSlashCommandExecuteData(executeData: AnyCommandExecuteData): executeData is SlashCommandExecuteData;
56
80
  }
@@ -9,7 +9,7 @@ const discord_js_1 = require("discord.js");
9
9
  class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
10
10
  constructor() {
11
11
  super(...arguments);
12
- this.builder = builders_1.CommandBuilderType.SlashCommand;
12
+ this.type = builders_1.CommandBuilderType.SlashCommand;
13
13
  this.cooldown = 0;
14
14
  this.requiredBotPermissions = [];
15
15
  this.requiredMemberPermissions = [];
@@ -59,5 +59,23 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
59
59
  this.execute = execute;
60
60
  return this;
61
61
  }
62
+ /**
63
+ * True if this is a slash command builder
64
+ */
65
+ isSlashCommand() {
66
+ return this instanceof SlashCommandBuilder;
67
+ }
68
+ /**
69
+ * Is a slash command builder
70
+ */
71
+ static isSlashCommandBuilder(builder) {
72
+ return builder instanceof SlashCommandBuilder;
73
+ }
74
+ /**
75
+ * Is a slash command execute data
76
+ */
77
+ static isSlashCommandExecuteData(executeData) {
78
+ return executeData.builder !== undefined && this.isSlashCommandBuilder(executeData.builder);
79
+ }
62
80
  }
63
81
  exports.SlashCommandBuilder = SlashCommandBuilder;
@@ -1,7 +1,7 @@
1
- import { CommandBuilder } from './types/builders';
1
+ import { AnyCommandBuilder } from './types/builders';
2
2
  import { RecipleClient } from './classes/RecipleClient';
3
3
  export declare type LoadedModules = {
4
- commands: CommandBuilder[];
4
+ commands: AnyCommandBuilder[];
5
5
  modules: RecipleModule[];
6
6
  };
7
7
  /**
@@ -9,7 +9,7 @@ export declare type LoadedModules = {
9
9
  */
10
10
  export interface RecipleScript {
11
11
  versions: string | string[];
12
- commands?: CommandBuilder[];
12
+ commands?: AnyCommandBuilder[];
13
13
  onLoad?(reciple: RecipleClient): void | Promise<void>;
14
14
  onStart(reciple: RecipleClient): boolean | Promise<boolean>;
15
15
  }
@@ -50,7 +50,7 @@ function loadModules(client, folder) {
50
50
  throw new Error(script + ' onStart is not defined or returned false.');
51
51
  if (module_.commands) {
52
52
  for (const command of module_.commands) {
53
- if (command.builder === builders_1.CommandBuilderType.MessageCommand || command.builder === builders_1.CommandBuilderType.SlashCommand) {
53
+ if (command.type === builders_1.CommandBuilderType.MessageCommand || command.type === builders_1.CommandBuilderType.SlashCommand) {
54
54
  commands.push(command);
55
55
  }
56
56
  }
@@ -66,12 +66,12 @@ function loadModules(client, folder) {
66
66
  response.commands.push(...commands.filter((c) => {
67
67
  if (!c.name) {
68
68
  if (client.isClientLogsEnabled())
69
- client.logger.error(`A ${c.builder} command name is not defined in ${script}`);
69
+ client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} command name is not defined in ${script}`);
70
70
  return false;
71
71
  }
72
- if (c.builder === builders_1.CommandBuilderType.MessageCommand && c.options.length && c.options.some(o => !o.name)) {
72
+ if (c.type === builders_1.CommandBuilderType.MessageCommand && c.options.length && c.options.some(o => !o.name)) {
73
73
  if (client.isClientLogsEnabled())
74
- client.logger.error(`A ${c.builder} option name is not defined in ${script}`);
74
+ client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} option name is not defined in ${script}`);
75
75
  return false;
76
76
  }
77
77
  return true;
@@ -1,13 +1,22 @@
1
- import { MessageCommandBuilder, MessageCommandExecuteData } from '../classes/builders/MessageCommandBuilder';
2
- import { SlashCommandBuilder, SlashCommandExecuteData } from '../classes/builders/SlashCommandBuilder';
1
+ import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandHaltData } from '../classes/builders/MessageCommandBuilder';
2
+ import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandHaltData } from '../classes/builders/SlashCommandBuilder';
3
+ import { Awaitable } from 'discord.js';
3
4
  /**
4
5
  * Reciple command builders
5
6
  */
6
- export declare type CommandBuilder = MessageCommandBuilder | SlashCommandBuilder;
7
+ export declare type AnyCommandBuilder = MessageCommandBuilder | SlashCommandBuilder;
7
8
  /**
8
- * Reciple command builders execute data
9
+ * Reciple command execute data
9
10
  */
10
- export declare type CommandBuilderExecuteData = SlashCommandExecuteData | MessageCommandExecuteData;
11
+ export declare type AnyCommandExecuteData = SlashCommandExecuteData | MessageCommandExecuteData;
12
+ /**
13
+ * Reciple command halt function
14
+ */
15
+ export declare type AnyCommandHaltFunction<T extends CommandBuilderType> = (haltData: T extends CommandBuilderType.SlashCommand ? SlashCommandHaltData : MessageCommandHaltData) => Awaitable<boolean | null | undefined | void>;
16
+ /**
17
+ * Reciple command execute function
18
+ */
19
+ export declare type AnyCommandExecuteFunction<T extends CommandBuilderType> = (executeData: T extends CommandBuilderType.SlashCommand ? SlashCommandExecuteData : MessageCommandExecuteData) => Awaitable<void>;
11
20
  /**
12
21
  * Types of Reciple command builders
13
22
  */
@@ -1,40 +1,43 @@
1
1
  import { MessageCommandExecuteData } from '../classes/builders/MessageCommandBuilder';
2
- import { SlashCommandBuilder, SlashCommandExecuteData } from '../classes/builders/SlashCommandBuilder';
3
2
  import { MessageCommandOptionManager } from '../classes/MessageCommandOptionManager';
3
+ import { SlashCommandExecuteData } from '../classes/builders/SlashCommandBuilder';
4
+ import { CommandBuilderType, AnyCommandExecuteData } from '../types/builders';
4
5
  import { CooledDownUser } from '../classes/CommandCooldownManager';
5
- import { CommandBuilder } from '../types/builders';
6
6
  /**
7
- * Halted command's data
7
+ * Any Halted command's data
8
8
  */
9
- export declare type HaltedCommandData<Builder extends CommandBuilder = CommandBuilder> = CommandErrorData<Builder> | CommandCooldownData<Builder> | (Builder extends SlashCommandBuilder ? never : CommandInvalidArguments<Builder> | CommandMissingArguments<Builder>) | CommandMissingMemberPermissions<Builder> | CommandMissingBotPermissions<Builder>;
10
- export interface CommandHaltBaseData<Builder extends CommandBuilder> {
11
- executeData: Builder extends SlashCommandBuilder ? SlashCommandExecuteData : MessageCommandExecuteData;
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>;
10
+ /**
11
+ * Command halt reason base interface
12
+ */
13
+ export interface CommandHaltReasonBase<T extends CommandBuilderType> {
14
+ executeData: T extends CommandBuilderType.SlashCommand ? SlashCommandExecuteData : T extends CommandBuilderType.MessageCommand ? MessageCommandExecuteData : AnyCommandExecuteData;
12
15
  }
13
- export interface CommandErrorData<Builder extends CommandBuilder> extends CommandHaltBaseData<Builder> {
14
- reason: HaltedCommandReason.Error;
16
+ export interface CommandErrorData<T extends CommandBuilderType> extends CommandHaltReasonBase<T> {
17
+ reason: CommandHaltReason.Error;
15
18
  error: any;
16
19
  }
17
- export interface CommandCooldownData<Builder extends CommandBuilder> extends CommandHaltBaseData<Builder>, CooledDownUser {
18
- reason: HaltedCommandReason.Cooldown;
20
+ export interface CommandCooldownData<T extends CommandBuilderType> extends CommandHaltReasonBase<T>, CooledDownUser {
21
+ reason: CommandHaltReason.Cooldown;
19
22
  }
20
- export interface CommandInvalidArguments<Builder extends CommandBuilder> extends CommandHaltBaseData<Builder> {
21
- reason: HaltedCommandReason.InvalidArguments;
23
+ export interface CommandInvalidArguments<T extends CommandBuilderType> extends CommandHaltReasonBase<T> {
24
+ reason: CommandHaltReason.InvalidArguments;
22
25
  invalidArguments: MessageCommandOptionManager;
23
26
  }
24
- export interface CommandMissingArguments<Builder extends CommandBuilder> extends CommandHaltBaseData<Builder> {
25
- reason: HaltedCommandReason.MissingArguments;
27
+ export interface CommandMissingArguments<T extends CommandBuilderType> extends CommandHaltReasonBase<T> {
28
+ reason: CommandHaltReason.MissingArguments;
26
29
  missingArguments: MessageCommandOptionManager;
27
30
  }
28
- export interface CommandMissingMemberPermissions<Builder extends CommandBuilder> extends CommandHaltBaseData<Builder> {
29
- reason: HaltedCommandReason.MissingMemberPermissions;
31
+ export interface CommandMissingMemberPermissions<T extends CommandBuilderType> extends CommandHaltReasonBase<T> {
32
+ reason: CommandHaltReason.MissingMemberPermissions;
30
33
  }
31
- export interface CommandMissingBotPermissions<Builder extends CommandBuilder> extends CommandHaltBaseData<Builder> {
32
- reason: HaltedCommandReason.MissingBotPermissions;
34
+ export interface CommandMissingBotPermissions<T extends CommandBuilderType> extends CommandHaltReasonBase<T> {
35
+ reason: CommandHaltReason.MissingBotPermissions;
33
36
  }
34
37
  /**
35
38
  * Command halt reasons
36
39
  */
37
- export declare enum HaltedCommandReason {
40
+ export declare enum CommandHaltReason {
38
41
  Error = 0,
39
42
  Cooldown = 1,
40
43
  InvalidArguments = 2,
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HaltedCommandReason = void 0;
3
+ exports.CommandHaltReason = void 0;
4
4
  /**
5
5
  * Command halt reasons
6
6
  */
7
- var HaltedCommandReason;
8
- (function (HaltedCommandReason) {
9
- HaltedCommandReason[HaltedCommandReason["Error"] = 0] = "Error";
10
- HaltedCommandReason[HaltedCommandReason["Cooldown"] = 1] = "Cooldown";
11
- HaltedCommandReason[HaltedCommandReason["InvalidArguments"] = 2] = "InvalidArguments";
12
- HaltedCommandReason[HaltedCommandReason["MissingArguments"] = 3] = "MissingArguments";
13
- HaltedCommandReason[HaltedCommandReason["MissingMemberPermissions"] = 4] = "MissingMemberPermissions";
14
- HaltedCommandReason[HaltedCommandReason["MissingBotPermissions"] = 5] = "MissingBotPermissions";
15
- })(HaltedCommandReason = exports.HaltedCommandReason || (exports.HaltedCommandReason = {}));
7
+ var CommandHaltReason;
8
+ (function (CommandHaltReason) {
9
+ CommandHaltReason[CommandHaltReason["Error"] = 0] = "Error";
10
+ CommandHaltReason[CommandHaltReason["Cooldown"] = 1] = "Cooldown";
11
+ CommandHaltReason[CommandHaltReason["InvalidArguments"] = 2] = "InvalidArguments";
12
+ CommandHaltReason[CommandHaltReason["MissingArguments"] = 3] = "MissingArguments";
13
+ CommandHaltReason[CommandHaltReason["MissingMemberPermissions"] = 4] = "MissingMemberPermissions";
14
+ CommandHaltReason[CommandHaltReason["MissingBotPermissions"] = 5] = "MissingBotPermissions";
15
+ })(CommandHaltReason = exports.CommandHaltReason || (exports.CommandHaltReason = {}));
@@ -3,7 +3,7 @@ import { ApplicationCommandData, PermissionsBitField } from 'discord.js';
3
3
  import { RecipleModule, RecipleScript } from '../modules';
4
4
  import { RecipleClient } from '../classes/RecipleClient';
5
5
  import { Config } from '../classes/RecipleConfig';
6
- import { CommandBuilder } from './builders';
6
+ import { AnyCommandBuilder } from './builders';
7
7
  export interface RecipleClientAddModuleOptions {
8
8
  /**
9
9
  * The Module script
@@ -33,7 +33,7 @@ export interface RegisterApplicationCommandsOptions {
33
33
  guilds?: string | string[];
34
34
  }
35
35
  export interface UserHasCommandPermissionsOptions {
36
- builder: CommandBuilder;
36
+ builder: AnyCommandBuilder;
37
37
  memberPermissions?: PermissionsBitField;
38
38
  commandPermissions?: Config["commands"]["slashCommand"]["permissions"] | Config["commands"]["messageCommand"]["permissions"];
39
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "4.0.0",
3
+ "version": "5.0.0-pre.1",
4
4
  "bin": "bin/bin.js",
5
5
  "license": "GPL-3.0",
6
6
  "main": "bin/index.js",
@@ -58,7 +58,7 @@
58
58
  "devDependencies": {
59
59
  "@types/node": "^18.6.1",
60
60
  "@types/semver": "^7.3.10",
61
- "discord.js": "^14.0.3",
61
+ "discord.js": "^14.1.2",
62
62
  "rimraf": "^3.0.2",
63
63
  "typedoc": "^0.23.9",
64
64
  "typedoc-plugin-discord-types": "^1.0.2",
@@ -67,7 +67,7 @@
67
67
  "typescript": "^4.7.4"
68
68
  },
69
69
  "peerDependencies": {
70
- "discord.js": "^14.0.3"
70
+ "discord.js": "^14.1.2"
71
71
  },
72
72
  "packageManager": "yarn@3.2.2"
73
73
  }