reciple 5.3.0 → 5.4.0
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/index.d.ts +1 -0
- package/bin/index.js +1 -0
- package/bin/reciple/classes/RecipleClient.d.ts +15 -7
- package/bin/reciple/classes/RecipleClient.js +30 -29
- package/bin/reciple/classes/RecipleConfig.d.ts +2 -2
- package/bin/reciple/classes/RecipleConfig.js +6 -6
- package/bin/reciple/classes/builders/MessageCommandBuilder.d.ts +8 -2
- package/bin/reciple/classes/builders/MessageCommandBuilder.js +48 -1
- package/bin/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +3 -0
- package/bin/reciple/classes/builders/MessageCommandOptionBuilder.js +17 -1
- package/bin/reciple/classes/builders/SlashCommandBuilder.d.ts +13 -3
- package/bin/reciple/classes/builders/SlashCommandBuilder.js +157 -2
- package/bin/reciple/modules.d.ts +2 -2
- package/bin/reciple/modules.js +7 -2
- package/bin/reciple/types/builders.d.ts +127 -5
- package/bin/reciple/util.d.ts +1 -0
- package/bin/reciple/util.js +11 -0
- package/package.json +1 -1
package/bin/index.d.ts
CHANGED
package/bin/index.js
CHANGED
|
@@ -29,4 +29,5 @@ __exportStar(require("./reciple/logger"), exports);
|
|
|
29
29
|
__exportStar(require("./reciple/modules"), exports);
|
|
30
30
|
__exportStar(require("./reciple/permissions"), exports);
|
|
31
31
|
__exportStar(require("./reciple/registerApplicationCommands"), exports);
|
|
32
|
+
__exportStar(require("./reciple/util"), exports);
|
|
32
33
|
__exportStar(require("./reciple/version"), exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { MessageCommandBuilder, MessageCommandExecuteData } from './builders/MessageCommandBuilder';
|
|
2
|
-
import { SlashCommandBuilder, SlashCommandExecuteData } from './builders/SlashCommandBuilder';
|
|
1
|
+
import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandHaltData } from './builders/MessageCommandBuilder';
|
|
2
|
+
import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandHaltData } from './builders/SlashCommandBuilder';
|
|
3
|
+
import { AnyCommandBuilder, AnyCommandData, AnySlashCommandBuilder, CommandBuilderType } from '../types/builders';
|
|
3
4
|
import { ApplicationCommandBuilder } from '../registerApplicationCommands';
|
|
4
|
-
import { AnyCommandBuilder, AnySlashCommandBuilder, CommandBuilderType } from '../types/builders';
|
|
5
5
|
import { AnyCommandExecuteData, AnyCommandHaltData } from '../types/commands';
|
|
6
6
|
import { CommandCooldownManager } from './CommandCooldownManager';
|
|
7
7
|
import { RecipleClientAddModuleOptions } from '../types/paramOptions';
|
|
@@ -80,7 +80,7 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
|
|
|
80
80
|
* Add slash or message command to client
|
|
81
81
|
* @param command Slash/Message command builder
|
|
82
82
|
*/
|
|
83
|
-
addCommand(command: AnyCommandBuilder): RecipleClient<Ready>;
|
|
83
|
+
addCommand(command: AnyCommandData | AnyCommandBuilder): RecipleClient<Ready>;
|
|
84
84
|
/**
|
|
85
85
|
* Listed to command executions
|
|
86
86
|
*/
|
|
@@ -117,17 +117,25 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
|
|
|
117
117
|
* Emits the "recipleReplyError" event
|
|
118
118
|
* @param error Received Error
|
|
119
119
|
*/
|
|
120
|
-
|
|
120
|
+
protected _replyError(error: unknown): void;
|
|
121
121
|
/**
|
|
122
122
|
* Executes command halt function
|
|
123
123
|
* @param command Halted command's builder
|
|
124
124
|
* @param haltData Halted command's data
|
|
125
125
|
*/
|
|
126
|
-
|
|
126
|
+
protected _haltCommand(command: SlashCommandBuilder, haltData: SlashCommandHaltData): Promise<boolean>;
|
|
127
|
+
protected _haltCommand(command: MessageCommandBuilder, haltData: MessageCommandHaltData): Promise<boolean>;
|
|
128
|
+
/**
|
|
129
|
+
* Executes a command through a commandBuilder#execute method
|
|
130
|
+
* @param command Command builder
|
|
131
|
+
* @param executeData Command execute data
|
|
132
|
+
*/
|
|
133
|
+
protected _executeCommand(command: SlashCommandBuilder, executeData: SlashCommandExecuteData): Promise<SlashCommandExecuteData | void>;
|
|
134
|
+
protected _executeCommand(command: MessageCommandBuilder, executeData: MessageCommandExecuteData): Promise<MessageCommandExecuteData | void>;
|
|
127
135
|
/**
|
|
128
136
|
* Error message when a command fails to execute
|
|
129
137
|
* @param err Received error
|
|
130
138
|
* @param command Slash/Message command execute data
|
|
131
139
|
*/
|
|
132
|
-
|
|
140
|
+
protected _commandExecuteError(err: Error, command: AnyCommandExecuteData): Promise<void>;
|
|
133
141
|
}
|
|
@@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.RecipleClient = void 0;
|
|
16
16
|
const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
|
|
17
17
|
const SlashCommandBuilder_1 = require("./builders/SlashCommandBuilder");
|
|
18
|
-
const registerApplicationCommands_1 = require("../registerApplicationCommands");
|
|
19
18
|
const builders_1 = require("../types/builders");
|
|
19
|
+
const registerApplicationCommands_1 = require("../registerApplicationCommands");
|
|
20
20
|
const commands_1 = require("../types/commands");
|
|
21
21
|
const permissions_1 = require("../permissions");
|
|
22
22
|
const CommandCooldownManager_1 = require("./CommandCooldownManager");
|
|
@@ -26,9 +26,9 @@ const RecipleConfig_1 = require("./RecipleConfig");
|
|
|
26
26
|
const modules_1 = require("../modules");
|
|
27
27
|
const logger_1 = require("../logger");
|
|
28
28
|
const version_1 = require("../version");
|
|
29
|
-
const discord_js_1 = require("discord.js");
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
29
|
const flags_1 = require("../flags");
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
31
|
+
const discord_js_1 = require("discord.js");
|
|
32
32
|
class RecipleClient extends discord_js_1.Client {
|
|
33
33
|
/**
|
|
34
34
|
* @param options Client options
|
|
@@ -146,11 +146,11 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
146
146
|
*/
|
|
147
147
|
addCommand(command) {
|
|
148
148
|
var _a;
|
|
149
|
-
if (command.type === builders_1.CommandBuilderType.
|
|
150
|
-
this.commands.
|
|
149
|
+
if (command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
150
|
+
this.commands.slashCommands[command.name] = SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command);
|
|
151
151
|
}
|
|
152
|
-
else if (command.type === builders_1.CommandBuilderType.
|
|
153
|
-
this.commands.
|
|
152
|
+
else if (command.type === builders_1.CommandBuilderType.MessageCommand) {
|
|
153
|
+
this.commands.messageCommands[command.name] = MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command);
|
|
154
154
|
}
|
|
155
155
|
else if (this.isClientLogsEnabled()) {
|
|
156
156
|
this.logger.error(`Unknow command "${(_a = typeof command) !== null && _a !== void 0 ? _a : 'unknown'}".`);
|
|
@@ -213,17 +213,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
213
213
|
}
|
|
214
214
|
return;
|
|
215
215
|
}
|
|
216
|
-
|
|
217
|
-
yield Promise.resolve(command.execute(executeData))
|
|
218
|
-
.then(() => this.emit('recipleCommandExecute', executeData))
|
|
219
|
-
.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; }));
|
|
220
|
-
return executeData;
|
|
221
|
-
}
|
|
222
|
-
catch (err) {
|
|
223
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Error, error: err }))) {
|
|
224
|
-
this._commandExecuteError(err, executeData);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
216
|
+
return this._executeCommand(command, executeData);
|
|
227
217
|
}
|
|
228
218
|
else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
|
|
229
219
|
yield interaction.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
@@ -297,17 +287,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
297
287
|
}
|
|
298
288
|
return;
|
|
299
289
|
}
|
|
300
|
-
|
|
301
|
-
yield Promise.resolve(command.execute(executeData))
|
|
302
|
-
.then(() => this.emit('recipleCommandExecute', executeData))
|
|
303
|
-
.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; }));
|
|
304
|
-
return executeData;
|
|
305
|
-
}
|
|
306
|
-
catch (err) {
|
|
307
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Error, error: err }))) {
|
|
308
|
-
this._commandExecuteError(err, executeData);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
290
|
+
return this._executeCommand(command, executeData);
|
|
311
291
|
}
|
|
312
292
|
else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
|
|
313
293
|
message.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
@@ -370,6 +350,27 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
370
350
|
}
|
|
371
351
|
});
|
|
372
352
|
}
|
|
353
|
+
_executeCommand(command, executeData) {
|
|
354
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
355
|
+
try {
|
|
356
|
+
yield Promise.resolve(command.type === builders_1.CommandBuilderType.SlashCommand
|
|
357
|
+
? command.execute(executeData)
|
|
358
|
+
: command.execute(executeData))
|
|
359
|
+
.then(() => this.emit('recipleCommandExecute', executeData))
|
|
360
|
+
.catch((err) => __awaiter(this, void 0, void 0, function* () {
|
|
361
|
+
return (yield this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err }))
|
|
362
|
+
? this._commandExecuteError(err, executeData)
|
|
363
|
+
: void 0;
|
|
364
|
+
}));
|
|
365
|
+
return executeData;
|
|
366
|
+
}
|
|
367
|
+
catch (err) {
|
|
368
|
+
if (!(yield this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err }))) {
|
|
369
|
+
this._commandExecuteError(err, executeData);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
373
374
|
/**
|
|
374
375
|
* Error message when a command fails to execute
|
|
375
376
|
* @param err Received error
|
|
@@ -80,11 +80,11 @@ export declare class RecipleConfig {
|
|
|
80
80
|
/**
|
|
81
81
|
* Check if the config version is supported
|
|
82
82
|
*/
|
|
83
|
-
|
|
83
|
+
protected _isSupportedConfig(): boolean;
|
|
84
84
|
/**
|
|
85
85
|
* Ask for a token
|
|
86
86
|
*/
|
|
87
|
-
|
|
87
|
+
protected _askToken(): string | null;
|
|
88
88
|
/**
|
|
89
89
|
* Get default config
|
|
90
90
|
*/
|
|
@@ -39,7 +39,7 @@ class RecipleConfig {
|
|
|
39
39
|
throw new Error('Failed to create config file.');
|
|
40
40
|
this.config = yaml_1.default.parse(defaultConfig);
|
|
41
41
|
if (this.config && this.config.token === 'TOKEN') {
|
|
42
|
-
this.config.token = this.
|
|
42
|
+
this.config.token = this._askToken() || this.config.token;
|
|
43
43
|
(0, fs_1.writeFileSync)(this.configPath, (0, fallout_utility_1.replaceAll)(defaultConfig, ' TOKEN', ` ${this.config.token}`), 'utf-8');
|
|
44
44
|
}
|
|
45
45
|
return this;
|
|
@@ -48,7 +48,7 @@ class RecipleConfig {
|
|
|
48
48
|
throw new Error('Failed to read config file.');
|
|
49
49
|
const config = (0, fs_1.readFileSync)(this.configPath, 'utf-8');
|
|
50
50
|
this.config = yaml_1.default.parse(config);
|
|
51
|
-
if (!this.
|
|
51
|
+
if (!this._isSupportedConfig())
|
|
52
52
|
throw new Error('Unsupported config version. Your config version: ' + (((_a = this.config) === null || _a === void 0 ? void 0 : _a.version) || 'No version specified.') + ', Reciple version: ' + version_1.version);
|
|
53
53
|
return this;
|
|
54
54
|
}
|
|
@@ -69,24 +69,24 @@ class RecipleConfig {
|
|
|
69
69
|
var _a;
|
|
70
70
|
let token = flags_1.token || ((_a = this.config) === null || _a === void 0 ? void 0 : _a.token) || null;
|
|
71
71
|
if (!token)
|
|
72
|
-
return token || (askIfNull ? this.
|
|
72
|
+
return token || (askIfNull ? this._askToken() : null);
|
|
73
73
|
const envToken = token.toString().split(':');
|
|
74
74
|
if (envToken.length === 2 && envToken[0].toLocaleLowerCase() === 'env' && envToken[1]) {
|
|
75
75
|
token = process.env[envToken[1]] || null;
|
|
76
76
|
}
|
|
77
|
-
return token || (askIfNull ? this.
|
|
77
|
+
return token || (askIfNull ? this._askToken() : null);
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Check if the config version is supported
|
|
81
81
|
*/
|
|
82
|
-
|
|
82
|
+
_isSupportedConfig() {
|
|
83
83
|
var _a;
|
|
84
84
|
return (0, version_1.isSupportedVersion)(((_a = this.config) === null || _a === void 0 ? void 0 : _a.version) || '0.0.0', version_1.version);
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
87
|
* Ask for a token
|
|
88
88
|
*/
|
|
89
|
-
|
|
89
|
+
_askToken() {
|
|
90
90
|
return flags_1.token || (0, fallout_utility_1.input)({ text: 'Bot Token >>> ', echo: '*', repeatIfEmpty: true, sigint: true }) || null;
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CommandBuilderType, CommandHaltFunction, CommandExecuteFunction, SharedCommandBuilderProperties } from '../../types/builders';
|
|
2
|
-
import { BaseCommandExecuteData, CommandHaltData } from '../../types/commands';
|
|
1
|
+
import { CommandBuilderType, CommandHaltFunction, CommandExecuteFunction, SharedCommandBuilderProperties, MessageCommandData } from '../../types/builders';
|
|
3
2
|
import { Message, PermissionResolvable, RestOrArray } from 'discord.js';
|
|
3
|
+
import { BaseCommandExecuteData, CommandHaltData } from '../../types/commands';
|
|
4
4
|
import { MessageCommandOptionManager } from '../MessageCommandOptionManager';
|
|
5
5
|
import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
|
|
6
6
|
import { Command as CommandMessage } from 'fallout-utility';
|
|
@@ -52,6 +52,7 @@ export declare class MessageCommandBuilder implements SharedCommandBuilderProper
|
|
|
52
52
|
allowExecuteByBots: boolean;
|
|
53
53
|
halt?: MessageCommandHaltFunction;
|
|
54
54
|
execute: MessageCommandExecuteFunction;
|
|
55
|
+
constructor(data?: Partial<Omit<MessageCommandData, "type">>);
|
|
55
56
|
/**
|
|
56
57
|
* Sets the command name
|
|
57
58
|
* @param name Command name
|
|
@@ -92,6 +93,11 @@ export declare class MessageCommandBuilder implements SharedCommandBuilderProper
|
|
|
92
93
|
setRequiredMemberPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
93
94
|
setHalt(halt?: MessageCommandHaltFunction | null): this;
|
|
94
95
|
setExecute(execute: MessageCommandExecuteFunction): this;
|
|
96
|
+
/**
|
|
97
|
+
* Returns JSON object of this builder
|
|
98
|
+
*/
|
|
99
|
+
toJSON(): MessageCommandData;
|
|
100
|
+
static resolveMessageCommand(commandData: MessageCommandData | MessageCommandBuilder): MessageCommandBuilder;
|
|
95
101
|
/**
|
|
96
102
|
* Is a message command builder
|
|
97
103
|
*/
|
|
@@ -18,7 +18,7 @@ const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
|
|
|
18
18
|
* Reciple builder for message command
|
|
19
19
|
*/
|
|
20
20
|
class MessageCommandBuilder {
|
|
21
|
-
constructor() {
|
|
21
|
+
constructor(data) {
|
|
22
22
|
this.type = builders_1.CommandBuilderType.MessageCommand;
|
|
23
23
|
this.name = '';
|
|
24
24
|
this.description = '';
|
|
@@ -31,6 +31,30 @@ class MessageCommandBuilder {
|
|
|
31
31
|
this.allowExecuteInDM = true;
|
|
32
32
|
this.allowExecuteByBots = false;
|
|
33
33
|
this.execute = () => { };
|
|
34
|
+
if ((data === null || data === void 0 ? void 0 : data.name) !== undefined)
|
|
35
|
+
this.setName(data.name);
|
|
36
|
+
if ((data === null || data === void 0 ? void 0 : data.description) !== undefined)
|
|
37
|
+
this.setDescription(data.description);
|
|
38
|
+
if ((data === null || data === void 0 ? void 0 : data.cooldown) !== undefined)
|
|
39
|
+
this.setCooldown(Number(data === null || data === void 0 ? void 0 : data.cooldown));
|
|
40
|
+
if ((data === null || data === void 0 ? void 0 : data.requiredBotPermissions) !== undefined)
|
|
41
|
+
this.setRequiredBotPermissions(data.requiredBotPermissions);
|
|
42
|
+
if ((data === null || data === void 0 ? void 0 : data.requiredMemberPermissions) !== undefined)
|
|
43
|
+
this.setRequiredMemberPermissions(data.requiredMemberPermissions);
|
|
44
|
+
if ((data === null || data === void 0 ? void 0 : data.halt) !== undefined)
|
|
45
|
+
this.setHalt(this.halt);
|
|
46
|
+
if ((data === null || data === void 0 ? void 0 : data.execute) !== undefined)
|
|
47
|
+
this.setExecute(data.execute);
|
|
48
|
+
if ((data === null || data === void 0 ? void 0 : data.aliases) !== undefined)
|
|
49
|
+
this.addAliases(data.aliases);
|
|
50
|
+
if (data === null || data === void 0 ? void 0 : data.allowExecuteByBots)
|
|
51
|
+
this.setAllowExecuteByBots(true);
|
|
52
|
+
if (data === null || data === void 0 ? void 0 : data.allowExecuteInDM)
|
|
53
|
+
this.setAllowExecuteInDM(true);
|
|
54
|
+
if (data === null || data === void 0 ? void 0 : data.validateOptions)
|
|
55
|
+
this.setValidateOptions(true);
|
|
56
|
+
if ((data === null || data === void 0 ? void 0 : data.options) !== undefined)
|
|
57
|
+
this.options = data.options.map(o => o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o));
|
|
34
58
|
}
|
|
35
59
|
/**
|
|
36
60
|
* Sets the command name
|
|
@@ -134,6 +158,29 @@ class MessageCommandBuilder {
|
|
|
134
158
|
this.execute = execute;
|
|
135
159
|
return this;
|
|
136
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Returns JSON object of this builder
|
|
163
|
+
*/
|
|
164
|
+
toJSON() {
|
|
165
|
+
return {
|
|
166
|
+
type: this.type,
|
|
167
|
+
name: this.name,
|
|
168
|
+
description: this.description,
|
|
169
|
+
aliases: this.aliases,
|
|
170
|
+
cooldown: this.cooldown,
|
|
171
|
+
requiredBotPermissions: this.requiredBotPermissions,
|
|
172
|
+
requiredMemberPermissions: this.requiredMemberPermissions,
|
|
173
|
+
halt: this.halt,
|
|
174
|
+
execute: this.execute,
|
|
175
|
+
allowExecuteByBots: this.allowExecuteByBots,
|
|
176
|
+
allowExecuteInDM: this.allowExecuteInDM,
|
|
177
|
+
validateOptions: this.validateOptions,
|
|
178
|
+
options: this.options.map(o => o.toJSON()),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
static resolveMessageCommand(commandData) {
|
|
182
|
+
return this.isMessageCommandBuilder(commandData) ? commandData : new MessageCommandBuilder(commandData);
|
|
183
|
+
}
|
|
137
184
|
/**
|
|
138
185
|
* Is a message command builder
|
|
139
186
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MessageCommandOptionData } from '../../types/builders';
|
|
1
2
|
import { Awaitable } from 'discord.js';
|
|
2
3
|
/**
|
|
3
4
|
* Option builder for MessageCommandBuilder
|
|
@@ -7,6 +8,7 @@ export declare class MessageCommandOptionBuilder {
|
|
|
7
8
|
description: string;
|
|
8
9
|
required: boolean;
|
|
9
10
|
validator: (value: string) => Awaitable<boolean>;
|
|
11
|
+
constructor(data?: Partial<MessageCommandOptionData>);
|
|
10
12
|
/**
|
|
11
13
|
* Set command option name
|
|
12
14
|
* @param name Option name
|
|
@@ -27,4 +29,5 @@ export declare class MessageCommandOptionBuilder {
|
|
|
27
29
|
* @param validator Custom function to validate value given for this option
|
|
28
30
|
*/
|
|
29
31
|
setValidator(validator: (value: string) => Awaitable<boolean>): this;
|
|
32
|
+
toJSON(): MessageCommandOptionData;
|
|
30
33
|
}
|
|
@@ -5,11 +5,19 @@ exports.MessageCommandOptionBuilder = void 0;
|
|
|
5
5
|
* Option builder for MessageCommandBuilder
|
|
6
6
|
*/
|
|
7
7
|
class MessageCommandOptionBuilder {
|
|
8
|
-
constructor() {
|
|
8
|
+
constructor(data) {
|
|
9
9
|
this.name = '';
|
|
10
10
|
this.description = '';
|
|
11
11
|
this.required = false;
|
|
12
12
|
this.validator = () => true;
|
|
13
|
+
if ((data === null || data === void 0 ? void 0 : data.name) !== undefined)
|
|
14
|
+
this.setName(data.name);
|
|
15
|
+
if ((data === null || data === void 0 ? void 0 : data.description) !== undefined)
|
|
16
|
+
this.setDescription(data.description);
|
|
17
|
+
if ((data === null || data === void 0 ? void 0 : data.required) !== undefined)
|
|
18
|
+
this.setRequired(data.required);
|
|
19
|
+
if ((data === null || data === void 0 ? void 0 : data.validator) !== undefined)
|
|
20
|
+
this.setValidator(data.validator);
|
|
13
21
|
}
|
|
14
22
|
/**
|
|
15
23
|
* Set command option name
|
|
@@ -51,5 +59,13 @@ class MessageCommandOptionBuilder {
|
|
|
51
59
|
this.validator = validator;
|
|
52
60
|
return this;
|
|
53
61
|
}
|
|
62
|
+
toJSON() {
|
|
63
|
+
return {
|
|
64
|
+
name: this.name,
|
|
65
|
+
description: this.description,
|
|
66
|
+
required: this.required,
|
|
67
|
+
validator: this.validator,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
54
70
|
}
|
|
55
71
|
exports.MessageCommandOptionBuilder = MessageCommandOptionBuilder;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CommandBuilderType, CommandHaltFunction, CommandExecuteFunction, SharedCommandBuilderProperties, AnySlashCommandBuilder } from '../../types/builders';
|
|
1
|
+
import { CommandBuilderType, CommandHaltFunction, CommandExecuteFunction, SharedCommandBuilderProperties, AnySlashCommandBuilder, SlashCommandData, AnySlashCommandOptionData, AnySlashCommandOptionBuilder } from '../../types/builders';
|
|
2
2
|
import { BaseCommandExecuteData, CommandHaltData } from '../../types/commands';
|
|
3
|
-
import { ChatInputCommandInteraction, PermissionResolvable, RestOrArray, SlashCommandBuilder as DiscordJsSlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandBooleanOption, SlashCommandUserOption, SlashCommandChannelOption, SlashCommandRoleOption, SlashCommandAttachmentOption, SlashCommandMentionableOption, SlashCommandStringOption, SlashCommandIntegerOption, SlashCommandNumberOption } from 'discord.js';
|
|
3
|
+
import { ChatInputCommandInteraction, PermissionResolvable, RestOrArray, SlashCommandBuilder as DiscordJsSlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandBooleanOption, SlashCommandUserOption, SlashCommandChannelOption, SlashCommandRoleOption, SlashCommandAttachmentOption, SlashCommandMentionableOption, SlashCommandStringOption, SlashCommandIntegerOption, SlashCommandNumberOption, SharedSlashCommandOptions } from 'discord.js';
|
|
4
4
|
/**
|
|
5
5
|
* Execute data for slash command
|
|
6
6
|
*/
|
|
@@ -45,15 +45,25 @@ export declare class SlashCommandBuilder extends DiscordJsSlashCommandBuilder im
|
|
|
45
45
|
requiredMemberPermissions: PermissionResolvable[];
|
|
46
46
|
halt?: SlashCommandHaltFunction;
|
|
47
47
|
execute: SlashCommandExecuteFunction;
|
|
48
|
+
constructor(data?: Partial<Omit<SlashCommandData, "type">>);
|
|
48
49
|
setCooldown(cooldown: number): this;
|
|
49
50
|
setRequiredBotPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
50
51
|
setRequiredMemberPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
51
52
|
setHalt(halt?: SlashCommandHaltFunction | null): this;
|
|
52
53
|
setExecute(execute: SlashCommandExecuteFunction): this;
|
|
54
|
+
/**
|
|
55
|
+
* Add option builder to command builder
|
|
56
|
+
*/
|
|
57
|
+
static addOption(builder: SharedSlashCommandOptions | SlashCommandBuilder, option: AnySlashCommandOptionBuilder): SharedSlashCommandOptions;
|
|
58
|
+
/**
|
|
59
|
+
* Resolve option data
|
|
60
|
+
*/
|
|
61
|
+
static resolveOption<T extends AnySlashCommandOptionBuilder>(option: AnySlashCommandOptionData): T;
|
|
62
|
+
static resolveSlashCommand(commandData: SlashCommandData | AnySlashCommandBuilder): AnySlashCommandBuilder;
|
|
53
63
|
/**
|
|
54
64
|
* Is a slash command builder
|
|
55
65
|
*/
|
|
56
|
-
static isSlashCommandBuilder(builder: unknown): builder is
|
|
66
|
+
static isSlashCommandBuilder(builder: unknown): builder is AnySlashCommandBuilder;
|
|
57
67
|
/**
|
|
58
68
|
* Is a slash command execute data
|
|
59
69
|
*/
|
|
@@ -2,18 +2,48 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SlashCommandBuilder = void 0;
|
|
4
4
|
const builders_1 = require("../../types/builders");
|
|
5
|
+
const util_1 = require("../../util");
|
|
5
6
|
const discord_js_1 = require("discord.js");
|
|
6
7
|
/**
|
|
7
8
|
* Reciple builder for slash command
|
|
8
9
|
*/
|
|
9
10
|
class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(
|
|
11
|
+
constructor(data) {
|
|
12
|
+
super();
|
|
12
13
|
this.type = builders_1.CommandBuilderType.SlashCommand;
|
|
13
14
|
this.cooldown = 0;
|
|
14
15
|
this.requiredBotPermissions = [];
|
|
15
16
|
this.requiredMemberPermissions = [];
|
|
16
17
|
this.execute = () => { };
|
|
18
|
+
if ((data === null || data === void 0 ? void 0 : data.name) !== undefined)
|
|
19
|
+
this.setName(data.name);
|
|
20
|
+
if ((data === null || data === void 0 ? void 0 : data.description) !== undefined)
|
|
21
|
+
this.setDescription(data.description);
|
|
22
|
+
if ((data === null || data === void 0 ? void 0 : data.cooldown) !== undefined)
|
|
23
|
+
this.setCooldown(Number(data === null || data === void 0 ? void 0 : data.cooldown));
|
|
24
|
+
if ((data === null || data === void 0 ? void 0 : data.requiredBotPermissions) !== undefined)
|
|
25
|
+
this.setRequiredBotPermissions(data.requiredBotPermissions);
|
|
26
|
+
if ((data === null || data === void 0 ? void 0 : data.requiredMemberPermissions) !== undefined)
|
|
27
|
+
this.setRequiredMemberPermissions(data.requiredMemberPermissions);
|
|
28
|
+
if ((data === null || data === void 0 ? void 0 : data.halt) !== undefined)
|
|
29
|
+
this.setHalt(this.halt);
|
|
30
|
+
if ((data === null || data === void 0 ? void 0 : data.execute) !== undefined)
|
|
31
|
+
this.setExecute(data.execute);
|
|
32
|
+
if ((data === null || data === void 0 ? void 0 : data.nameLocalizations) !== undefined)
|
|
33
|
+
this.setNameLocalizations(data.nameLocalizations);
|
|
34
|
+
if ((data === null || data === void 0 ? void 0 : data.descriptionLocalizations) !== undefined)
|
|
35
|
+
this.setDescriptionLocalizations(data.descriptionLocalizations);
|
|
36
|
+
if ((data === null || data === void 0 ? void 0 : data.defaultMemberPermissions) !== undefined)
|
|
37
|
+
this.setDefaultMemberPermissions(data.defaultMemberPermissions);
|
|
38
|
+
if (data === null || data === void 0 ? void 0 : data.dmPermission)
|
|
39
|
+
this.setDMPermission(true);
|
|
40
|
+
if (data === null || data === void 0 ? void 0 : data.defaultPermission)
|
|
41
|
+
this.setDefaultPermission(true);
|
|
42
|
+
if (data === null || data === void 0 ? void 0 : data.options) {
|
|
43
|
+
for (const option of data.options) {
|
|
44
|
+
SlashCommandBuilder.addOption(this, (0, util_1.isClass)(option) ? option : SlashCommandBuilder.resolveOption(option));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
17
47
|
}
|
|
18
48
|
setCooldown(cooldown) {
|
|
19
49
|
this.cooldown = cooldown;
|
|
@@ -37,6 +67,131 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
37
67
|
this.execute = execute;
|
|
38
68
|
return this;
|
|
39
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Add option builder to command builder
|
|
72
|
+
*/
|
|
73
|
+
static addOption(builder, option) {
|
|
74
|
+
if (option instanceof discord_js_1.SlashCommandAttachmentOption) {
|
|
75
|
+
builder.addAttachmentOption(option);
|
|
76
|
+
}
|
|
77
|
+
else if (option instanceof discord_js_1.SlashCommandBooleanOption) {
|
|
78
|
+
builder.addBooleanOption(option);
|
|
79
|
+
}
|
|
80
|
+
else if (option instanceof discord_js_1.SlashCommandChannelOption) {
|
|
81
|
+
builder.addChannelOption(option);
|
|
82
|
+
}
|
|
83
|
+
else if (option instanceof discord_js_1.SlashCommandIntegerOption) {
|
|
84
|
+
builder.addIntegerOption(option);
|
|
85
|
+
}
|
|
86
|
+
else if (option instanceof discord_js_1.SlashCommandMentionableOption) {
|
|
87
|
+
builder.addMentionableOption(option);
|
|
88
|
+
}
|
|
89
|
+
else if (option instanceof discord_js_1.SlashCommandNumberOption) {
|
|
90
|
+
builder.addNumberOption(option);
|
|
91
|
+
}
|
|
92
|
+
else if (option instanceof discord_js_1.SlashCommandRoleOption) {
|
|
93
|
+
builder.addRoleOption(option);
|
|
94
|
+
}
|
|
95
|
+
else if (option instanceof discord_js_1.SlashCommandStringOption) {
|
|
96
|
+
builder.addStringOption(option);
|
|
97
|
+
}
|
|
98
|
+
else if (option instanceof discord_js_1.SlashCommandUserOption) {
|
|
99
|
+
builder.addUserOption(option);
|
|
100
|
+
}
|
|
101
|
+
else if (builder instanceof SlashCommandBuilder) {
|
|
102
|
+
if (option instanceof discord_js_1.SlashCommandSubcommandBuilder) {
|
|
103
|
+
builder.addSubcommand(option);
|
|
104
|
+
}
|
|
105
|
+
else if (option instanceof discord_js_1.SlashCommandSubcommandGroupBuilder) {
|
|
106
|
+
builder.addSubcommandGroup(option);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return builder;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Resolve option data
|
|
113
|
+
*/
|
|
114
|
+
static resolveOption(option) {
|
|
115
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
116
|
+
let builder;
|
|
117
|
+
switch (option.type) {
|
|
118
|
+
case discord_js_1.ApplicationCommandOptionType.Attachment:
|
|
119
|
+
builder = new discord_js_1.SlashCommandAttachmentOption();
|
|
120
|
+
break;
|
|
121
|
+
case discord_js_1.ApplicationCommandOptionType.Boolean:
|
|
122
|
+
builder = new discord_js_1.SlashCommandBooleanOption();
|
|
123
|
+
break;
|
|
124
|
+
case discord_js_1.ApplicationCommandOptionType.Channel:
|
|
125
|
+
builder = new discord_js_1.SlashCommandChannelOption()
|
|
126
|
+
.addChannelTypes(...((_a = option.channelTypes) !== null && _a !== void 0 ? _a : []));
|
|
127
|
+
break;
|
|
128
|
+
case discord_js_1.ApplicationCommandOptionType.Integer:
|
|
129
|
+
builder = new discord_js_1.SlashCommandIntegerOption()
|
|
130
|
+
.addChoices(...((_b = option.choices) !== null && _b !== void 0 ? _b : []))
|
|
131
|
+
.setAutocomplete(!!option.autocomplete);
|
|
132
|
+
if (option.maxValue)
|
|
133
|
+
builder.setMaxValue(option.maxValue);
|
|
134
|
+
if (option.minValue)
|
|
135
|
+
builder.setMinValue(option.minValue);
|
|
136
|
+
break;
|
|
137
|
+
case discord_js_1.ApplicationCommandOptionType.Mentionable:
|
|
138
|
+
builder = new discord_js_1.SlashCommandMentionableOption();
|
|
139
|
+
break;
|
|
140
|
+
case discord_js_1.ApplicationCommandOptionType.Number:
|
|
141
|
+
builder = new discord_js_1.SlashCommandNumberOption()
|
|
142
|
+
.addChoices(...((_c = option.choices) !== null && _c !== void 0 ? _c : []))
|
|
143
|
+
.setAutocomplete(!!option.autocomplete);
|
|
144
|
+
if (option.maxValue)
|
|
145
|
+
builder.setMaxValue(option.maxValue);
|
|
146
|
+
if (option.minValue)
|
|
147
|
+
builder.setMinValue(option.minValue);
|
|
148
|
+
break;
|
|
149
|
+
case discord_js_1.ApplicationCommandOptionType.Role:
|
|
150
|
+
builder = new discord_js_1.SlashCommandRoleOption();
|
|
151
|
+
break;
|
|
152
|
+
case discord_js_1.ApplicationCommandOptionType.String:
|
|
153
|
+
builder = new discord_js_1.SlashCommandStringOption()
|
|
154
|
+
.addChoices(...((_d = option.choices) !== null && _d !== void 0 ? _d : []))
|
|
155
|
+
.setAutocomplete(!!option.autocomplete);
|
|
156
|
+
if (option.maxLength)
|
|
157
|
+
builder.setMaxLength(option.maxLength);
|
|
158
|
+
if (option.minLength)
|
|
159
|
+
builder.setMinLength(option.minLength);
|
|
160
|
+
break;
|
|
161
|
+
case discord_js_1.ApplicationCommandOptionType.User:
|
|
162
|
+
builder = new discord_js_1.SlashCommandUserOption();
|
|
163
|
+
break;
|
|
164
|
+
case discord_js_1.ApplicationCommandOptionType.Subcommand:
|
|
165
|
+
builder = new discord_js_1.SlashCommandSubcommandBuilder();
|
|
166
|
+
for (const optionData of option.options) {
|
|
167
|
+
this.addOption(builder, this.resolveOption(optionData));
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
case discord_js_1.ApplicationCommandOptionType.SubcommandGroup:
|
|
171
|
+
builder = new discord_js_1.SlashCommandSubcommandGroupBuilder();
|
|
172
|
+
for (const subCommandData of option.options) {
|
|
173
|
+
builder.addSubcommand(subCommandData instanceof discord_js_1.SlashCommandSubcommandBuilder
|
|
174
|
+
? subCommandData
|
|
175
|
+
: this.resolveOption(subCommandData));
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
default:
|
|
179
|
+
throw new TypeError("Unknown option data");
|
|
180
|
+
}
|
|
181
|
+
if (!(builder instanceof discord_js_1.SlashCommandSubcommandBuilder) && !(builder instanceof discord_js_1.SlashCommandSubcommandGroupBuilder)
|
|
182
|
+
&&
|
|
183
|
+
option.type !== discord_js_1.ApplicationCommandOptionType.Subcommand && option.type !== discord_js_1.ApplicationCommandOptionType.SubcommandGroup) {
|
|
184
|
+
builder.setRequired((_e = option.required) !== null && _e !== void 0 ? _e : false);
|
|
185
|
+
}
|
|
186
|
+
return builder
|
|
187
|
+
.setName(option.name)
|
|
188
|
+
.setDescription(option.description)
|
|
189
|
+
.setNameLocalizations((_f = option.nameLocalizations) !== null && _f !== void 0 ? _f : null)
|
|
190
|
+
.setDescriptionLocalizations((_g = option.descriptionLocalizations) !== null && _g !== void 0 ? _g : null);
|
|
191
|
+
}
|
|
192
|
+
static resolveSlashCommand(commandData) {
|
|
193
|
+
return this.isSlashCommandBuilder(commandData) ? commandData : new SlashCommandBuilder(commandData);
|
|
194
|
+
}
|
|
40
195
|
/**
|
|
41
196
|
* Is a slash command builder
|
|
42
197
|
*/
|
package/bin/reciple/modules.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyCommandBuilder } from './types/builders';
|
|
1
|
+
import { AnyCommandBuilder, AnyCommandData } from './types/builders';
|
|
2
2
|
import { RecipleClient } from './classes/RecipleClient';
|
|
3
3
|
export declare type LoadedModules = {
|
|
4
4
|
commands: AnyCommandBuilder[];
|
|
@@ -9,7 +9,7 @@ export declare type LoadedModules = {
|
|
|
9
9
|
*/
|
|
10
10
|
export interface RecipleScript {
|
|
11
11
|
versions: string | string[];
|
|
12
|
-
commands?: AnyCommandBuilder[];
|
|
12
|
+
commands?: (AnyCommandBuilder | AnyCommandData)[];
|
|
13
13
|
onLoad?(client: RecipleClient): void | Promise<void>;
|
|
14
14
|
onStart(client: RecipleClient): boolean | Promise<boolean>;
|
|
15
15
|
}
|
package/bin/reciple/modules.js
CHANGED
|
@@ -14,6 +14,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.getModules = void 0;
|
|
16
16
|
const builders_1 = require("./types/builders");
|
|
17
|
+
const MessageCommandBuilder_1 = require("./classes/builders/MessageCommandBuilder");
|
|
18
|
+
const SlashCommandBuilder_1 = require("./classes/builders/SlashCommandBuilder");
|
|
17
19
|
const discord_js_1 = require("discord.js");
|
|
18
20
|
const version_1 = require("./version");
|
|
19
21
|
const fs_1 = require("fs");
|
|
@@ -52,8 +54,11 @@ function getModules(client, folder) {
|
|
|
52
54
|
throw new Error(script + ' onStart returned false or undefined.');
|
|
53
55
|
if (module_.commands) {
|
|
54
56
|
for (const command of module_.commands) {
|
|
55
|
-
if (command.type === builders_1.CommandBuilderType.MessageCommand
|
|
56
|
-
commands.push(command);
|
|
57
|
+
if (command.type === builders_1.CommandBuilderType.MessageCommand) {
|
|
58
|
+
commands.push(MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
|
|
59
|
+
}
|
|
60
|
+
else if (command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
61
|
+
commands.push(SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApplicationCommandOptionAllowedChannelTypes, ApplicationCommandOptionType, Awaitable, LocalizationMap, PermissionResolvable, RestOrArray, SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandChannelOption, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandRoleOption, SlashCommandStringOption, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandUserOption } from 'discord.js';
|
|
2
2
|
import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandExecuteFunction, SlashCommandHaltData, SlashCommandHaltFunction, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandsOnlyBuilder } from '../classes/builders/SlashCommandBuilder';
|
|
3
|
-
import {
|
|
3
|
+
import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandExecuteFunction, MessageCommandHaltData, MessageCommandHaltFunction } from '../classes/builders/MessageCommandBuilder';
|
|
4
|
+
import { MessageCommandOptionBuilder } from '../classes/builders/MessageCommandOptionBuilder';
|
|
4
5
|
/**
|
|
5
6
|
* Any command builders
|
|
6
7
|
*/
|
|
7
8
|
export declare type AnyCommandBuilder = AnySlashCommandBuilder | MessageCommandBuilder;
|
|
9
|
+
/**
|
|
10
|
+
* Any command data
|
|
11
|
+
*/
|
|
12
|
+
export declare type AnyCommandData = SlashCommandData | MessageCommandData;
|
|
8
13
|
/**
|
|
9
14
|
* Any slash command builders
|
|
10
15
|
*/
|
|
@@ -18,13 +23,33 @@ export declare type AnyCommandHaltFunction = SlashCommandHaltFunction | MessageC
|
|
|
18
23
|
*/
|
|
19
24
|
export declare type AnyCommandExecuteFunction = SlashCommandExecuteFunction | MessageCommandExecuteFunction;
|
|
20
25
|
/**
|
|
21
|
-
*
|
|
26
|
+
* Command halt function
|
|
22
27
|
*/
|
|
23
28
|
export declare type CommandHaltFunction<T extends CommandBuilderType> = (haltData: T extends CommandBuilderType.SlashCommand ? SlashCommandHaltData : MessageCommandHaltData) => Awaitable<boolean | null | undefined | void>;
|
|
24
29
|
/**
|
|
25
|
-
*
|
|
30
|
+
* Command execute function
|
|
26
31
|
*/
|
|
27
32
|
export declare type CommandExecuteFunction<T extends CommandBuilderType> = (executeData: T extends CommandBuilderType.SlashCommand ? SlashCommandExecuteData : MessageCommandExecuteData) => Awaitable<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Message command options resolvable
|
|
35
|
+
*/
|
|
36
|
+
export declare type MessageCommandOptionResolvable = MessageCommandOptionBuilder | MessageCommandOptionData;
|
|
37
|
+
/**
|
|
38
|
+
* Slash command options
|
|
39
|
+
*/
|
|
40
|
+
export declare type AnySlashCommandOptionData = AnySlashCommandOptionsOnlyOptionData | SlashCommandSubCommandGroupData | SlashCommandSubCommandData;
|
|
41
|
+
/**
|
|
42
|
+
* Slash command options builders
|
|
43
|
+
*/
|
|
44
|
+
export declare type AnySlashCommandOptionBuilder = AnySlashCommandOptionsOnlyOptionBuilder | SlashCommandSubcommandGroupBuilder | SlashCommandSubcommandBuilder;
|
|
45
|
+
/**
|
|
46
|
+
* Slash command options without sub commands
|
|
47
|
+
*/
|
|
48
|
+
export declare type AnySlashCommandOptionsOnlyOptionData = SlashCommandStringOptionData | SlashCommandNumberOptionData | SlashCommandIntegerOptionData | SlashCommandBooleanOptionData | SlashCommandMentionableOptionData | SlashCommandRoleOptionData | SlashCommandUserOptionData | SlashCommandAttachmentOptionData | SlashCommandChannelOptionData;
|
|
49
|
+
/**
|
|
50
|
+
* Slash command option builder without sub commands
|
|
51
|
+
*/
|
|
52
|
+
export declare type AnySlashCommandOptionsOnlyOptionBuilder = SlashCommandStringOption | SlashCommandNumberOption | SlashCommandIntegerOption | SlashCommandBooleanOption | SlashCommandMentionableOption | SlashCommandRoleOption | SlashCommandUserOption | SlashCommandAttachmentOption | SlashCommandChannelOption;
|
|
28
53
|
/**
|
|
29
54
|
* Types of command builders
|
|
30
55
|
*/
|
|
@@ -33,7 +58,7 @@ export declare enum CommandBuilderType {
|
|
|
33
58
|
SlashCommand = 1
|
|
34
59
|
}
|
|
35
60
|
/**
|
|
36
|
-
* Shared command builder methods
|
|
61
|
+
* Shared command builder methods and properties
|
|
37
62
|
*/
|
|
38
63
|
export interface SharedCommandBuilderProperties {
|
|
39
64
|
readonly type: CommandBuilderType;
|
|
@@ -69,3 +94,100 @@ export interface SharedCommandBuilderProperties {
|
|
|
69
94
|
*/
|
|
70
95
|
setExecute(execute: this["execute"]): this;
|
|
71
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Shared command name and description properties
|
|
99
|
+
*/
|
|
100
|
+
export interface SharedCommandDataProperties {
|
|
101
|
+
name: string;
|
|
102
|
+
description: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Slash command object data interface
|
|
106
|
+
*/
|
|
107
|
+
export interface SlashCommandData extends SharedCommandDataProperties, Partial<Omit<SharedCommandBuilderProperties, "setCooldown" | "setRequiredBotPermissions" | "setRequiredMemberPermissions" | "setHalt" | "setExecute" | "halt" | "execute">> {
|
|
108
|
+
type: CommandBuilderType.SlashCommand;
|
|
109
|
+
nameLocalizations?: LocalizationMap;
|
|
110
|
+
descriptionLocalizations?: LocalizationMap;
|
|
111
|
+
options: (AnySlashCommandOptionData | AnySlashCommandOptionBuilder)[];
|
|
112
|
+
/**
|
|
113
|
+
* @deprecated This property is deprecated and will be removed in the future.
|
|
114
|
+
*/
|
|
115
|
+
defaultPermission?: boolean;
|
|
116
|
+
defaultMemberPermissions?: string | null;
|
|
117
|
+
dmPermission?: boolean;
|
|
118
|
+
halt?: SlashCommandHaltFunction;
|
|
119
|
+
execute: SlashCommandExecuteFunction;
|
|
120
|
+
}
|
|
121
|
+
export interface SharedSlashCommandOptionData<V = string | number> extends SharedCommandDataProperties, Pick<SlashCommandData, "nameLocalizations" | "descriptionLocalizations"> {
|
|
122
|
+
choices?: {
|
|
123
|
+
name: string;
|
|
124
|
+
nameLocalizations?: LocalizationMap;
|
|
125
|
+
value: V;
|
|
126
|
+
}[];
|
|
127
|
+
autocomplete?: boolean;
|
|
128
|
+
required?: boolean;
|
|
129
|
+
}
|
|
130
|
+
export interface SlashCommandAttachmentOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
|
|
131
|
+
type: ApplicationCommandOptionType.Attachment;
|
|
132
|
+
}
|
|
133
|
+
export interface SlashCommandBooleanOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
|
|
134
|
+
type: ApplicationCommandOptionType.Boolean;
|
|
135
|
+
}
|
|
136
|
+
export interface SlashCommandChannelOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
|
|
137
|
+
type: ApplicationCommandOptionType.Channel;
|
|
138
|
+
channelTypes?: ApplicationCommandOptionAllowedChannelTypes[];
|
|
139
|
+
}
|
|
140
|
+
export interface SlashCommandIntegerOptionData extends SharedSlashCommandOptionData<number> {
|
|
141
|
+
type: ApplicationCommandOptionType.Integer;
|
|
142
|
+
minValue?: number;
|
|
143
|
+
maxValue?: number;
|
|
144
|
+
}
|
|
145
|
+
export interface SlashCommandMentionableOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
|
|
146
|
+
type: ApplicationCommandOptionType.Mentionable;
|
|
147
|
+
}
|
|
148
|
+
export interface SlashCommandNumberOptionData extends SharedSlashCommandOptionData<number> {
|
|
149
|
+
type: ApplicationCommandOptionType.Number;
|
|
150
|
+
minValue?: number;
|
|
151
|
+
maxValue?: number;
|
|
152
|
+
}
|
|
153
|
+
export interface SlashCommandRoleOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
|
|
154
|
+
type: ApplicationCommandOptionType.Role;
|
|
155
|
+
}
|
|
156
|
+
export interface SlashCommandStringOptionData extends SharedSlashCommandOptionData<string> {
|
|
157
|
+
type: ApplicationCommandOptionType.String;
|
|
158
|
+
minLength?: number;
|
|
159
|
+
maxLength?: number;
|
|
160
|
+
}
|
|
161
|
+
export interface SlashCommandUserOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
|
|
162
|
+
type: ApplicationCommandOptionType.User;
|
|
163
|
+
}
|
|
164
|
+
export interface SlashCommandSubCommandData extends SharedCommandDataProperties, Pick<SlashCommandData, "nameLocalizations" | "descriptionLocalizations"> {
|
|
165
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
166
|
+
options: (AnySlashCommandOptionsOnlyOptionData | AnySlashCommandOptionsOnlyOptionBuilder)[];
|
|
167
|
+
}
|
|
168
|
+
export interface SlashCommandSubCommandGroupData extends SharedCommandDataProperties, Pick<SlashCommandData, "nameLocalizations" | "descriptionLocalizations"> {
|
|
169
|
+
type: ApplicationCommandOptionType.SubcommandGroup;
|
|
170
|
+
options: (SlashCommandSubCommandData | SlashCommandSubcommandBuilder)[];
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Message command object data interface
|
|
174
|
+
*/
|
|
175
|
+
export interface MessageCommandData extends SharedCommandDataProperties, Partial<Omit<SharedCommandBuilderProperties, "setCooldown" | "setRequiredBotPermissions" | "setRequiredMemberPermissions" | "setHalt" | "setExecute" | "halt" | "execute">> {
|
|
176
|
+
type: CommandBuilderType.MessageCommand;
|
|
177
|
+
aliases?: string[];
|
|
178
|
+
validateOptions?: boolean;
|
|
179
|
+
allowExecuteInDM?: boolean;
|
|
180
|
+
allowExecuteByBots?: boolean;
|
|
181
|
+
halt?: MessageCommandHaltFunction;
|
|
182
|
+
execute: MessageCommandExecuteFunction;
|
|
183
|
+
options: MessageCommandOptionResolvable[];
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Message command option object data interface
|
|
187
|
+
*/
|
|
188
|
+
export interface MessageCommandOptionData extends SharedCommandDataProperties {
|
|
189
|
+
name: string;
|
|
190
|
+
description: string;
|
|
191
|
+
required: boolean;
|
|
192
|
+
validator: (value: string) => Awaitable<boolean>;
|
|
193
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isClass<T extends any>(object: any): object is T;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isClass = void 0;
|
|
4
|
+
function isClass(object) {
|
|
5
|
+
const isClassConstructor = object.constructor && object.constructor.toString().substring(0, 5) === 'class';
|
|
6
|
+
if (object.prototype === undefined)
|
|
7
|
+
return isClassConstructor;
|
|
8
|
+
const isPrototypeClassConstructor = object.prototype.constructor && object.prototype.constructor.toString && object.prototype.constructor.toString().substring(0, 5) === 'class';
|
|
9
|
+
return isClassConstructor || isPrototypeClassConstructor;
|
|
10
|
+
}
|
|
11
|
+
exports.isClass = isClass;
|