reciple 4.1.0 → 5.0.0-pre.2
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/reciple/classes/RecipleClient.d.ts +3 -3
- package/bin/reciple/classes/RecipleClient.js +21 -20
- package/bin/reciple/classes/builders/MessageCommandBuilder.d.ts +27 -6
- package/bin/reciple/classes/builders/MessageCommandBuilder.js +13 -1
- package/bin/reciple/classes/builders/SlashCommandBuilder.d.ts +27 -6
- package/bin/reciple/classes/builders/SlashCommandBuilder.js +13 -1
- package/bin/reciple/modules.d.ts +3 -3
- package/bin/reciple/modules.js +4 -4
- package/bin/reciple/types/builders.d.ts +12 -9
- package/bin/reciple/types/commands.d.ts +27 -20
- package/bin/reciple/types/commands.js +10 -10
- package/bin/reciple/types/paramOptions.d.ts +2 -2
- package/package.json +3 -3
|
@@ -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:
|
|
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
|
|
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.
|
|
138
|
+
if (command.type === builders_1.CommandBuilderType.MessageCommand) {
|
|
138
139
|
this.commands.messageCommands[command.name] = command;
|
|
139
140
|
}
|
|
140
|
-
else if (command.
|
|
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()) {
|
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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 ||
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
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));
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { CommandBuilderType,
|
|
1
|
+
import { CommandBuilderType, AnyCommandExecuteData, CommandHaltFunction, CommandExecuteFunction } 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
5
|
import { Message, PermissionResolvable } from 'discord.js';
|
|
6
|
+
import { CommandHaltData } from '../../types/commands';
|
|
6
7
|
import { RecipleClient } from '../RecipleClient';
|
|
7
8
|
/**
|
|
8
9
|
* Execute data for message command
|
|
@@ -24,11 +25,23 @@ export interface MessageCommandValidatedOption {
|
|
|
24
25
|
invalid: boolean;
|
|
25
26
|
missing: boolean;
|
|
26
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Message command halt data
|
|
30
|
+
*/
|
|
31
|
+
export declare type MessageCommandHaltData = CommandHaltData<CommandBuilderType.MessageCommand>;
|
|
32
|
+
/**
|
|
33
|
+
* Message command halt function
|
|
34
|
+
*/
|
|
35
|
+
export declare type MessageCommandHaltFunction = CommandHaltFunction<CommandBuilderType.MessageCommand>;
|
|
36
|
+
/**
|
|
37
|
+
* Message command execute function
|
|
38
|
+
*/
|
|
39
|
+
export declare type MessageCommandExecuteFunction = CommandExecuteFunction<CommandBuilderType.MessageCommand>;
|
|
27
40
|
/**
|
|
28
41
|
* Reciple builder for message command
|
|
29
42
|
*/
|
|
30
43
|
export declare class MessageCommandBuilder {
|
|
31
|
-
readonly
|
|
44
|
+
readonly type = CommandBuilderType.MessageCommand;
|
|
32
45
|
name: string;
|
|
33
46
|
cooldown: number;
|
|
34
47
|
description: string;
|
|
@@ -39,8 +52,8 @@ export declare class MessageCommandBuilder {
|
|
|
39
52
|
requiredMemberPermissions: PermissionResolvable[];
|
|
40
53
|
allowExecuteInDM: boolean;
|
|
41
54
|
allowExecuteByBots: boolean;
|
|
42
|
-
halt?:
|
|
43
|
-
execute:
|
|
55
|
+
halt?: MessageCommandHaltFunction;
|
|
56
|
+
execute: MessageCommandExecuteFunction;
|
|
44
57
|
/**
|
|
45
58
|
* Sets the command name
|
|
46
59
|
* @param name Command name
|
|
@@ -86,12 +99,12 @@ export declare class MessageCommandBuilder {
|
|
|
86
99
|
* Function when the command is interupted
|
|
87
100
|
* @param halt Function to execute when command is halted
|
|
88
101
|
*/
|
|
89
|
-
setHalt(halt?:
|
|
102
|
+
setHalt(halt?: this["halt"]): this;
|
|
90
103
|
/**
|
|
91
104
|
* Function when the command is executed
|
|
92
105
|
* @param execute Function to execute when the command is called
|
|
93
106
|
*/
|
|
94
|
-
setExecute(execute:
|
|
107
|
+
setExecute(execute: this["execute"]): this;
|
|
95
108
|
/**
|
|
96
109
|
* Add option to the command
|
|
97
110
|
* @param option Message option builder
|
|
@@ -102,5 +115,13 @@ export declare class MessageCommandBuilder {
|
|
|
102
115
|
* @param validateOptions `true` if the command options needs to be validated before executing
|
|
103
116
|
*/
|
|
104
117
|
setValidateOptions(validateOptions: boolean): this;
|
|
118
|
+
/**
|
|
119
|
+
* Is a message command builder
|
|
120
|
+
*/
|
|
121
|
+
static isMessageCommandBuilder(builder: any): builder is MessageCommandBuilder;
|
|
122
|
+
/**
|
|
123
|
+
* Is a message command execute data
|
|
124
|
+
*/
|
|
125
|
+
static isMessageCommandExecuteData(executeData: AnyCommandExecuteData): executeData is MessageCommandExecuteData;
|
|
105
126
|
}
|
|
106
127
|
export declare function validateMessageCommandOptions(builder: MessageCommandBuilder, options: CommandMessage): Promise<MessageCommandOptionManager>;
|
|
@@ -18,7 +18,7 @@ const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
|
|
|
18
18
|
*/
|
|
19
19
|
class MessageCommandBuilder {
|
|
20
20
|
constructor() {
|
|
21
|
-
this.
|
|
21
|
+
this.type = builders_1.CommandBuilderType.MessageCommand;
|
|
22
22
|
this.name = '';
|
|
23
23
|
this.cooldown = 0;
|
|
24
24
|
this.description = '';
|
|
@@ -153,6 +153,18 @@ class MessageCommandBuilder {
|
|
|
153
153
|
this.validateOptions = validateOptions;
|
|
154
154
|
return this;
|
|
155
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Is a message command builder
|
|
158
|
+
*/
|
|
159
|
+
static isMessageCommandBuilder(builder) {
|
|
160
|
+
return builder instanceof MessageCommandBuilder;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Is a message command execute data
|
|
164
|
+
*/
|
|
165
|
+
static isMessageCommandExecuteData(executeData) {
|
|
166
|
+
return executeData.builder !== undefined && this.isMessageCommandBuilder(executeData.builder);
|
|
167
|
+
}
|
|
156
168
|
}
|
|
157
169
|
exports.MessageCommandBuilder = MessageCommandBuilder;
|
|
158
170
|
function validateMessageCommandOptions(builder, options) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { CommandBuilderType,
|
|
1
|
+
import { CommandBuilderType, AnyCommandExecuteData, CommandHaltFunction, CommandExecuteFunction } from '../../types/builders';
|
|
2
|
+
import { CommandHaltData } from '../../types/commands';
|
|
2
3
|
import { RecipleClient } from '../RecipleClient';
|
|
3
4
|
import { ChatInputCommandInteraction, PermissionResolvable, SlashCommandBuilder as DiscordJsSlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder as DiscordJsSlashCommandSubcommandsOnlyBuilder } from 'discord.js';
|
|
4
5
|
/**
|
|
@@ -15,17 +16,29 @@ export interface SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
|
|
|
15
16
|
addSubcommandGroup(input: SlashCommandSubcommandGroupBuilder | ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder)): SlashCommandSubcommandsOnlyBuilder;
|
|
16
17
|
addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): SlashCommandSubcommandsOnlyBuilder;
|
|
17
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Slash command halt data
|
|
21
|
+
*/
|
|
22
|
+
export declare type SlashCommandHaltData = CommandHaltData<CommandBuilderType.SlashCommand>;
|
|
23
|
+
/**
|
|
24
|
+
* Slash command halt function
|
|
25
|
+
*/
|
|
26
|
+
export declare type SlashCommandHaltFunction = CommandHaltFunction<CommandBuilderType.SlashCommand>;
|
|
27
|
+
/**
|
|
28
|
+
* Slash command execute function
|
|
29
|
+
*/
|
|
30
|
+
export declare type SlashCommandExecuteFunction = CommandExecuteFunction<CommandBuilderType.SlashCommand>;
|
|
18
31
|
/**
|
|
19
32
|
* Reciple builder for interaction/slash command
|
|
20
33
|
*/
|
|
21
34
|
export declare class SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
|
|
22
|
-
readonly
|
|
35
|
+
readonly type = CommandBuilderType.SlashCommand;
|
|
23
36
|
cooldown: number;
|
|
24
37
|
requiredBotPermissions: PermissionResolvable[];
|
|
25
38
|
requiredMemberPermissions: PermissionResolvable[];
|
|
26
39
|
allowExecuteInDM: boolean;
|
|
27
|
-
halt?:
|
|
28
|
-
execute:
|
|
40
|
+
halt?: SlashCommandHaltFunction;
|
|
41
|
+
execute: SlashCommandExecuteFunction;
|
|
29
42
|
/**
|
|
30
43
|
* Sets the execute cooldown for this command.
|
|
31
44
|
* - `0` means no cooldown
|
|
@@ -46,10 +59,18 @@ export declare class SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
|
|
|
46
59
|
* Function when the command is interupted
|
|
47
60
|
* @param halt Function to execute when command is halted
|
|
48
61
|
*/
|
|
49
|
-
setHalt(halt?:
|
|
62
|
+
setHalt(halt?: this["halt"]): this;
|
|
50
63
|
/**
|
|
51
64
|
* Function when the command is executed
|
|
52
65
|
* @param execute Function to execute when the command is called
|
|
53
66
|
*/
|
|
54
|
-
setExecute(execute:
|
|
67
|
+
setExecute(execute: this["execute"]): this;
|
|
68
|
+
/**
|
|
69
|
+
* Is a slash command builder
|
|
70
|
+
*/
|
|
71
|
+
static isSlashCommandBuilder(builder: any): builder is SlashCommandBuilder;
|
|
72
|
+
/**
|
|
73
|
+
* Is a slash command execute data
|
|
74
|
+
*/
|
|
75
|
+
static isSlashCommandExecuteData(executeData: AnyCommandExecuteData): executeData is SlashCommandExecuteData;
|
|
55
76
|
}
|
|
@@ -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.
|
|
12
|
+
this.type = builders_1.CommandBuilderType.SlashCommand;
|
|
13
13
|
this.cooldown = 0;
|
|
14
14
|
this.requiredBotPermissions = [];
|
|
15
15
|
this.requiredMemberPermissions = [];
|
|
@@ -59,5 +59,17 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
59
59
|
this.execute = execute;
|
|
60
60
|
return this;
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Is a slash command builder
|
|
64
|
+
*/
|
|
65
|
+
static isSlashCommandBuilder(builder) {
|
|
66
|
+
return builder instanceof SlashCommandBuilder;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Is a slash command execute data
|
|
70
|
+
*/
|
|
71
|
+
static isSlashCommandExecuteData(executeData) {
|
|
72
|
+
return executeData.builder !== undefined && this.isSlashCommandBuilder(executeData.builder);
|
|
73
|
+
}
|
|
62
74
|
}
|
|
63
75
|
exports.SlashCommandBuilder = SlashCommandBuilder;
|
package/bin/reciple/modules.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyCommandBuilder } from './types/builders';
|
|
2
2
|
import { RecipleClient } from './classes/RecipleClient';
|
|
3
3
|
export declare type LoadedModules = {
|
|
4
|
-
commands:
|
|
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?:
|
|
12
|
+
commands?: AnyCommandBuilder[];
|
|
13
13
|
onLoad?(reciple: RecipleClient): void | Promise<void>;
|
|
14
14
|
onStart(reciple: RecipleClient): boolean | Promise<boolean>;
|
|
15
15
|
}
|
package/bin/reciple/modules.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
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.
|
|
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,23 +1,26 @@
|
|
|
1
|
+
import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandHaltData, MessageCommandHaltFunction } from '../classes/builders/MessageCommandBuilder';
|
|
2
|
+
import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandHaltData, SlashCommandHaltFunction } from '../classes/builders/SlashCommandBuilder';
|
|
1
3
|
import { Awaitable } from 'discord.js';
|
|
2
|
-
import { MessageCommandBuilder, MessageCommandExecuteData } from '../classes/builders/MessageCommandBuilder';
|
|
3
|
-
import { SlashCommandBuilder, SlashCommandExecuteData } from '../classes/builders/SlashCommandBuilder';
|
|
4
|
-
import { HaltedCommandData } from './commands';
|
|
5
4
|
/**
|
|
6
|
-
* Reciple command builders
|
|
5
|
+
* Any Reciple command builders
|
|
7
6
|
*/
|
|
8
|
-
export declare type
|
|
7
|
+
export declare type AnyCommandBuilder = SlashCommandBuilder | MessageCommandBuilder;
|
|
9
8
|
/**
|
|
10
|
-
* Reciple command
|
|
9
|
+
* Any Reciple command execute data
|
|
11
10
|
*/
|
|
12
|
-
export declare type
|
|
11
|
+
export declare type AnyCommandExecuteData = SlashCommandExecuteData | MessageCommandExecuteData;
|
|
12
|
+
/**
|
|
13
|
+
* Any Reciple command halt functions
|
|
14
|
+
*/
|
|
15
|
+
export declare type AnyCommandHaltFunction = SlashCommandHaltFunction | MessageCommandHaltFunction;
|
|
13
16
|
/**
|
|
14
17
|
* Reciple command halt function
|
|
15
18
|
*/
|
|
16
|
-
export declare type CommandHaltFunction<
|
|
19
|
+
export declare type CommandHaltFunction<T extends CommandBuilderType> = (haltData: T extends CommandBuilderType.SlashCommand ? SlashCommandHaltData : MessageCommandHaltData) => Awaitable<boolean | null | undefined | void>;
|
|
17
20
|
/**
|
|
18
21
|
* Reciple command execute function
|
|
19
22
|
*/
|
|
20
|
-
export declare type CommandExecuteFunction<
|
|
23
|
+
export declare type CommandExecuteFunction<T extends CommandBuilderType> = (executeData: T extends CommandBuilderType.SlashCommand ? SlashCommandExecuteData : MessageCommandExecuteData) => Awaitable<void>;
|
|
21
24
|
/**
|
|
22
25
|
* Types of Reciple command builders
|
|
23
26
|
*/
|
|
@@ -1,40 +1,47 @@
|
|
|
1
|
-
import { MessageCommandExecuteData } from '../classes/builders/MessageCommandBuilder';
|
|
2
|
-
import {
|
|
1
|
+
import { MessageCommandExecuteData, MessageCommandHaltData } from '../classes/builders/MessageCommandBuilder';
|
|
2
|
+
import { SlashCommandExecuteData, SlashCommandHaltData } from '../classes/builders/SlashCommandBuilder';
|
|
3
3
|
import { MessageCommandOptionManager } from '../classes/MessageCommandOptionManager';
|
|
4
|
+
import { CommandBuilderType, AnyCommandExecuteData } from '../types/builders';
|
|
4
5
|
import { CooledDownUser } from '../classes/CommandCooldownManager';
|
|
5
|
-
import { CommandBuilder } from '../types/builders';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Any reciple halted command data
|
|
8
8
|
*/
|
|
9
|
-
export declare type
|
|
10
|
-
|
|
11
|
-
|
|
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>;
|
|
14
|
+
/**
|
|
15
|
+
* Command halt reason base interface
|
|
16
|
+
*/
|
|
17
|
+
export interface CommandHaltReasonBase<T extends CommandBuilderType> {
|
|
18
|
+
executeData: T extends CommandBuilderType.SlashCommand ? SlashCommandExecuteData : T extends CommandBuilderType.MessageCommand ? MessageCommandExecuteData : AnyCommandExecuteData;
|
|
12
19
|
}
|
|
13
|
-
export interface CommandErrorData<
|
|
14
|
-
reason:
|
|
20
|
+
export interface CommandErrorData<T extends CommandBuilderType> extends CommandHaltReasonBase<T> {
|
|
21
|
+
reason: CommandHaltReason.Error;
|
|
15
22
|
error: any;
|
|
16
23
|
}
|
|
17
|
-
export interface CommandCooldownData<
|
|
18
|
-
reason:
|
|
24
|
+
export interface CommandCooldownData<T extends CommandBuilderType> extends CommandHaltReasonBase<T>, CooledDownUser {
|
|
25
|
+
reason: CommandHaltReason.Cooldown;
|
|
19
26
|
}
|
|
20
|
-
export interface CommandInvalidArguments<
|
|
21
|
-
reason:
|
|
27
|
+
export interface CommandInvalidArguments<T extends CommandBuilderType> extends CommandHaltReasonBase<T> {
|
|
28
|
+
reason: CommandHaltReason.InvalidArguments;
|
|
22
29
|
invalidArguments: MessageCommandOptionManager;
|
|
23
30
|
}
|
|
24
|
-
export interface CommandMissingArguments<
|
|
25
|
-
reason:
|
|
31
|
+
export interface CommandMissingArguments<T extends CommandBuilderType> extends CommandHaltReasonBase<T> {
|
|
32
|
+
reason: CommandHaltReason.MissingArguments;
|
|
26
33
|
missingArguments: MessageCommandOptionManager;
|
|
27
34
|
}
|
|
28
|
-
export interface CommandMissingMemberPermissions<
|
|
29
|
-
reason:
|
|
35
|
+
export interface CommandMissingMemberPermissions<T extends CommandBuilderType> extends CommandHaltReasonBase<T> {
|
|
36
|
+
reason: CommandHaltReason.MissingMemberPermissions;
|
|
30
37
|
}
|
|
31
|
-
export interface CommandMissingBotPermissions<
|
|
32
|
-
reason:
|
|
38
|
+
export interface CommandMissingBotPermissions<T extends CommandBuilderType> extends CommandHaltReasonBase<T> {
|
|
39
|
+
reason: CommandHaltReason.MissingBotPermissions;
|
|
33
40
|
}
|
|
34
41
|
/**
|
|
35
42
|
* Command halt reasons
|
|
36
43
|
*/
|
|
37
|
-
export declare enum
|
|
44
|
+
export declare enum CommandHaltReason {
|
|
38
45
|
Error = 0,
|
|
39
46
|
Cooldown = 1,
|
|
40
47
|
InvalidArguments = 2,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CommandHaltReason = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Command halt reasons
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
(function (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
})(
|
|
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 {
|
|
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:
|
|
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": "
|
|
3
|
+
"version": "5.0.0-pre.2",
|
|
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.
|
|
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.
|
|
70
|
+
"discord.js": "^14.1.2"
|
|
71
71
|
},
|
|
72
72
|
"packageManager": "yarn@3.2.2"
|
|
73
73
|
}
|