reciple 1.3.1 → 1.3.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/Client.d.ts +2 -2
- package/bin/reciple/classes/Client.js +3 -8
- package/bin/reciple/classes/builders/MessageCommandBuilder.d.ts +3 -12
- package/bin/reciple/classes/builders/MessageCommandBuilder.js +13 -45
- package/bin/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +10 -0
- package/bin/reciple/classes/builders/MessageCommandOptionBuilder.js +36 -0
- package/bin/reciple/modules.d.ts +2 -2
- package/bin/reciple/registerInteractionCommands.js +12 -13
- package/package.json +1 -1
|
@@ -10,10 +10,10 @@ export interface RecipleClientOptions extends ClientOptions {
|
|
|
10
10
|
}
|
|
11
11
|
export interface RecipleClientCommands {
|
|
12
12
|
MESSAGE_COMMANDS: {
|
|
13
|
-
[
|
|
13
|
+
[commandName: string]: MessageCommandBuilder;
|
|
14
14
|
};
|
|
15
15
|
INTERACTION_COMMANDS: {
|
|
16
|
-
[
|
|
16
|
+
[commandName: string]: InteractionCommandBuilder;
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
export interface RecipleClientEvents extends ClientEvents {
|
|
@@ -90,7 +90,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
90
90
|
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, ((_b = this.config) === null || _b === void 0 ? void 0 : _b.prefix) || '!', ((_c = this.config) === null || _c === void 0 ? void 0 : _c.commands.messageCommand.commandArgumentSeparator) || ' ');
|
|
91
91
|
if (!(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command) || !parseCommand)
|
|
92
92
|
return this;
|
|
93
|
-
const command = this.commands.MESSAGE_COMMANDS[parseCommand.command];
|
|
93
|
+
const command = this.commands.MESSAGE_COMMANDS[parseCommand.command.toLowerCase()];
|
|
94
94
|
if (!command)
|
|
95
95
|
return this;
|
|
96
96
|
if ((0, commandPermissions_1.commandPermissions)(command.name, (_d = message.member) === null || _d === void 0 ? void 0 : _d.permissions, (_e = this.config) === null || _e === void 0 ? void 0 : _e.permissions.messageCommands, command)) {
|
|
@@ -144,7 +144,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
_commandExecuteError(err, command) {
|
|
147
|
-
var _a, _b, _c, _d
|
|
147
|
+
var _a, _b, _c, _d;
|
|
148
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
149
|
this.logger.error(`An error occured executing ${command.builder.builder == 'MESSAGE_COMMAND' ? 'message' : 'interaction'} command "${command.builder.name}"`);
|
|
150
150
|
this.logger.error(err);
|
|
@@ -158,12 +158,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
158
158
|
else if (command === null || command === void 0 ? void 0 : command.interaction) {
|
|
159
159
|
if (!((_c = this.config) === null || _c === void 0 ? void 0 : _c.commands.interactionCommand.replyOnError))
|
|
160
160
|
return;
|
|
161
|
-
|
|
162
|
-
yield command.interaction.reply(((_d = this.config) === null || _d === void 0 ? void 0 : _d.messages.error) || 'An error occured.').catch((e) => this.logger.error(e));
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
yield command.interaction.followUp(((_e = this.config) === null || _e === void 0 ? void 0 : _e.messages.error) || 'An error occured.').catch((e) => this.logger.error(e));
|
|
166
|
-
}
|
|
161
|
+
yield command.interaction.followUp(((_d = this.config) === null || _d === void 0 ? void 0 : _d.messages.error) || 'An error occured.').catch((e) => this.logger.error(e));
|
|
167
162
|
}
|
|
168
163
|
});
|
|
169
164
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Message, PermissionFlags, PermissionString } from 'discord.js';
|
|
2
2
|
import { Command } from 'fallout-utility';
|
|
3
3
|
import { RecipleClient } from '../Client';
|
|
4
|
+
import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
|
|
4
5
|
export declare type CommandMessage = Command;
|
|
5
6
|
export interface RecipleMessageCommandExecute {
|
|
6
7
|
message: Message;
|
|
@@ -13,21 +14,11 @@ export interface MessageCommandValidatedOption {
|
|
|
13
14
|
value: string;
|
|
14
15
|
required: boolean;
|
|
15
16
|
}
|
|
16
|
-
export declare class MessageOption {
|
|
17
|
-
name: string;
|
|
18
|
-
description: string;
|
|
19
|
-
required: boolean;
|
|
20
|
-
validate: (value: string) => boolean;
|
|
21
|
-
setName(name: string): MessageOption;
|
|
22
|
-
setDescription(description: string): MessageOption;
|
|
23
|
-
setRequired(required: boolean): MessageOption;
|
|
24
|
-
setValidator(validator: (value: string) => boolean): MessageOption;
|
|
25
|
-
}
|
|
26
17
|
export declare class MessageCommandBuilder {
|
|
27
18
|
readonly builder: string;
|
|
28
19
|
name: string;
|
|
29
20
|
description: string;
|
|
30
|
-
options:
|
|
21
|
+
options: MessageCommandOptionBuilder[];
|
|
31
22
|
validateOptions: boolean;
|
|
32
23
|
requiredPermissions: (PermissionFlags | PermissionString)[];
|
|
33
24
|
allowExecuteInDM: boolean;
|
|
@@ -39,7 +30,7 @@ export declare class MessageCommandBuilder {
|
|
|
39
30
|
setAllowExecuteByBots(allowExecuteByBots: boolean): MessageCommandBuilder;
|
|
40
31
|
setDescription(description: string): MessageCommandBuilder;
|
|
41
32
|
setExecute(execute: (options: RecipleMessageCommandExecute) => void): MessageCommandBuilder;
|
|
42
|
-
addOption(option:
|
|
33
|
+
addOption(option: MessageCommandOptionBuilder | ((constructor: MessageCommandOptionBuilder) => MessageCommandOptionBuilder)): MessageCommandBuilder;
|
|
43
34
|
setValidateOptions(validateOptions: boolean): MessageCommandBuilder;
|
|
44
35
|
getCommandOptionValues(options: CommandMessage): undefined | MessageCommandValidatedOption[];
|
|
45
36
|
}
|
|
@@ -1,39 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MessageCommandBuilder =
|
|
4
|
-
|
|
5
|
-
constructor() {
|
|
6
|
-
this.name = '';
|
|
7
|
-
this.description = '';
|
|
8
|
-
this.required = true;
|
|
9
|
-
this.validate = () => true;
|
|
10
|
-
}
|
|
11
|
-
setName(name) {
|
|
12
|
-
if (typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
|
|
13
|
-
throw new Error('name must be a string and match the regex /^[\\w-]{1,32}$/.');
|
|
14
|
-
this.name = name;
|
|
15
|
-
return this;
|
|
16
|
-
}
|
|
17
|
-
setDescription(description) {
|
|
18
|
-
if (!description || typeof description !== 'string')
|
|
19
|
-
throw new Error('description must be a string.');
|
|
20
|
-
this.description = description;
|
|
21
|
-
return this;
|
|
22
|
-
}
|
|
23
|
-
setRequired(required) {
|
|
24
|
-
if (typeof required !== 'boolean')
|
|
25
|
-
throw new Error('required must be a boolean.');
|
|
26
|
-
this.required = required;
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
setValidator(validator) {
|
|
30
|
-
if (!validator || typeof validator !== 'function')
|
|
31
|
-
throw new Error('validator must be a function.');
|
|
32
|
-
this.validate = validator;
|
|
33
|
-
return this;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.MessageOption = MessageOption;
|
|
3
|
+
exports.MessageCommandBuilder = void 0;
|
|
4
|
+
const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
|
|
37
5
|
class MessageCommandBuilder {
|
|
38
6
|
constructor() {
|
|
39
7
|
this.builder = 'MESSAGE_COMMAND';
|
|
@@ -48,54 +16,54 @@ class MessageCommandBuilder {
|
|
|
48
16
|
}
|
|
49
17
|
setName(name) {
|
|
50
18
|
if (!name || typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
|
|
51
|
-
throw new
|
|
19
|
+
throw new TypeError('name must be a string and match the regex /^[\\w-]{1,32}$/');
|
|
52
20
|
this.name = name;
|
|
53
21
|
return this;
|
|
54
22
|
}
|
|
55
23
|
setRequiredPermissions(permissions) {
|
|
56
24
|
if (!permissions || !Array.isArray(permissions))
|
|
57
|
-
throw new
|
|
25
|
+
throw new TypeError('permissions must be an array.');
|
|
58
26
|
this.requiredPermissions = permissions;
|
|
59
27
|
return this;
|
|
60
28
|
}
|
|
61
29
|
setAllowExecuteInDM(allowExecuteInDM) {
|
|
62
30
|
if (typeof allowExecuteInDM !== 'boolean')
|
|
63
|
-
throw new
|
|
31
|
+
throw new TypeError('allowExecuteInDM must be a boolean.');
|
|
64
32
|
this.allowExecuteInDM = allowExecuteInDM;
|
|
65
33
|
return this;
|
|
66
34
|
}
|
|
67
35
|
setAllowExecuteByBots(allowExecuteByBots) {
|
|
68
36
|
if (typeof allowExecuteByBots !== 'boolean')
|
|
69
|
-
throw new
|
|
37
|
+
throw new TypeError('allowExecuteByBots must be a boolean.');
|
|
70
38
|
this.allowExecuteByBots = allowExecuteByBots;
|
|
71
39
|
return this;
|
|
72
40
|
}
|
|
73
41
|
setDescription(description) {
|
|
74
42
|
if (!description || typeof description !== 'string')
|
|
75
|
-
throw new
|
|
43
|
+
throw new TypeError('description must be a string.');
|
|
76
44
|
this.description = description;
|
|
77
45
|
return this;
|
|
78
46
|
}
|
|
79
47
|
setExecute(execute) {
|
|
80
48
|
if (!execute || typeof execute !== 'function')
|
|
81
|
-
throw new
|
|
49
|
+
throw new TypeError('execute must be a function.');
|
|
82
50
|
this.execute = execute;
|
|
83
51
|
return this;
|
|
84
52
|
}
|
|
85
53
|
addOption(option) {
|
|
86
54
|
if (!option)
|
|
87
|
-
throw new
|
|
88
|
-
option = typeof option === 'function' ? option(new
|
|
55
|
+
throw new TypeError('option must be a MessageOption.');
|
|
56
|
+
option = typeof option === 'function' ? option(new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder()) : option;
|
|
89
57
|
if (this.options.find(o => o.name === option.name))
|
|
90
|
-
throw new
|
|
58
|
+
throw new TypeError('option with name "' + option.name + '" already exists.');
|
|
91
59
|
if (this.options.length > 0 && !this.options[this.options.length - 1 < 0 ? 0 : this.options.length - 1].required && option.required)
|
|
92
|
-
throw new
|
|
60
|
+
throw new TypeError('All required options must be before optional options.');
|
|
93
61
|
this.options = [...this.options, option];
|
|
94
62
|
return this;
|
|
95
63
|
}
|
|
96
64
|
setValidateOptions(validateOptions) {
|
|
97
65
|
if (typeof validateOptions !== 'boolean')
|
|
98
|
-
throw new
|
|
66
|
+
throw new TypeError('validateOptions must be a boolean.');
|
|
99
67
|
this.validateOptions = validateOptions;
|
|
100
68
|
return this;
|
|
101
69
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class MessageCommandOptionBuilder {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
required: boolean;
|
|
5
|
+
validate: (value: string) => boolean;
|
|
6
|
+
setName(name: string): MessageCommandOptionBuilder;
|
|
7
|
+
setDescription(description: string): MessageCommandOptionBuilder;
|
|
8
|
+
setRequired(required: boolean): MessageCommandOptionBuilder;
|
|
9
|
+
setValidator(validator: (value: string) => boolean): MessageCommandOptionBuilder;
|
|
10
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageCommandOptionBuilder = void 0;
|
|
4
|
+
class MessageCommandOptionBuilder {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.name = '';
|
|
7
|
+
this.description = '';
|
|
8
|
+
this.required = true;
|
|
9
|
+
this.validate = () => true;
|
|
10
|
+
}
|
|
11
|
+
setName(name) {
|
|
12
|
+
if (typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
|
|
13
|
+
throw new TypeError('name must be a string and match the regex /^[\\w-]{1,32}$/.');
|
|
14
|
+
this.name = name;
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
setDescription(description) {
|
|
18
|
+
if (!description || typeof description !== 'string')
|
|
19
|
+
throw new TypeError('description must be a string.');
|
|
20
|
+
this.description = description;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
setRequired(required) {
|
|
24
|
+
if (typeof required !== 'boolean')
|
|
25
|
+
throw new TypeError('required must be a boolean.');
|
|
26
|
+
this.required = required;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
setValidator(validator) {
|
|
30
|
+
if (!validator || typeof validator !== 'function')
|
|
31
|
+
throw new TypeError('validator must be a function.');
|
|
32
|
+
this.validate = validator;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.MessageCommandOptionBuilder = MessageCommandOptionBuilder;
|
package/bin/reciple/modules.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export declare type loadedModules = {
|
|
|
9
9
|
export interface RecipleScript {
|
|
10
10
|
versions: string | string[];
|
|
11
11
|
commands?: (MessageCommandBuilder | InteractionCommandBuilder)[];
|
|
12
|
-
onLoad
|
|
13
|
-
onStart
|
|
12
|
+
onLoad?(reciple: RecipleClient): void | Promise<void>;
|
|
13
|
+
onStart(reciple: RecipleClient): boolean | Promise<boolean>;
|
|
14
14
|
}
|
|
15
15
|
export interface RecipleModule {
|
|
16
16
|
script: RecipleScript;
|
|
@@ -15,20 +15,19 @@ function registerInteractionCommands(client, cmds, overwriteGuilds) {
|
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
let commands = (_a = Object.values(cmds !== null && cmds !== void 0 ? cmds : client.commands.INTERACTION_COMMANDS).map(c => {
|
|
17
17
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
18
|
-
if (typeof c.toJSON
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
cmd.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return c.toJSON();
|
|
18
|
+
if (typeof c.toJSON == 'undefined')
|
|
19
|
+
return c;
|
|
20
|
+
const cmd = c;
|
|
21
|
+
if ((cmd === null || cmd === void 0 ? void 0 : cmd.builder) === 'INTERACTION_COMMAND' && ((_a = client.config) === null || _a === void 0 ? void 0 : _a.commands.interactionCommand.setRequiredPermissions)) {
|
|
22
|
+
const permissions = (_g = (((_c = (_b = client.config) === null || _b === void 0 ? void 0 : _b.permissions) === null || _c === void 0 ? void 0 : _c.interactionCommands.enabled) ?
|
|
23
|
+
(_f = (_e = (_d = client.config) === null || _d === void 0 ? void 0 : _d.permissions) === null || _e === void 0 ? void 0 : _e.interactionCommands.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())) === null || _f === void 0 ? void 0 : _f.permissions :
|
|
24
|
+
undefined)) !== null && _g !== void 0 ? _g : cmd.requiredPermissions;
|
|
25
|
+
cmd.setRequiredPermissions(permissions);
|
|
26
|
+
client.commands.INTERACTION_COMMANDS[cmd.name] = cmd;
|
|
27
|
+
client.logger.debug(`Set required permissions for ${cmd.name} to ${permissions.join(', ')}`);
|
|
28
|
+
return cmd.toJSON();
|
|
30
29
|
}
|
|
31
|
-
return c;
|
|
30
|
+
return c.toJSON();
|
|
32
31
|
})) !== null && _a !== void 0 ? _a : [];
|
|
33
32
|
if (!commands || !commands.length) {
|
|
34
33
|
client.logger.warn('No interaction commands found.');
|