reciple 4.1.2 → 5.0.0-pre.3
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 +3 -0
- package/bin/reciple/classes/RecipleClient.d.ts +4 -4
- package/bin/reciple/classes/RecipleClient.js +27 -29
- package/bin/reciple/classes/RecipleConfig.d.ts +0 -5
- 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/flags.js +2 -1
- package/bin/reciple/modules.d.ts +3 -3
- package/bin/reciple/modules.js +4 -4
- package/bin/reciple/permissions.d.ts +0 -7
- package/bin/reciple/permissions.js +1 -16
- 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 +1 -1
- package/resource/reciple.yml +0 -10
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,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';
|
|
@@ -53,7 +53,7 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
|
|
|
53
53
|
config: Config;
|
|
54
54
|
commands: RecipleClientCommands;
|
|
55
55
|
otherApplicationCommandData: (ApplicationCommandBuilder | ApplicationCommandData)[];
|
|
56
|
-
|
|
56
|
+
cooldowns: CommandCooldownManager;
|
|
57
57
|
modules: RecipleModule[];
|
|
58
58
|
logger: ILogger;
|
|
59
59
|
version: string;
|
|
@@ -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,9 +11,10 @@ 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
16
|
const builders_1 = require("../types/builders");
|
|
17
|
+
const permissions_1 = require("../permissions");
|
|
17
18
|
const CommandCooldownManager_1 = require("./CommandCooldownManager");
|
|
18
19
|
const MessageCommandOptionManager_1 = require("./MessageCommandOptionManager");
|
|
19
20
|
const commands_1 = require("../types/commands");
|
|
@@ -33,7 +34,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
33
34
|
this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
|
|
34
35
|
this.commands = { messageCommands: {}, slashCommands: {} };
|
|
35
36
|
this.otherApplicationCommandData = [];
|
|
36
|
-
this.
|
|
37
|
+
this.cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
|
|
37
38
|
this.modules = [];
|
|
38
39
|
this.version = version_1.version;
|
|
39
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);
|
|
@@ -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()) {
|
|
@@ -184,27 +185,24 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
184
185
|
memberPermissions: (_a = message.member) === null || _a === void 0 ? void 0 : _a.permissions,
|
|
185
186
|
commandPermissions: this.config.commands.messageCommand.permissions
|
|
186
187
|
})) {
|
|
187
|
-
if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM
|
|
188
|
-
|| !command.allowExecuteByBots
|
|
189
|
-
&& (message.author.bot || message.author.system)
|
|
190
|
-
|| (0, permissions_1.isIgnoredChannel)(message.channelId, this.config.ignoredChannels))
|
|
188
|
+
if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM || !command.allowExecuteByBots && (message.author.bot || message.author.system))
|
|
191
189
|
return;
|
|
192
190
|
if (command.validateOptions) {
|
|
193
191
|
if (commandOptions.some(o => o.invalid)) {
|
|
194
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.
|
|
192
|
+
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)) }))) {
|
|
195
193
|
message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
|
|
196
194
|
}
|
|
197
195
|
return;
|
|
198
196
|
}
|
|
199
197
|
if (commandOptions.some(o => o.missing)) {
|
|
200
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.
|
|
198
|
+
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)) }))) {
|
|
201
199
|
message.reply(this.getMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
|
|
202
200
|
}
|
|
203
201
|
return;
|
|
204
202
|
}
|
|
205
203
|
}
|
|
206
204
|
if (message.guild && !(0, permissions_1.botHasExecutePermissions)(message.guild, command.requiredBotPermissions)) {
|
|
207
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.
|
|
205
|
+
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
|
|
208
206
|
message.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
|
|
209
207
|
}
|
|
210
208
|
return;
|
|
@@ -216,11 +214,11 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
216
214
|
guild: message.guild,
|
|
217
215
|
type: builders_1.CommandBuilderType.MessageCommand
|
|
218
216
|
};
|
|
219
|
-
if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.
|
|
220
|
-
this.
|
|
217
|
+
if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
|
|
218
|
+
this.cooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
|
|
221
219
|
}
|
|
222
220
|
else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
|
|
223
|
-
if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.
|
|
221
|
+
if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.cooldowns.get(userCooldown))))) {
|
|
224
222
|
yield message.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
|
|
225
223
|
}
|
|
226
224
|
return;
|
|
@@ -228,16 +226,16 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
228
226
|
try {
|
|
229
227
|
yield Promise.resolve(command.execute(executeData))
|
|
230
228
|
.then(() => this.emit('recipleMessageCommandCreate', executeData))
|
|
231
|
-
.catch((err) => __awaiter(this, void 0, void 0, function* () { return (yield this._haltCommand(command, { executeData, reason: commands_1.
|
|
229
|
+
.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
230
|
return executeData;
|
|
233
231
|
}
|
|
234
232
|
catch (err) {
|
|
235
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.
|
|
233
|
+
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Error, error: err }))) {
|
|
236
234
|
this._commandExecuteError(err, executeData);
|
|
237
235
|
}
|
|
238
236
|
}
|
|
239
237
|
}
|
|
240
|
-
else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.
|
|
238
|
+
else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
|
|
241
239
|
message.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
242
240
|
}
|
|
243
241
|
});
|
|
@@ -264,10 +262,10 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
264
262
|
memberPermissions: (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined,
|
|
265
263
|
commandPermissions: this.config.commands.slashCommand.permissions
|
|
266
264
|
})) {
|
|
267
|
-
if (!command
|
|
265
|
+
if (!command)
|
|
268
266
|
return;
|
|
269
267
|
if (interaction.guild && !(0, permissions_1.botHasExecutePermissions)(interaction.guild, command.requiredBotPermissions)) {
|
|
270
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.
|
|
268
|
+
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
|
|
271
269
|
yield interaction.reply(this.getMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
|
|
272
270
|
}
|
|
273
271
|
return;
|
|
@@ -279,11 +277,11 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
279
277
|
guild: interaction.guild,
|
|
280
278
|
type: builders_1.CommandBuilderType.SlashCommand
|
|
281
279
|
};
|
|
282
|
-
if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.
|
|
283
|
-
this.
|
|
280
|
+
if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
|
|
281
|
+
this.cooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
|
|
284
282
|
}
|
|
285
283
|
else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
|
|
286
|
-
if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.
|
|
284
|
+
if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.cooldowns.get(userCooldown))))) {
|
|
287
285
|
yield interaction.reply(this.getMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
|
|
288
286
|
}
|
|
289
287
|
return;
|
|
@@ -291,16 +289,16 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
291
289
|
try {
|
|
292
290
|
yield Promise.resolve(command.execute(executeData))
|
|
293
291
|
.then(() => this.emit('recipleInteractionCommandCreate', executeData))
|
|
294
|
-
.catch((err) => __awaiter(this, void 0, void 0, function* () { return (yield this._haltCommand(command, { executeData, reason: commands_1.
|
|
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; }));
|
|
295
293
|
return executeData;
|
|
296
294
|
}
|
|
297
295
|
catch (err) {
|
|
298
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.
|
|
296
|
+
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Error, error: err }))) {
|
|
299
297
|
this._commandExecuteError(err, executeData);
|
|
300
298
|
}
|
|
301
299
|
}
|
|
302
300
|
}
|
|
303
|
-
else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.
|
|
301
|
+
else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
|
|
304
302
|
yield interaction.reply(this.getMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
305
303
|
}
|
|
306
304
|
});
|
|
@@ -345,7 +343,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
345
343
|
return __awaiter(this, void 0, void 0, function* () {
|
|
346
344
|
try {
|
|
347
345
|
return (_a = (command.halt
|
|
348
|
-
? yield (command.
|
|
346
|
+
? yield (command.type == builders_1.CommandBuilderType.SlashCommand
|
|
349
347
|
? Promise.resolve(command.halt(haltData))
|
|
350
348
|
: Promise.resolve(command.halt(haltData))).catch(err => { throw err; })
|
|
351
349
|
: false)) !== null && _a !== void 0 ? _a : false;
|
|
@@ -367,17 +365,17 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
367
365
|
_commandExecuteError(err, command) {
|
|
368
366
|
return __awaiter(this, void 0, void 0, function* () {
|
|
369
367
|
if (this.isClientLogsEnabled()) {
|
|
370
|
-
this.logger.error(`An error occured executing ${command.builder.
|
|
368
|
+
this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandBuilderType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
|
|
371
369
|
this.logger.error(err);
|
|
372
370
|
}
|
|
373
371
|
if (!err || !command)
|
|
374
372
|
return;
|
|
375
|
-
if (command
|
|
373
|
+
if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
|
|
376
374
|
if (!this.config.commands.messageCommand.replyOnError)
|
|
377
375
|
return;
|
|
378
376
|
yield command.message.reply(this.getMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
|
|
379
377
|
}
|
|
380
|
-
else if (command
|
|
378
|
+
else if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
|
|
381
379
|
if (!this.config.commands.slashCommand.replyOnError)
|
|
382
380
|
return;
|
|
383
381
|
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/flags.js
CHANGED
|
@@ -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${
|
|
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')
|
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,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.
|
|
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;
|
|
@@ -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
package/resource/reciple.yml
CHANGED
|
@@ -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
|