reciple 5.1.2 → 5.4.0-pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +28 -26
- 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 +7 -2
- package/bin/reciple/classes/builders/MessageCommandBuilder.js +49 -4
- 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 +11 -3
- package/bin/reciple/classes/builders/SlashCommandBuilder.js +155 -3
- package/bin/reciple/logger.js +4 -4
- package/bin/reciple/modules.d.ts +2 -2
- package/bin/reciple/modules.js +7 -2
- package/bin/reciple/types/builders.d.ts +130 -5
- package/bin/reciple/util.d.ts +1 -0
- package/bin/reciple/util.js +11 -0
- package/package.json +3 -3
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
3
|
import { ApplicationCommandBuilder } from '../registerApplicationCommands';
|
|
4
|
-
import { AnyCommandBuilder, AnySlashCommandBuilder, CommandBuilderType } from '../types/builders';
|
|
4
|
+
import { AnyCommandBuilder, AnyCommandData, 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
|
}
|
|
@@ -29,6 +29,7 @@ const version_1 = require("../version");
|
|
|
29
29
|
const discord_js_1 = require("discord.js");
|
|
30
30
|
const path_1 = __importDefault(require("path"));
|
|
31
31
|
const flags_1 = require("../flags");
|
|
32
|
+
const util_1 = require("../util");
|
|
32
33
|
class RecipleClient extends discord_js_1.Client {
|
|
33
34
|
/**
|
|
34
35
|
* @param options Client options
|
|
@@ -146,11 +147,11 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
146
147
|
*/
|
|
147
148
|
addCommand(command) {
|
|
148
149
|
var _a;
|
|
149
|
-
if (command.type === builders_1.CommandBuilderType.
|
|
150
|
-
this.commands.
|
|
150
|
+
if (command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
151
|
+
this.commands.slashCommands[command.name] = (0, util_1.isClass)(command) ? command : new SlashCommandBuilder_1.SlashCommandBuilder(command);
|
|
151
152
|
}
|
|
152
|
-
else if (command.type === builders_1.CommandBuilderType.
|
|
153
|
-
this.commands.
|
|
153
|
+
else if (command.type === builders_1.CommandBuilderType.MessageCommand) {
|
|
154
|
+
this.commands.messageCommands[command.name] = (0, util_1.isClass)(command) ? command : new MessageCommandBuilder_1.MessageCommandBuilder(command);
|
|
154
155
|
}
|
|
155
156
|
else if (this.isClientLogsEnabled()) {
|
|
156
157
|
this.logger.error(`Unknow command "${(_a = typeof command) !== null && _a !== void 0 ? _a : 'unknown'}".`);
|
|
@@ -213,17 +214,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
213
214
|
}
|
|
214
215
|
return;
|
|
215
216
|
}
|
|
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
|
-
}
|
|
217
|
+
return this._executeCommand(command, executeData);
|
|
227
218
|
}
|
|
228
219
|
else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
|
|
229
220
|
yield interaction.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
@@ -297,17 +288,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
297
288
|
}
|
|
298
289
|
return;
|
|
299
290
|
}
|
|
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
|
-
}
|
|
291
|
+
return this._executeCommand(command, executeData);
|
|
311
292
|
}
|
|
312
293
|
else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
|
|
313
294
|
message.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
@@ -370,6 +351,27 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
370
351
|
}
|
|
371
352
|
});
|
|
372
353
|
}
|
|
354
|
+
_executeCommand(command, executeData) {
|
|
355
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
try {
|
|
357
|
+
yield Promise.resolve(command.type === builders_1.CommandBuilderType.SlashCommand
|
|
358
|
+
? command.execute(executeData)
|
|
359
|
+
: command.execute(executeData))
|
|
360
|
+
.then(() => this.emit('recipleCommandExecute', executeData))
|
|
361
|
+
.catch((err) => __awaiter(this, void 0, void 0, function* () {
|
|
362
|
+
return (yield this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err }))
|
|
363
|
+
? this._commandExecuteError(err, executeData)
|
|
364
|
+
: void 0;
|
|
365
|
+
}));
|
|
366
|
+
return executeData;
|
|
367
|
+
}
|
|
368
|
+
catch (err) {
|
|
369
|
+
if (!(yield this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err }))) {
|
|
370
|
+
this._commandExecuteError(err, executeData);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
}
|
|
373
375
|
/**
|
|
374
376
|
* Error message when a command fails to execute
|
|
375
377
|
* @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,10 @@ 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;
|
|
95
100
|
/**
|
|
96
101
|
* Is a message command builder
|
|
97
102
|
*/
|
|
@@ -14,11 +14,12 @@ const builders_1 = require("../../types/builders");
|
|
|
14
14
|
const discord_js_1 = require("discord.js");
|
|
15
15
|
const MessageCommandOptionManager_1 = require("../MessageCommandOptionManager");
|
|
16
16
|
const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
|
|
17
|
+
const fallout_utility_1 = require("fallout-utility");
|
|
17
18
|
/**
|
|
18
19
|
* Reciple builder for message command
|
|
19
20
|
*/
|
|
20
21
|
class MessageCommandBuilder {
|
|
21
|
-
constructor() {
|
|
22
|
+
constructor(data) {
|
|
22
23
|
this.type = builders_1.CommandBuilderType.MessageCommand;
|
|
23
24
|
this.name = '';
|
|
24
25
|
this.description = '';
|
|
@@ -31,6 +32,30 @@ class MessageCommandBuilder {
|
|
|
31
32
|
this.allowExecuteInDM = true;
|
|
32
33
|
this.allowExecuteByBots = false;
|
|
33
34
|
this.execute = () => { };
|
|
35
|
+
if ((data === null || data === void 0 ? void 0 : data.name) !== undefined)
|
|
36
|
+
this.setName(data.name);
|
|
37
|
+
if ((data === null || data === void 0 ? void 0 : data.description) !== undefined)
|
|
38
|
+
this.setDescription(data.description);
|
|
39
|
+
if ((0, fallout_utility_1.isNumber)(data === null || data === void 0 ? void 0 : data.cooldown))
|
|
40
|
+
this.setCooldown(data === null || data === void 0 ? void 0 : data.cooldown);
|
|
41
|
+
if ((data === null || data === void 0 ? void 0 : data.requiredBotPermissions) !== undefined)
|
|
42
|
+
this.setRequiredBotPermissions(data.requiredBotPermissions);
|
|
43
|
+
if ((data === null || data === void 0 ? void 0 : data.requiredMemberPermissions) !== undefined)
|
|
44
|
+
this.setRequiredMemberPermissions(data.requiredMemberPermissions);
|
|
45
|
+
if ((data === null || data === void 0 ? void 0 : data.halt) !== undefined)
|
|
46
|
+
this.setHalt(this.halt);
|
|
47
|
+
if ((data === null || data === void 0 ? void 0 : data.execute) !== undefined)
|
|
48
|
+
this.setExecute(data.execute);
|
|
49
|
+
if ((data === null || data === void 0 ? void 0 : data.aliases) !== undefined)
|
|
50
|
+
this.addAliases(data.aliases);
|
|
51
|
+
if (data === null || data === void 0 ? void 0 : data.allowExecuteByBots)
|
|
52
|
+
this.setAllowExecuteByBots(true);
|
|
53
|
+
if (data === null || data === void 0 ? void 0 : data.allowExecuteInDM)
|
|
54
|
+
this.setAllowExecuteInDM(true);
|
|
55
|
+
if (data === null || data === void 0 ? void 0 : data.validateOptions)
|
|
56
|
+
this.setValidateOptions(true);
|
|
57
|
+
if ((data === null || data === void 0 ? void 0 : data.options) !== undefined)
|
|
58
|
+
this.options = data.options.map(o => o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o));
|
|
34
59
|
}
|
|
35
60
|
/**
|
|
36
61
|
* Sets the command name
|
|
@@ -60,11 +85,11 @@ class MessageCommandBuilder {
|
|
|
60
85
|
aliases = (0, discord_js_1.normalizeArray)(aliases);
|
|
61
86
|
if (!aliases.length)
|
|
62
87
|
throw new TypeError('Provide atleast one alias');
|
|
63
|
-
if (aliases.some(a => !a || typeof a !== 'string' ||
|
|
64
|
-
throw new TypeError('aliases must be strings and
|
|
88
|
+
if (aliases.some(a => !a || typeof a !== 'string' || a.match(/^\s+$/)))
|
|
89
|
+
throw new TypeError('aliases must be strings and should not contain whitespaces');
|
|
65
90
|
if (this.name && aliases.some(a => a == this.name))
|
|
66
91
|
throw new TypeError('alias cannot have same name to its real command name');
|
|
67
|
-
this.aliases = [...new Set(aliases)];
|
|
92
|
+
this.aliases = [...new Set(aliases.map(s => s.toLowerCase()))];
|
|
68
93
|
return this;
|
|
69
94
|
}
|
|
70
95
|
/**
|
|
@@ -134,6 +159,26 @@ class MessageCommandBuilder {
|
|
|
134
159
|
this.execute = execute;
|
|
135
160
|
return this;
|
|
136
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Returns JSON object of this builder
|
|
164
|
+
*/
|
|
165
|
+
toJSON() {
|
|
166
|
+
return {
|
|
167
|
+
type: this.type,
|
|
168
|
+
name: this.name,
|
|
169
|
+
description: this.description,
|
|
170
|
+
aliases: this.aliases,
|
|
171
|
+
cooldown: this.cooldown,
|
|
172
|
+
requiredBotPermissions: this.requiredBotPermissions,
|
|
173
|
+
requiredMemberPermissions: this.requiredMemberPermissions,
|
|
174
|
+
halt: this.halt,
|
|
175
|
+
execute: this.execute,
|
|
176
|
+
allowExecuteByBots: this.allowExecuteByBots,
|
|
177
|
+
allowExecuteInDM: this.allowExecuteInDM,
|
|
178
|
+
validateOptions: this.validateOptions,
|
|
179
|
+
options: this.options.map(o => o.toJSON()),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
137
182
|
/**
|
|
138
183
|
* Is a message command builder
|
|
139
184
|
*/
|
|
@@ -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
|
*/
|
|
@@ -43,14 +43,22 @@ export declare class SlashCommandBuilder extends DiscordJsSlashCommandBuilder im
|
|
|
43
43
|
cooldown: number;
|
|
44
44
|
requiredBotPermissions: PermissionResolvable[];
|
|
45
45
|
requiredMemberPermissions: PermissionResolvable[];
|
|
46
|
-
allowExecuteInDM: boolean;
|
|
47
46
|
halt?: SlashCommandHaltFunction;
|
|
48
47
|
execute: SlashCommandExecuteFunction;
|
|
48
|
+
constructor(data?: Partial<Omit<SlashCommandData, "type">>);
|
|
49
49
|
setCooldown(cooldown: number): this;
|
|
50
50
|
setRequiredBotPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
51
51
|
setRequiredMemberPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
52
52
|
setHalt(halt?: SlashCommandHaltFunction | null): this;
|
|
53
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;
|
|
54
62
|
/**
|
|
55
63
|
* Is a slash command builder
|
|
56
64
|
*/
|
|
@@ -3,18 +3,48 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SlashCommandBuilder = void 0;
|
|
4
4
|
const builders_1 = require("../../types/builders");
|
|
5
5
|
const discord_js_1 = require("discord.js");
|
|
6
|
+
const fallout_utility_1 = require("fallout-utility");
|
|
7
|
+
const util_1 = require("../../util");
|
|
6
8
|
/**
|
|
7
9
|
* Reciple builder for slash command
|
|
8
10
|
*/
|
|
9
11
|
class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(
|
|
12
|
+
constructor(data) {
|
|
13
|
+
super();
|
|
12
14
|
this.type = builders_1.CommandBuilderType.SlashCommand;
|
|
13
15
|
this.cooldown = 0;
|
|
14
16
|
this.requiredBotPermissions = [];
|
|
15
17
|
this.requiredMemberPermissions = [];
|
|
16
|
-
this.allowExecuteInDM = true;
|
|
17
18
|
this.execute = () => { };
|
|
19
|
+
if ((data === null || data === void 0 ? void 0 : data.name) !== undefined)
|
|
20
|
+
this.setName(data.name);
|
|
21
|
+
if ((data === null || data === void 0 ? void 0 : data.description) !== undefined)
|
|
22
|
+
this.setDescription(data.description);
|
|
23
|
+
if ((0, fallout_utility_1.isNumber)(data === null || data === void 0 ? void 0 : data.cooldown))
|
|
24
|
+
this.setCooldown(data === null || data === void 0 ? void 0 : data.cooldown);
|
|
25
|
+
if ((data === null || data === void 0 ? void 0 : data.requiredBotPermissions) !== undefined)
|
|
26
|
+
this.setRequiredBotPermissions(data.requiredBotPermissions);
|
|
27
|
+
if ((data === null || data === void 0 ? void 0 : data.requiredMemberPermissions) !== undefined)
|
|
28
|
+
this.setRequiredMemberPermissions(data.requiredMemberPermissions);
|
|
29
|
+
if ((data === null || data === void 0 ? void 0 : data.halt) !== undefined)
|
|
30
|
+
this.setHalt(this.halt);
|
|
31
|
+
if ((data === null || data === void 0 ? void 0 : data.execute) !== undefined)
|
|
32
|
+
this.setExecute(data.execute);
|
|
33
|
+
if ((data === null || data === void 0 ? void 0 : data.nameLocalizations) !== undefined)
|
|
34
|
+
this.setNameLocalizations(data.nameLocalizations);
|
|
35
|
+
if ((data === null || data === void 0 ? void 0 : data.descriptionLocalizations) !== undefined)
|
|
36
|
+
this.setDescriptionLocalizations(data.descriptionLocalizations);
|
|
37
|
+
if ((data === null || data === void 0 ? void 0 : data.defaultMemberPermissions) !== undefined)
|
|
38
|
+
this.setDefaultMemberPermissions(data.defaultMemberPermissions);
|
|
39
|
+
if (data === null || data === void 0 ? void 0 : data.dmPermission)
|
|
40
|
+
this.setDMPermission(true);
|
|
41
|
+
if (data === null || data === void 0 ? void 0 : data.defaultPermission)
|
|
42
|
+
this.setDefaultPermission(true);
|
|
43
|
+
if (data === null || data === void 0 ? void 0 : data.options) {
|
|
44
|
+
for (const option of data.options) {
|
|
45
|
+
SlashCommandBuilder.addOption(this, (0, util_1.isClass)(option) ? option : SlashCommandBuilder.resolveOption(option));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
18
48
|
}
|
|
19
49
|
setCooldown(cooldown) {
|
|
20
50
|
this.cooldown = cooldown;
|
|
@@ -38,6 +68,128 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
38
68
|
this.execute = execute;
|
|
39
69
|
return this;
|
|
40
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Add option builder to command builder
|
|
73
|
+
*/
|
|
74
|
+
static addOption(builder, option) {
|
|
75
|
+
if (option instanceof discord_js_1.SlashCommandStringOption) {
|
|
76
|
+
builder.addStringOption(option);
|
|
77
|
+
}
|
|
78
|
+
else if (option instanceof discord_js_1.SlashCommandNumberOption) {
|
|
79
|
+
builder.addNumberOption(option);
|
|
80
|
+
}
|
|
81
|
+
else if (option instanceof discord_js_1.SlashCommandIntegerOption) {
|
|
82
|
+
builder.addIntegerOption(option);
|
|
83
|
+
}
|
|
84
|
+
else if (option instanceof discord_js_1.SlashCommandBooleanOption) {
|
|
85
|
+
builder.addBooleanOption(option);
|
|
86
|
+
}
|
|
87
|
+
else if (option instanceof discord_js_1.SlashCommandChannelOption) {
|
|
88
|
+
builder.addChannelOption(option);
|
|
89
|
+
}
|
|
90
|
+
else if (option instanceof discord_js_1.SlashCommandMentionableOption) {
|
|
91
|
+
builder.addMentionableOption(option);
|
|
92
|
+
}
|
|
93
|
+
else if (option instanceof discord_js_1.SlashCommandUserOption) {
|
|
94
|
+
builder.addUserOption(option);
|
|
95
|
+
}
|
|
96
|
+
else if (option instanceof discord_js_1.SlashCommandRoleOption) {
|
|
97
|
+
builder.addRoleOption(option);
|
|
98
|
+
}
|
|
99
|
+
else if (option instanceof discord_js_1.SlashCommandAttachmentOption) {
|
|
100
|
+
builder.addAttachmentOption(option);
|
|
101
|
+
}
|
|
102
|
+
else if (builder instanceof SlashCommandBuilder) {
|
|
103
|
+
if (option instanceof discord_js_1.SlashCommandSubcommandBuilder) {
|
|
104
|
+
builder.addSubcommand(option);
|
|
105
|
+
}
|
|
106
|
+
else if (option instanceof discord_js_1.SlashCommandSubcommandGroupBuilder) {
|
|
107
|
+
builder.addSubcommandGroup(option);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return builder;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Resolve option data
|
|
114
|
+
*/
|
|
115
|
+
static resolveOption(option) {
|
|
116
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
117
|
+
let builder;
|
|
118
|
+
switch (option.type) {
|
|
119
|
+
case discord_js_1.ApplicationCommandOptionType.Attachment:
|
|
120
|
+
builder = new discord_js_1.SlashCommandAttachmentOption();
|
|
121
|
+
break;
|
|
122
|
+
case discord_js_1.ApplicationCommandOptionType.Boolean:
|
|
123
|
+
builder = new discord_js_1.SlashCommandBooleanOption();
|
|
124
|
+
break;
|
|
125
|
+
case discord_js_1.ApplicationCommandOptionType.Channel:
|
|
126
|
+
builder = new discord_js_1.SlashCommandChannelOption()
|
|
127
|
+
.addChannelTypes(...((_a = option.channelTypes) !== null && _a !== void 0 ? _a : []));
|
|
128
|
+
break;
|
|
129
|
+
case discord_js_1.ApplicationCommandOptionType.Integer:
|
|
130
|
+
builder = new discord_js_1.SlashCommandIntegerOption()
|
|
131
|
+
.addChoices(...((_b = option.choices) !== null && _b !== void 0 ? _b : []))
|
|
132
|
+
.setAutocomplete(!!option.autocomplete);
|
|
133
|
+
if (option.maxValue)
|
|
134
|
+
builder.setMaxValue(option.maxValue);
|
|
135
|
+
if (option.minValue)
|
|
136
|
+
builder.setMinValue(option.minValue);
|
|
137
|
+
break;
|
|
138
|
+
case discord_js_1.ApplicationCommandOptionType.Mentionable:
|
|
139
|
+
builder = new discord_js_1.SlashCommandMentionableOption();
|
|
140
|
+
break;
|
|
141
|
+
case discord_js_1.ApplicationCommandOptionType.Number:
|
|
142
|
+
builder = new discord_js_1.SlashCommandNumberOption()
|
|
143
|
+
.addChoices(...((_c = option.choices) !== null && _c !== void 0 ? _c : []))
|
|
144
|
+
.setAutocomplete(!!option.autocomplete);
|
|
145
|
+
if (option.maxValue)
|
|
146
|
+
builder.setMaxValue(option.maxValue);
|
|
147
|
+
if (option.minValue)
|
|
148
|
+
builder.setMinValue(option.minValue);
|
|
149
|
+
break;
|
|
150
|
+
case discord_js_1.ApplicationCommandOptionType.Role:
|
|
151
|
+
builder = new discord_js_1.SlashCommandRoleOption();
|
|
152
|
+
break;
|
|
153
|
+
case discord_js_1.ApplicationCommandOptionType.String:
|
|
154
|
+
builder = new discord_js_1.SlashCommandStringOption()
|
|
155
|
+
.addChoices(...((_d = option.choices) !== null && _d !== void 0 ? _d : []))
|
|
156
|
+
.setAutocomplete(!!option.autocomplete);
|
|
157
|
+
if (option.maxLength)
|
|
158
|
+
builder.setMaxLength(option.maxLength);
|
|
159
|
+
if (option.minLength)
|
|
160
|
+
builder.setMinLength(option.minLength);
|
|
161
|
+
break;
|
|
162
|
+
case discord_js_1.ApplicationCommandOptionType.User:
|
|
163
|
+
builder = new discord_js_1.SlashCommandUserOption();
|
|
164
|
+
break;
|
|
165
|
+
case discord_js_1.ApplicationCommandOptionType.Subcommand:
|
|
166
|
+
builder = new discord_js_1.SlashCommandSubcommandBuilder();
|
|
167
|
+
for (const optionData of option.options) {
|
|
168
|
+
this.addOption(builder, this.resolveOption(optionData));
|
|
169
|
+
}
|
|
170
|
+
break;
|
|
171
|
+
case discord_js_1.ApplicationCommandOptionType.SubcommandGroup:
|
|
172
|
+
builder = new discord_js_1.SlashCommandSubcommandGroupBuilder();
|
|
173
|
+
for (const subCommandData of option.options) {
|
|
174
|
+
builder.addSubcommand(subCommandData instanceof discord_js_1.SlashCommandSubcommandBuilder
|
|
175
|
+
? subCommandData
|
|
176
|
+
: this.resolveOption(subCommandData));
|
|
177
|
+
}
|
|
178
|
+
break;
|
|
179
|
+
default:
|
|
180
|
+
throw new TypeError("Unknown option data");
|
|
181
|
+
}
|
|
182
|
+
if (!(builder instanceof discord_js_1.SlashCommandSubcommandBuilder) && !(builder instanceof discord_js_1.SlashCommandSubcommandGroupBuilder)
|
|
183
|
+
&&
|
|
184
|
+
option.type !== discord_js_1.ApplicationCommandOptionType.Subcommand && option.type !== discord_js_1.ApplicationCommandOptionType.SubcommandGroup) {
|
|
185
|
+
builder.setRequired((_e = option.required) !== null && _e !== void 0 ? _e : false);
|
|
186
|
+
}
|
|
187
|
+
return builder
|
|
188
|
+
.setName(option.name)
|
|
189
|
+
.setDescription(option.description)
|
|
190
|
+
.setNameLocalizations((_f = option.nameLocalizations) !== null && _f !== void 0 ? _f : null)
|
|
191
|
+
.setDescriptionLocalizations((_g = option.descriptionLocalizations) !== null && _g !== void 0 ? _g : null);
|
|
192
|
+
}
|
|
41
193
|
/**
|
|
42
194
|
* Is a slash command builder
|
|
43
195
|
*/
|
package/bin/reciple/logger.js
CHANGED
|
@@ -20,10 +20,10 @@ function createLogger(stringifyJSON, debugmode = false, colorizeMessage = true)
|
|
|
20
20
|
enableDebugMode: (_a = flags_1.flags.debugmode) !== null && _a !== void 0 ? _a : debugmode,
|
|
21
21
|
loggerName: 'Main',
|
|
22
22
|
prefixes: {
|
|
23
|
-
[fallout_utility_1.LogLevels.INFO]: (name) => `[${new Date().toLocaleTimeString()}][${(name ? name + "/" : '') + "INFO"}]`,
|
|
24
|
-
[fallout_utility_1.LogLevels.WARN]: (name) => `[${chalk_1.default.yellow(new Date().toLocaleTimeString())}][${chalk_1.default.yellow((name ? name + "/" : '') + "WARN")}]`,
|
|
25
|
-
[fallout_utility_1.LogLevels.ERROR]: (name) => `[${chalk_1.default.red(new Date().toLocaleTimeString())}][${chalk_1.default.red((name ? name + "/" : '') + "ERROR")}]`,
|
|
26
|
-
[fallout_utility_1.LogLevels.DEBUG]: (name) => `[${chalk_1.default.blue(new Date().toLocaleTimeString())}][${chalk_1.default.blue((name ? name + "/" : '') + "DEBUG")}]`
|
|
23
|
+
[fallout_utility_1.LogLevels.INFO]: (name) => `[${new Date().toLocaleTimeString(undefined, { hour12: false })}][${(name ? name + "/" : '') + "INFO"}]`,
|
|
24
|
+
[fallout_utility_1.LogLevels.WARN]: (name) => `[${chalk_1.default.yellow(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.yellow((name ? name + "/" : '') + "WARN")}]`,
|
|
25
|
+
[fallout_utility_1.LogLevels.ERROR]: (name) => `[${chalk_1.default.red(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.red((name ? name + "/" : '') + "ERROR")}]`,
|
|
26
|
+
[fallout_utility_1.LogLevels.DEBUG]: (name) => `[${chalk_1.default.blue(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.blue((name ? name + "/" : '') + "DEBUG")}]`
|
|
27
27
|
},
|
|
28
28
|
colorMessages: {
|
|
29
29
|
[fallout_utility_1.LogLevels.INFO]: (message) => message,
|
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
|
@@ -20,6 +20,8 @@ const fs_1 = require("fs");
|
|
|
20
20
|
const wildcard_match_1 = __importDefault(require("wildcard-match"));
|
|
21
21
|
const flags_1 = require("./flags");
|
|
22
22
|
const path_1 = __importDefault(require("path"));
|
|
23
|
+
const MessageCommandBuilder_1 = require("./classes/builders/MessageCommandBuilder");
|
|
24
|
+
const SlashCommandBuilder_1 = require("./classes/builders/SlashCommandBuilder");
|
|
23
25
|
/**
|
|
24
26
|
* Load modules from folder
|
|
25
27
|
* @param client Reciple client
|
|
@@ -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.isMessageCommandBuilder(command) ? command : new MessageCommandBuilder_1.MessageCommandBuilder(command));
|
|
59
|
+
}
|
|
60
|
+
else if (command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
61
|
+
commands.push(SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandBuilder(command) ? command : new SlashCommandBuilder_1.SlashCommandBuilder(command));
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandExecuteFunction, MessageCommandHaltData, MessageCommandHaltFunction } from '../classes/builders/MessageCommandBuilder';
|
|
2
2
|
import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandExecuteFunction, SlashCommandHaltData, SlashCommandHaltFunction, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandsOnlyBuilder } from '../classes/builders/SlashCommandBuilder';
|
|
3
|
-
import { Awaitable, PermissionResolvable, RestOrArray } from 'discord.js';
|
|
3
|
+
import { ApplicationCommandOptionAllowedChannelTypes, ApplicationCommandOptionType, Awaitable, LocalizationMap, PermissionResolvable, RestOrArray, SlashCommandAttachmentOption, SlashCommandBooleanOption, SlashCommandChannelOption, SlashCommandIntegerOption, SlashCommandMentionableOption, SlashCommandNumberOption, SlashCommandRoleOption, SlashCommandStringOption, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandUserOption } from 'discord.js';
|
|
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,14 +58,13 @@ 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;
|
|
40
65
|
cooldown: number;
|
|
41
66
|
requiredBotPermissions: PermissionResolvable[];
|
|
42
67
|
requiredMemberPermissions: PermissionResolvable[];
|
|
43
|
-
allowExecuteInDM: boolean;
|
|
44
68
|
halt?: AnyCommandHaltFunction;
|
|
45
69
|
execute: AnyCommandExecuteFunction;
|
|
46
70
|
/**
|
|
@@ -70,3 +94,104 @@ export interface SharedCommandBuilderProperties {
|
|
|
70
94
|
*/
|
|
71
95
|
setExecute(execute: this["execute"]): this;
|
|
72
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, 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
|
+
/**
|
|
123
|
+
* Option choices
|
|
124
|
+
*/
|
|
125
|
+
choices?: {
|
|
126
|
+
name: string;
|
|
127
|
+
nameLocalizations?: LocalizationMap;
|
|
128
|
+
value: V;
|
|
129
|
+
}[];
|
|
130
|
+
/**
|
|
131
|
+
* Enable autocomplete
|
|
132
|
+
*/
|
|
133
|
+
autocomplete?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Is required
|
|
136
|
+
* @default false
|
|
137
|
+
*/
|
|
138
|
+
required?: boolean;
|
|
139
|
+
}
|
|
140
|
+
export interface SlashCommandStringOptionData extends SharedSlashCommandOptionData<string> {
|
|
141
|
+
type: ApplicationCommandOptionType.String;
|
|
142
|
+
minLength?: number;
|
|
143
|
+
maxLength?: number;
|
|
144
|
+
}
|
|
145
|
+
export interface SlashCommandNumberOptionData extends SharedSlashCommandOptionData<number> {
|
|
146
|
+
type: ApplicationCommandOptionType.Number;
|
|
147
|
+
minValue?: number;
|
|
148
|
+
maxValue?: number;
|
|
149
|
+
}
|
|
150
|
+
export interface SlashCommandIntegerOptionData extends SharedSlashCommandOptionData<number> {
|
|
151
|
+
type: ApplicationCommandOptionType.Integer;
|
|
152
|
+
minValue?: number;
|
|
153
|
+
maxValue?: number;
|
|
154
|
+
}
|
|
155
|
+
export interface SlashCommandBooleanOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
|
|
156
|
+
type: ApplicationCommandOptionType.Boolean;
|
|
157
|
+
}
|
|
158
|
+
export interface SlashCommandMentionableOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
|
|
159
|
+
type: ApplicationCommandOptionType.Mentionable;
|
|
160
|
+
}
|
|
161
|
+
export interface SlashCommandRoleOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
|
|
162
|
+
type: ApplicationCommandOptionType.Role;
|
|
163
|
+
}
|
|
164
|
+
export interface SlashCommandUserOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
|
|
165
|
+
type: ApplicationCommandOptionType.User;
|
|
166
|
+
}
|
|
167
|
+
export interface SlashCommandAttachmentOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
|
|
168
|
+
type: ApplicationCommandOptionType.Attachment;
|
|
169
|
+
}
|
|
170
|
+
export interface SlashCommandChannelOptionData extends Omit<SharedSlashCommandOptionData, "choices" | "autocomplete"> {
|
|
171
|
+
type: ApplicationCommandOptionType.Channel;
|
|
172
|
+
channelTypes?: ApplicationCommandOptionAllowedChannelTypes[];
|
|
173
|
+
}
|
|
174
|
+
export interface SlashCommandSubCommandGroupData extends SharedCommandDataProperties, Pick<SlashCommandData, "nameLocalizations" | "descriptionLocalizations"> {
|
|
175
|
+
type: ApplicationCommandOptionType.SubcommandGroup;
|
|
176
|
+
options: (SlashCommandSubCommandData | SlashCommandSubcommandBuilder)[];
|
|
177
|
+
}
|
|
178
|
+
export interface SlashCommandSubCommandData extends SharedCommandDataProperties, Pick<SlashCommandData, "nameLocalizations" | "descriptionLocalizations"> {
|
|
179
|
+
type: ApplicationCommandOptionType.Subcommand;
|
|
180
|
+
options: (AnySlashCommandOptionsOnlyOptionData | AnySlashCommandOptionsOnlyOptionBuilder)[];
|
|
181
|
+
}
|
|
182
|
+
export interface MessageCommandData extends SharedCommandDataProperties, Omit<SharedCommandBuilderProperties, "setCooldown" | "setRequiredBotPermissions" | "setRequiredMemberPermissions" | "setHalt" | "setExecute" | "halt" | "execute"> {
|
|
183
|
+
type: CommandBuilderType.MessageCommand;
|
|
184
|
+
aliases: string[];
|
|
185
|
+
validateOptions: boolean;
|
|
186
|
+
allowExecuteInDM: boolean;
|
|
187
|
+
allowExecuteByBots: boolean;
|
|
188
|
+
halt?: MessageCommandHaltFunction;
|
|
189
|
+
execute: MessageCommandExecuteFunction;
|
|
190
|
+
options: MessageCommandOptionResolvable[];
|
|
191
|
+
}
|
|
192
|
+
export interface MessageCommandOptionData extends SharedCommandDataProperties {
|
|
193
|
+
name: string;
|
|
194
|
+
description: string;
|
|
195
|
+
required: boolean;
|
|
196
|
+
validator: (value: string) => Awaitable<boolean>;
|
|
197
|
+
}
|
|
@@ -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 isCtorClass = object.constructor && object.constructor.toString().substring(0, 5) === 'class';
|
|
6
|
+
if (object.prototype === undefined)
|
|
7
|
+
return isCtorClass;
|
|
8
|
+
const isPrototypeCtorClass = object.prototype.constructor && object.prototype.constructor.toString && object.prototype.constructor.toString().substring(0, 5) === 'class';
|
|
9
|
+
return isCtorClass || isPrototypeCtorClass;
|
|
10
|
+
}
|
|
11
|
+
exports.isClass = isClass;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reciple",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.4.0-pre.1",
|
|
4
4
|
"bin": "bin/bin.js",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "bin/index.js",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"yaml": "^2.1.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@types/node": "^18.7.
|
|
60
|
+
"@types/node": "^18.7.9",
|
|
61
61
|
"@types/semver": "^7.3.12",
|
|
62
|
-
"discord.js": "^14.
|
|
62
|
+
"discord.js": "^14.3.0",
|
|
63
63
|
"rimraf": "^3.0.2",
|
|
64
64
|
"typedoc": "^0.23.10",
|
|
65
65
|
"typedoc-plugin-discord-types": "^1.0.2",
|