reciple 5.0.0-pre.3 → 5.0.0-pre.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/bin.js +6 -3
- package/bin/reciple/classes/RecipleClient.d.ts +17 -16
- package/bin/reciple/classes/RecipleClient.js +98 -85
- package/bin/reciple/classes/RecipleConfig.d.ts +9 -9
- package/bin/reciple/classes/RecipleConfig.js +5 -10
- package/bin/reciple/classes/builders/MessageCommandBuilder.d.ts +11 -32
- package/bin/reciple/classes/builders/MessageCommandBuilder.js +26 -45
- package/bin/reciple/classes/builders/SlashCommandBuilder.d.ts +11 -32
- package/bin/reciple/classes/builders/SlashCommandBuilder.js +2 -23
- package/bin/reciple/flags.d.ts +9 -0
- package/bin/reciple/flags.js +17 -4
- package/bin/reciple/modules.d.ts +1 -1
- package/bin/reciple/modules.js +18 -17
- package/bin/reciple/registerApplicationCommands.js +1 -2
- package/bin/reciple/types/builders.d.ts +45 -3
- package/package.json +1 -1
- package/resource/reciple.yml +1 -1
package/bin/bin.js
CHANGED
|
@@ -22,15 +22,18 @@ const flags_1 = require("./reciple/flags");
|
|
|
22
22
|
const fallout_utility_1 = require("fallout-utility");
|
|
23
23
|
const chalk_1 = __importDefault(require("chalk"));
|
|
24
24
|
require("dotenv/config");
|
|
25
|
+
const discord_js_1 = require("discord.js");
|
|
26
|
+
const path_1 = __importDefault(require("path"));
|
|
25
27
|
const allowedFiles = ['node_modules', 'reciple.yml', 'package.json'];
|
|
26
|
-
|
|
28
|
+
const configPath = path_1.default.join(flags_1.cwd, './reciple.yml');
|
|
29
|
+
if ((0, fs_1.readdirSync)(flags_1.cwd).filter(f => !f.startsWith('.') && allowedFiles.indexOf(f)).length > 0 && !(0, fs_1.existsSync)((_a = flags_1.flags.config) !== null && _a !== void 0 ? _a : configPath)) {
|
|
27
30
|
const ask = (_c = (_b = (flags_1.flags.yes ? 'y' : null)) !== null && _b !== void 0 ? _b : (0, fallout_utility_1.input)('This directory does not contain reciple.yml. Would you like to init axis here? [y/n] ')) !== null && _c !== void 0 ? _c : '';
|
|
28
31
|
if (ask.toString().toLowerCase() !== 'y')
|
|
29
32
|
process.exit(0);
|
|
30
33
|
}
|
|
31
34
|
let configParser;
|
|
32
35
|
try {
|
|
33
|
-
configParser = new RecipleConfig_1.RecipleConfig((_d = flags_1.flags.config) !== null && _d !== void 0 ? _d :
|
|
36
|
+
configParser = new RecipleConfig_1.RecipleConfig((_d = flags_1.flags.config) !== null && _d !== void 0 ? _d : configPath).parseConfig();
|
|
34
37
|
}
|
|
35
38
|
catch (err) {
|
|
36
39
|
console.error(`${chalk_1.default.bold.red('Config Error')}: ${chalk_1.default.white(err.message)}`);
|
|
@@ -41,7 +44,7 @@ const client = new RecipleClient_1.RecipleClient(Object.assign({ config: config
|
|
|
41
44
|
if (config.fileLogging.clientLogs)
|
|
42
45
|
client.logger.info('Reciple Client v' + version_1.rawVersion + ' is starting...');
|
|
43
46
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
yield client.startModules();
|
|
47
|
+
yield client.startModules((0, discord_js_1.normalizeArray)(config.modulesFolder));
|
|
45
48
|
client.on('ready', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
49
|
var _e;
|
|
47
50
|
if (client.isClientLogsEnabled())
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { MessageCommandBuilder, MessageCommandExecuteData } from './builders/MessageCommandBuilder';
|
|
2
2
|
import { SlashCommandBuilder, SlashCommandExecuteData } from './builders/SlashCommandBuilder';
|
|
3
3
|
import { ApplicationCommandBuilder } from '../registerApplicationCommands';
|
|
4
|
-
import { AnyCommandBuilder, CommandBuilderType } from '../types/builders';
|
|
4
|
+
import { AnyCommandBuilder, CommandBuilderType, AnyCommandExecuteData } from '../types/builders';
|
|
5
5
|
import { CommandCooldownManager } from './CommandCooldownManager';
|
|
6
|
+
import { AnyCommandHaltData } from '../types/commands';
|
|
6
7
|
import { RecipleClientAddModuleOptions } from '../types/paramOptions';
|
|
7
8
|
import { Logger as ILogger } from 'fallout-utility';
|
|
8
9
|
import { Config } from './RecipleConfig';
|
|
9
10
|
import { RecipleModule } from '../modules';
|
|
10
|
-
import { ApplicationCommandData, Awaitable, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, Interaction, Message } from 'discord.js';
|
|
11
|
+
import { ApplicationCommandData, Awaitable, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, Interaction, Message, RestOrArray } from 'discord.js';
|
|
11
12
|
/**
|
|
12
13
|
* options for Reciple client
|
|
13
14
|
*/
|
|
@@ -18,19 +19,19 @@ export interface RecipleClientOptions extends ClientOptions {
|
|
|
18
19
|
* Reciple client commands object interface
|
|
19
20
|
*/
|
|
20
21
|
export interface RecipleClientCommands {
|
|
21
|
-
messageCommands: {
|
|
22
|
-
[commandName: string]: MessageCommandBuilder;
|
|
23
|
-
};
|
|
24
22
|
slashCommands: {
|
|
25
23
|
[commandName: string]: SlashCommandBuilder;
|
|
26
24
|
};
|
|
25
|
+
messageCommands: {
|
|
26
|
+
[commandName: string]: MessageCommandBuilder;
|
|
27
|
+
};
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* Reciple client events
|
|
30
31
|
*/
|
|
31
32
|
export interface RecipleClientEvents extends ClientEvents {
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
recipleCommandExecute: [executeData: AnyCommandExecuteData];
|
|
34
|
+
recipleCommandHalt: [haltData: AnyCommandHaltData];
|
|
34
35
|
recipleReplyError: [error: unknown];
|
|
35
36
|
}
|
|
36
37
|
/**
|
|
@@ -52,7 +53,7 @@ export interface RecipleClient<Ready extends boolean = boolean> extends Client<R
|
|
|
52
53
|
export declare class RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
53
54
|
config: Config;
|
|
54
55
|
commands: RecipleClientCommands;
|
|
55
|
-
|
|
56
|
+
additionalApplicationCommands: (ApplicationCommandBuilder | ApplicationCommandData)[];
|
|
56
57
|
cooldowns: CommandCooldownManager;
|
|
57
58
|
modules: RecipleModule[];
|
|
58
59
|
logger: ILogger;
|
|
@@ -63,9 +64,9 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
|
|
|
63
64
|
constructor(options: RecipleClientOptions);
|
|
64
65
|
/**
|
|
65
66
|
* Load modules from modules folder
|
|
66
|
-
* @param
|
|
67
|
+
* @param folders List of folders that contains the modules you want to load
|
|
67
68
|
*/
|
|
68
|
-
startModules(
|
|
69
|
+
startModules(...folders: RestOrArray<string>): Promise<RecipleClient<Ready>>;
|
|
69
70
|
/**
|
|
70
71
|
* Execute `onLoad()` from client modules and register application commands if enabled
|
|
71
72
|
*/
|
|
@@ -84,23 +85,23 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
|
|
|
84
85
|
* Listed to command executions
|
|
85
86
|
*/
|
|
86
87
|
addCommandListeners(): RecipleClient<Ready>;
|
|
88
|
+
/**
|
|
89
|
+
* Execute a slash command
|
|
90
|
+
* @param interaction Slash command interaction
|
|
91
|
+
*/
|
|
92
|
+
slashCommandExecute(interaction: Interaction | ChatInputCommandInteraction): Promise<void | SlashCommandExecuteData>;
|
|
87
93
|
/**
|
|
88
94
|
* Execute a Message command
|
|
89
95
|
* @param message Message command executor
|
|
90
96
|
* @param prefix Message command prefix
|
|
91
97
|
*/
|
|
92
98
|
messageCommandExecute(message: Message, prefix?: string): Promise<void | MessageCommandExecuteData>;
|
|
93
|
-
/**
|
|
94
|
-
* Execute a slash command
|
|
95
|
-
* @param interaction Slash command interaction
|
|
96
|
-
*/
|
|
97
|
-
slashCommandExecute(interaction: Interaction | ChatInputCommandInteraction): Promise<void | SlashCommandExecuteData>;
|
|
98
99
|
/**
|
|
99
100
|
* Get a message from config
|
|
100
101
|
* @param messageKey Config messages key
|
|
101
102
|
* @param defaultMessage Default message when the key does not exists
|
|
102
103
|
*/
|
|
103
|
-
|
|
104
|
+
getConfigMessage<T = unknown>(messageKey: string, defaultMessage?: T): T;
|
|
104
105
|
/**
|
|
105
106
|
* Get command builder by name or alias if it's a message command
|
|
106
107
|
* @param command Command name
|
|
@@ -8,6 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.RecipleClient = void 0;
|
|
13
16
|
const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
|
|
@@ -24,16 +27,18 @@ const modules_1 = require("../modules");
|
|
|
24
27
|
const logger_1 = require("../logger");
|
|
25
28
|
const version_1 = require("../version");
|
|
26
29
|
const discord_js_1 = require("discord.js");
|
|
30
|
+
const path_1 = __importDefault(require("path"));
|
|
31
|
+
const flags_1 = require("../flags");
|
|
27
32
|
class RecipleClient extends discord_js_1.Client {
|
|
28
33
|
/**
|
|
29
34
|
* @param options Client options
|
|
30
35
|
*/
|
|
31
36
|
constructor(options) {
|
|
32
|
-
var _a, _b, _c;
|
|
37
|
+
var _a, _b, _c, _d;
|
|
33
38
|
super(options);
|
|
34
39
|
this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
|
|
35
|
-
this.commands = {
|
|
36
|
-
this.
|
|
40
|
+
this.commands = { slashCommands: {}, messageCommands: {} };
|
|
41
|
+
this.additionalApplicationCommands = [];
|
|
37
42
|
this.cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
|
|
38
43
|
this.modules = [];
|
|
39
44
|
this.version = version_1.version;
|
|
@@ -42,20 +47,26 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
42
47
|
throw new Error('Config is not defined.');
|
|
43
48
|
this.config = Object.assign(Object.assign({}, this.config), ((_c = options.config) !== null && _c !== void 0 ? _c : {}));
|
|
44
49
|
if (this.config.fileLogging.enabled)
|
|
45
|
-
this.logger.logFile(this.config.fileLogging.logFilePath, false);
|
|
50
|
+
this.logger.logFile((_d = this.config.fileLogging.logFilePath) !== null && _d !== void 0 ? _d : path_1.default.join(flags_1.cwd, 'logs/latest.log'), false);
|
|
46
51
|
}
|
|
47
52
|
/**
|
|
48
53
|
* Load modules from modules folder
|
|
49
|
-
* @param
|
|
54
|
+
* @param folders List of folders that contains the modules you want to load
|
|
50
55
|
*/
|
|
51
|
-
startModules(
|
|
56
|
+
startModules(...folders) {
|
|
52
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
folders = (0, discord_js_1.normalizeArray)(folders).map(f => path_1.default.join(flags_1.cwd, f));
|
|
59
|
+
for (const folder of folders) {
|
|
60
|
+
if (this.isClientLogsEnabled())
|
|
61
|
+
this.logger.info(`Loading Modules from ${folder}`);
|
|
62
|
+
const modules = yield (0, modules_1.getModules)(this, folder).catch(() => null);
|
|
63
|
+
if (!modules) {
|
|
64
|
+
if (this.isClientLogsEnabled())
|
|
65
|
+
this.logger.error(`Failed to load modules from ${folder}`);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
this.modules = modules.modules;
|
|
69
|
+
}
|
|
59
70
|
return this;
|
|
60
71
|
});
|
|
61
72
|
}
|
|
@@ -91,7 +102,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
91
102
|
if (this.config.commands.slashCommand.registerCommands) {
|
|
92
103
|
yield (0, registerApplicationCommands_1.registerApplicationCommands)({
|
|
93
104
|
client: this,
|
|
94
|
-
commands: [...Object.values(this.commands.slashCommands), ...this.
|
|
105
|
+
commands: [...Object.values(this.commands.slashCommands), ...this.additionalApplicationCommands],
|
|
95
106
|
guilds: this.config.commands.slashCommand.guilds
|
|
96
107
|
});
|
|
97
108
|
}
|
|
@@ -124,7 +135,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
124
135
|
if (registerCommands)
|
|
125
136
|
yield (0, registerApplicationCommands_1.registerApplicationCommands)({
|
|
126
137
|
client: this,
|
|
127
|
-
commands: [...Object.values(this.commands.slashCommands), ...this.
|
|
138
|
+
commands: [...Object.values(this.commands.slashCommands), ...this.additionalApplicationCommands],
|
|
128
139
|
guilds: this.config.commands.slashCommand.guilds
|
|
129
140
|
});
|
|
130
141
|
});
|
|
@@ -157,75 +168,54 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
157
168
|
return this;
|
|
158
169
|
}
|
|
159
170
|
/**
|
|
160
|
-
* Execute a
|
|
161
|
-
* @param
|
|
162
|
-
* @param prefix Message command prefix
|
|
171
|
+
* Execute a slash command
|
|
172
|
+
* @param interaction Slash command interaction
|
|
163
173
|
*/
|
|
164
|
-
|
|
165
|
-
var _a;
|
|
174
|
+
slashCommandExecute(interaction) {
|
|
175
|
+
var _a, _b;
|
|
166
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
if (!
|
|
168
|
-
return;
|
|
169
|
-
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
170
|
-
if (!parseCommand || !(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command))
|
|
177
|
+
if (!interaction || !interaction.isChatInputCommand() || !this.isReady())
|
|
171
178
|
return;
|
|
172
|
-
const command = this.findCommand(
|
|
179
|
+
const command = this.findCommand(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
|
|
173
180
|
if (!command)
|
|
174
181
|
return;
|
|
175
|
-
const commandOptions = yield (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
|
|
176
182
|
const executeData = {
|
|
177
|
-
|
|
178
|
-
options: commandOptions,
|
|
179
|
-
command: parseCommand,
|
|
183
|
+
interaction,
|
|
180
184
|
builder: command,
|
|
181
185
|
client: this
|
|
182
186
|
};
|
|
183
187
|
if ((0, permissions_1.userHasCommandPermissions)({
|
|
184
188
|
builder: command,
|
|
185
|
-
memberPermissions: (_a =
|
|
186
|
-
commandPermissions: this.config.commands.
|
|
189
|
+
memberPermissions: (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined,
|
|
190
|
+
commandPermissions: this.config.commands.slashCommand.permissions
|
|
187
191
|
})) {
|
|
188
|
-
if (!command
|
|
192
|
+
if (!command)
|
|
189
193
|
return;
|
|
190
|
-
if (command.
|
|
191
|
-
if (commandOptions.some(o => o.invalid)) {
|
|
192
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)) }))) {
|
|
193
|
-
message.reply(this.getMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
|
|
194
|
-
}
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
if (commandOptions.some(o => o.missing)) {
|
|
198
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)) }))) {
|
|
199
|
-
message.reply(this.getMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
|
|
200
|
-
}
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (message.guild && !(0, permissions_1.botHasExecutePermissions)(message.guild, command.requiredBotPermissions)) {
|
|
194
|
+
if (interaction.guild && !(0, permissions_1.botHasExecutePermissions)(interaction.guild, command.requiredBotPermissions)) {
|
|
205
195
|
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
|
|
206
|
-
|
|
196
|
+
yield interaction.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
|
|
207
197
|
}
|
|
208
198
|
return;
|
|
209
199
|
}
|
|
210
200
|
const userCooldown = {
|
|
211
|
-
user:
|
|
201
|
+
user: interaction.user,
|
|
212
202
|
command: command.name,
|
|
213
|
-
channel:
|
|
214
|
-
guild:
|
|
215
|
-
type: builders_1.CommandBuilderType.
|
|
203
|
+
channel: (_b = interaction.channel) !== null && _b !== void 0 ? _b : undefined,
|
|
204
|
+
guild: interaction.guild,
|
|
205
|
+
type: builders_1.CommandBuilderType.SlashCommand
|
|
216
206
|
};
|
|
217
|
-
if (this.config.commands.
|
|
207
|
+
if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
|
|
218
208
|
this.cooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
|
|
219
209
|
}
|
|
220
|
-
else if (this.config.commands.
|
|
210
|
+
else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
|
|
221
211
|
if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.cooldowns.get(userCooldown))))) {
|
|
222
|
-
yield
|
|
212
|
+
yield interaction.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
|
|
223
213
|
}
|
|
224
214
|
return;
|
|
225
215
|
}
|
|
226
216
|
try {
|
|
227
217
|
yield Promise.resolve(command.execute(executeData))
|
|
228
|
-
.then(() => this.emit('
|
|
218
|
+
.then(() => this.emit('recipleCommandExecute', executeData))
|
|
229
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; }));
|
|
230
220
|
return executeData;
|
|
231
221
|
}
|
|
@@ -236,59 +226,80 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
236
226
|
}
|
|
237
227
|
}
|
|
238
228
|
else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
|
|
239
|
-
|
|
229
|
+
yield interaction.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
240
230
|
}
|
|
241
231
|
});
|
|
242
232
|
}
|
|
243
233
|
/**
|
|
244
|
-
* Execute a
|
|
245
|
-
* @param
|
|
234
|
+
* Execute a Message command
|
|
235
|
+
* @param message Message command executor
|
|
236
|
+
* @param prefix Message command prefix
|
|
246
237
|
*/
|
|
247
|
-
|
|
248
|
-
var _a
|
|
238
|
+
messageCommandExecute(message, prefix) {
|
|
239
|
+
var _a;
|
|
249
240
|
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
-
if (!
|
|
241
|
+
if (!message.content || !this.isReady())
|
|
251
242
|
return;
|
|
252
|
-
const
|
|
243
|
+
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
244
|
+
if (!parseCommand || !(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command))
|
|
245
|
+
return;
|
|
246
|
+
const command = this.findCommand(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
|
|
253
247
|
if (!command)
|
|
254
248
|
return;
|
|
249
|
+
const commandOptions = yield (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
|
|
255
250
|
const executeData = {
|
|
256
|
-
|
|
251
|
+
message: message,
|
|
252
|
+
options: commandOptions,
|
|
253
|
+
command: parseCommand,
|
|
257
254
|
builder: command,
|
|
258
255
|
client: this
|
|
259
256
|
};
|
|
260
257
|
if ((0, permissions_1.userHasCommandPermissions)({
|
|
261
258
|
builder: command,
|
|
262
|
-
memberPermissions: (_a =
|
|
263
|
-
commandPermissions: this.config.commands.
|
|
259
|
+
memberPermissions: (_a = message.member) === null || _a === void 0 ? void 0 : _a.permissions,
|
|
260
|
+
commandPermissions: this.config.commands.messageCommand.permissions
|
|
264
261
|
})) {
|
|
265
|
-
if (!command)
|
|
262
|
+
if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM || !command.allowExecuteByBots && (message.author.bot || message.author.system))
|
|
266
263
|
return;
|
|
267
|
-
if (
|
|
264
|
+
if (command.validateOptions) {
|
|
265
|
+
if (commandOptions.some(o => o.invalid)) {
|
|
266
|
+
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)) }))) {
|
|
267
|
+
message.reply(this.getConfigMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
|
|
268
|
+
}
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (commandOptions.some(o => o.missing)) {
|
|
272
|
+
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)) }))) {
|
|
273
|
+
message.reply(this.getConfigMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
|
|
274
|
+
}
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (message.guild && !(0, permissions_1.botHasExecutePermissions)(message.guild, command.requiredBotPermissions)) {
|
|
268
279
|
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
|
|
269
|
-
|
|
280
|
+
message.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
|
|
270
281
|
}
|
|
271
282
|
return;
|
|
272
283
|
}
|
|
273
284
|
const userCooldown = {
|
|
274
|
-
user:
|
|
285
|
+
user: message.author,
|
|
275
286
|
command: command.name,
|
|
276
|
-
channel:
|
|
277
|
-
guild:
|
|
278
|
-
type: builders_1.CommandBuilderType.
|
|
287
|
+
channel: message.channel,
|
|
288
|
+
guild: message.guild,
|
|
289
|
+
type: builders_1.CommandBuilderType.MessageCommand
|
|
279
290
|
};
|
|
280
|
-
if (this.config.commands.
|
|
291
|
+
if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
|
|
281
292
|
this.cooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
|
|
282
293
|
}
|
|
283
|
-
else if (this.config.commands.
|
|
294
|
+
else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
|
|
284
295
|
if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.cooldowns.get(userCooldown))))) {
|
|
285
|
-
yield
|
|
296
|
+
yield message.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
|
|
286
297
|
}
|
|
287
298
|
return;
|
|
288
299
|
}
|
|
289
300
|
try {
|
|
290
301
|
yield Promise.resolve(command.execute(executeData))
|
|
291
|
-
.then(() => this.emit('
|
|
302
|
+
.then(() => this.emit('recipleCommandExecute', executeData))
|
|
292
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; }));
|
|
293
304
|
return executeData;
|
|
294
305
|
}
|
|
@@ -299,7 +310,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
299
310
|
}
|
|
300
311
|
}
|
|
301
312
|
else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
|
|
302
|
-
|
|
313
|
+
message.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
303
314
|
}
|
|
304
315
|
});
|
|
305
316
|
}
|
|
@@ -308,7 +319,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
308
319
|
* @param messageKey Config messages key
|
|
309
320
|
* @param defaultMessage Default message when the key does not exists
|
|
310
321
|
*/
|
|
311
|
-
|
|
322
|
+
getConfigMessage(messageKey, defaultMessage) {
|
|
312
323
|
var _a, _b;
|
|
313
324
|
return (_b = (_a = this.config.messages[messageKey]) !== null && _a !== void 0 ? _a : defaultMessage) !== null && _b !== void 0 ? _b : messageKey;
|
|
314
325
|
}
|
|
@@ -342,11 +353,13 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
342
353
|
var _a;
|
|
343
354
|
return __awaiter(this, void 0, void 0, function* () {
|
|
344
355
|
try {
|
|
345
|
-
|
|
356
|
+
const haltResolved = (_a = (command.halt
|
|
346
357
|
? yield (command.type == builders_1.CommandBuilderType.SlashCommand
|
|
347
358
|
? Promise.resolve(command.halt(haltData))
|
|
348
359
|
: Promise.resolve(command.halt(haltData))).catch(err => { throw err; })
|
|
349
360
|
: false)) !== null && _a !== void 0 ? _a : false;
|
|
361
|
+
this.emit('recipleCommandHalt', haltData);
|
|
362
|
+
return haltResolved;
|
|
350
363
|
}
|
|
351
364
|
catch (err) {
|
|
352
365
|
if (this.isClientLogsEnabled()) {
|
|
@@ -370,15 +383,15 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
370
383
|
}
|
|
371
384
|
if (!err || !command)
|
|
372
385
|
return;
|
|
373
|
-
if (
|
|
374
|
-
if (!this.config.commands.
|
|
386
|
+
if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
|
|
387
|
+
if (!this.config.commands.slashCommand.replyOnError)
|
|
375
388
|
return;
|
|
376
|
-
yield command.
|
|
389
|
+
yield command.interaction.followUp(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
|
|
377
390
|
}
|
|
378
|
-
else if (
|
|
379
|
-
if (!this.config.commands.
|
|
391
|
+
else if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
|
|
392
|
+
if (!this.config.commands.messageCommand.replyOnError)
|
|
380
393
|
return;
|
|
381
|
-
yield command.
|
|
394
|
+
yield command.message.reply(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
|
|
382
395
|
}
|
|
383
396
|
});
|
|
384
397
|
}
|
|
@@ -12,25 +12,25 @@ export interface ConfigCommandPermissions {
|
|
|
12
12
|
export interface Config {
|
|
13
13
|
token: string;
|
|
14
14
|
commands: {
|
|
15
|
-
|
|
15
|
+
slashCommand: {
|
|
16
16
|
enabled: boolean;
|
|
17
|
-
prefix?: string;
|
|
18
17
|
replyOnError: boolean;
|
|
19
|
-
|
|
18
|
+
registerCommands: boolean;
|
|
20
19
|
enableCooldown: boolean;
|
|
21
|
-
|
|
20
|
+
setRequiredPermissions: boolean;
|
|
21
|
+
guilds?: string[] | string;
|
|
22
22
|
permissions: {
|
|
23
23
|
enabled: boolean;
|
|
24
24
|
commands: ConfigCommandPermissions[];
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
|
-
|
|
27
|
+
messageCommand: {
|
|
28
28
|
enabled: boolean;
|
|
29
|
+
prefix?: string;
|
|
29
30
|
replyOnError: boolean;
|
|
30
|
-
|
|
31
|
+
allowCommandAlias: boolean;
|
|
31
32
|
enableCooldown: boolean;
|
|
32
|
-
|
|
33
|
-
guilds?: string[] | string;
|
|
33
|
+
commandArgumentSeparator: string;
|
|
34
34
|
permissions: {
|
|
35
35
|
enabled: boolean;
|
|
36
36
|
commands: ConfigCommandPermissions[];
|
|
@@ -49,7 +49,7 @@ export interface Config {
|
|
|
49
49
|
[messageKey: string]: any;
|
|
50
50
|
};
|
|
51
51
|
ignoredFiles: string[];
|
|
52
|
-
modulesFolder: string;
|
|
52
|
+
modulesFolder: string | string[];
|
|
53
53
|
disableVersionCheck: boolean;
|
|
54
54
|
version: string;
|
|
55
55
|
}
|
|
@@ -19,7 +19,7 @@ class RecipleConfig {
|
|
|
19
19
|
*/
|
|
20
20
|
constructor(configPath) {
|
|
21
21
|
this.config = RecipleConfig.getDefaultConfig();
|
|
22
|
-
this.configPath = '
|
|
22
|
+
this.configPath = path_1.default.join(flags_1.cwd, 'reciple.yml');
|
|
23
23
|
if (!configPath)
|
|
24
24
|
throw new Error('Config path is not defined');
|
|
25
25
|
this.configPath = configPath;
|
|
@@ -66,15 +66,10 @@ class RecipleConfig {
|
|
|
66
66
|
* @param askIfNull Ask for token if the token is null/undefined
|
|
67
67
|
*/
|
|
68
68
|
parseToken(askIfNull = true) {
|
|
69
|
-
var _a
|
|
70
|
-
let token = flags_1.token || null;
|
|
71
|
-
if (!this.config && !token)
|
|
72
|
-
return token;
|
|
73
|
-
if (this.config && !((_a = this.config) === null || _a === void 0 ? void 0 : _a.token) && !token)
|
|
74
|
-
return token || (askIfNull ? this.askToken() : null);
|
|
75
|
-
token = token || ((_b = this.config) === null || _b === void 0 ? void 0 : _b.token) || null;
|
|
69
|
+
var _a;
|
|
70
|
+
let token = flags_1.token || ((_a = this.config) === null || _a === void 0 ? void 0 : _a.token) || null;
|
|
76
71
|
if (!token)
|
|
77
|
-
return token;
|
|
72
|
+
return token || (askIfNull ? this.askToken() : null);
|
|
78
73
|
const envToken = token.toString().split(':');
|
|
79
74
|
if (envToken.length === 2 && envToken[0].toLocaleLowerCase() === 'env' && envToken[1]) {
|
|
80
75
|
token = process.env[envToken[1]] || null;
|
|
@@ -92,7 +87,7 @@ class RecipleConfig {
|
|
|
92
87
|
* Ask for a token
|
|
93
88
|
*/
|
|
94
89
|
askToken() {
|
|
95
|
-
return flags_1.token || (0, fallout_utility_1.input)({
|
|
90
|
+
return flags_1.token || (0, fallout_utility_1.input)({ text: 'Bot Token >>> ', echo: '*', repeatIfEmpty: true, sigint: true }) || null;
|
|
96
91
|
}
|
|
97
92
|
/**
|
|
98
93
|
* Get default config
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CommandBuilderType, AnyCommandExecuteData, CommandHaltFunction, CommandExecuteFunction } from '../../types/builders';
|
|
1
|
+
import { CommandBuilderType, AnyCommandExecuteData, CommandHaltFunction, CommandExecuteFunction, SharedCommandBuilderProperties } from '../../types/builders';
|
|
2
2
|
import { MessageCommandOptionManager } from '../MessageCommandOptionManager';
|
|
3
3
|
import { MessageCommandOptionBuilder } from './MessageCommandOptionBuilder';
|
|
4
4
|
import { Command as CommandMessage } from 'fallout-utility';
|
|
5
|
-
import { Message, PermissionResolvable } from 'discord.js';
|
|
5
|
+
import { Message, PermissionResolvable, RestOrArray } from 'discord.js';
|
|
6
6
|
import { CommandHaltData } from '../../types/commands';
|
|
7
7
|
import { RecipleClient } from '../RecipleClient';
|
|
8
8
|
/**
|
|
@@ -40,14 +40,14 @@ export declare type MessageCommandExecuteFunction = CommandExecuteFunction<Comma
|
|
|
40
40
|
/**
|
|
41
41
|
* Reciple builder for message command
|
|
42
42
|
*/
|
|
43
|
-
export declare class MessageCommandBuilder {
|
|
43
|
+
export declare class MessageCommandBuilder implements SharedCommandBuilderProperties {
|
|
44
44
|
readonly type = CommandBuilderType.MessageCommand;
|
|
45
45
|
name: string;
|
|
46
|
-
cooldown: number;
|
|
47
46
|
description: string;
|
|
47
|
+
cooldown: number;
|
|
48
48
|
aliases: string[];
|
|
49
|
-
options: MessageCommandOptionBuilder[];
|
|
50
49
|
validateOptions: boolean;
|
|
50
|
+
options: MessageCommandOptionBuilder[];
|
|
51
51
|
requiredBotPermissions: PermissionResolvable[];
|
|
52
52
|
requiredMemberPermissions: PermissionResolvable[];
|
|
53
53
|
allowExecuteInDM: boolean;
|
|
@@ -64,27 +64,11 @@ export declare class MessageCommandBuilder {
|
|
|
64
64
|
* @param description Command description
|
|
65
65
|
*/
|
|
66
66
|
setDescription(description: string): this;
|
|
67
|
-
/**
|
|
68
|
-
* Sets the execute cooldown for this command.
|
|
69
|
-
* - `0` means no cooldown
|
|
70
|
-
* @param cooldown Command cooldown in milliseconds
|
|
71
|
-
*/
|
|
72
|
-
setCooldown(cooldown: number): this;
|
|
73
67
|
/**
|
|
74
68
|
* Add aliases to the command
|
|
75
69
|
* @param aliases Command aliases
|
|
76
70
|
*/
|
|
77
|
-
addAliases(...aliases: string
|
|
78
|
-
/**
|
|
79
|
-
* Set required bot permissions to execute the command
|
|
80
|
-
* @param permissions Bot's required permissions
|
|
81
|
-
*/
|
|
82
|
-
setRequiredBotPermissions(...permissions: PermissionResolvable[]): this;
|
|
83
|
-
/**
|
|
84
|
-
* Set required permissions to execute the command
|
|
85
|
-
* @param permissions User's return permissions
|
|
86
|
-
*/
|
|
87
|
-
setRequiredMemberPermissions(...permissions: PermissionResolvable[]): this;
|
|
71
|
+
addAliases(...aliases: RestOrArray<string>): this;
|
|
88
72
|
/**
|
|
89
73
|
* Set if command can be executed in dms
|
|
90
74
|
* @param allowExecuteInDM `true` if the command can execute in DMs
|
|
@@ -95,16 +79,6 @@ export declare class MessageCommandBuilder {
|
|
|
95
79
|
* @param allowExecuteByBots `true` if the command can be executed by bots
|
|
96
80
|
*/
|
|
97
81
|
setAllowExecuteByBots(allowExecuteByBots: boolean): this;
|
|
98
|
-
/**
|
|
99
|
-
* Function when the command is interupted
|
|
100
|
-
* @param halt Function to execute when command is halted
|
|
101
|
-
*/
|
|
102
|
-
setHalt(halt?: this["halt"]): this;
|
|
103
|
-
/**
|
|
104
|
-
* Function when the command is executed
|
|
105
|
-
* @param execute Function to execute when the command is called
|
|
106
|
-
*/
|
|
107
|
-
setExecute(execute: this["execute"]): this;
|
|
108
82
|
/**
|
|
109
83
|
* Add option to the command
|
|
110
84
|
* @param option Message option builder
|
|
@@ -115,6 +89,11 @@ export declare class MessageCommandBuilder {
|
|
|
115
89
|
* @param validateOptions `true` if the command options needs to be validated before executing
|
|
116
90
|
*/
|
|
117
91
|
setValidateOptions(validateOptions: boolean): this;
|
|
92
|
+
setCooldown(cooldown: number): this;
|
|
93
|
+
setRequiredBotPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
94
|
+
setRequiredMemberPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
95
|
+
setHalt(halt?: this["halt"]): this;
|
|
96
|
+
setExecute(execute: this["execute"]): this;
|
|
118
97
|
/**
|
|
119
98
|
* Is a message command builder
|
|
120
99
|
*/
|
|
@@ -13,6 +13,7 @@ exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
|
|
|
13
13
|
const builders_1 = require("../../types/builders");
|
|
14
14
|
const MessageCommandOptionManager_1 = require("../MessageCommandOptionManager");
|
|
15
15
|
const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
|
|
16
|
+
const discord_js_1 = require("discord.js");
|
|
16
17
|
/**
|
|
17
18
|
* Reciple builder for message command
|
|
18
19
|
*/
|
|
@@ -20,11 +21,11 @@ class MessageCommandBuilder {
|
|
|
20
21
|
constructor() {
|
|
21
22
|
this.type = builders_1.CommandBuilderType.MessageCommand;
|
|
22
23
|
this.name = '';
|
|
23
|
-
this.cooldown = 0;
|
|
24
24
|
this.description = '';
|
|
25
|
+
this.cooldown = 0;
|
|
25
26
|
this.aliases = [];
|
|
26
|
-
this.options = [];
|
|
27
27
|
this.validateOptions = false;
|
|
28
|
+
this.options = [];
|
|
28
29
|
this.requiredBotPermissions = [];
|
|
29
30
|
this.requiredMemberPermissions = [];
|
|
30
31
|
this.allowExecuteInDM = true;
|
|
@@ -51,20 +52,12 @@ class MessageCommandBuilder {
|
|
|
51
52
|
this.description = description;
|
|
52
53
|
return this;
|
|
53
54
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Sets the execute cooldown for this command.
|
|
56
|
-
* - `0` means no cooldown
|
|
57
|
-
* @param cooldown Command cooldown in milliseconds
|
|
58
|
-
*/
|
|
59
|
-
setCooldown(cooldown) {
|
|
60
|
-
this.cooldown = cooldown;
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
55
|
/**
|
|
64
56
|
* Add aliases to the command
|
|
65
57
|
* @param aliases Command aliases
|
|
66
58
|
*/
|
|
67
59
|
addAliases(...aliases) {
|
|
60
|
+
aliases = (0, discord_js_1.normalizeArray)(aliases);
|
|
68
61
|
if (!aliases.length)
|
|
69
62
|
throw new TypeError('Provide atleast one alias');
|
|
70
63
|
if (aliases.some(a => !a || typeof a !== 'string' || !a.match(/^[\w-]{1,32}$/)))
|
|
@@ -74,22 +67,6 @@ class MessageCommandBuilder {
|
|
|
74
67
|
this.aliases = [...new Set(aliases)];
|
|
75
68
|
return this;
|
|
76
69
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Set required bot permissions to execute the command
|
|
79
|
-
* @param permissions Bot's required permissions
|
|
80
|
-
*/
|
|
81
|
-
setRequiredBotPermissions(...permissions) {
|
|
82
|
-
this.requiredBotPermissions = permissions;
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Set required permissions to execute the command
|
|
87
|
-
* @param permissions User's return permissions
|
|
88
|
-
*/
|
|
89
|
-
setRequiredMemberPermissions(...permissions) {
|
|
90
|
-
this.requiredMemberPermissions = permissions;
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
70
|
/**
|
|
94
71
|
* Set if command can be executed in dms
|
|
95
72
|
* @param allowExecuteInDM `true` if the command can execute in DMs
|
|
@@ -110,24 +87,6 @@ class MessageCommandBuilder {
|
|
|
110
87
|
this.allowExecuteByBots = allowExecuteByBots;
|
|
111
88
|
return this;
|
|
112
89
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Function when the command is interupted
|
|
115
|
-
* @param halt Function to execute when command is halted
|
|
116
|
-
*/
|
|
117
|
-
setHalt(halt) {
|
|
118
|
-
this.halt = halt ? halt : undefined;
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Function when the command is executed
|
|
123
|
-
* @param execute Function to execute when the command is called
|
|
124
|
-
*/
|
|
125
|
-
setExecute(execute) {
|
|
126
|
-
if (!execute || typeof execute !== 'function')
|
|
127
|
-
throw new TypeError('execute must be a function.');
|
|
128
|
-
this.execute = execute;
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
90
|
/**
|
|
132
91
|
* Add option to the command
|
|
133
92
|
* @param option Message option builder
|
|
@@ -153,6 +112,28 @@ class MessageCommandBuilder {
|
|
|
153
112
|
this.validateOptions = validateOptions;
|
|
154
113
|
return this;
|
|
155
114
|
}
|
|
115
|
+
setCooldown(cooldown) {
|
|
116
|
+
this.cooldown = cooldown;
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
setRequiredBotPermissions(...permissions) {
|
|
120
|
+
this.requiredBotPermissions = (0, discord_js_1.normalizeArray)(permissions);
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
setRequiredMemberPermissions(...permissions) {
|
|
124
|
+
this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
setHalt(halt) {
|
|
128
|
+
this.halt = halt ? halt : undefined;
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
setExecute(execute) {
|
|
132
|
+
if (!execute || typeof execute !== 'function')
|
|
133
|
+
throw new TypeError('execute must be a function.');
|
|
134
|
+
this.execute = execute;
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
156
137
|
/**
|
|
157
138
|
* Is a message command builder
|
|
158
139
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CommandBuilderType, AnyCommandExecuteData, CommandHaltFunction, CommandExecuteFunction } from '../../types/builders';
|
|
1
|
+
import { CommandBuilderType, AnyCommandExecuteData, CommandHaltFunction, CommandExecuteFunction, SharedCommandBuilderProperties } from '../../types/builders';
|
|
2
2
|
import { CommandHaltData } from '../../types/commands';
|
|
3
3
|
import { RecipleClient } from '../RecipleClient';
|
|
4
|
-
import { ChatInputCommandInteraction, PermissionResolvable, SlashCommandBuilder as DiscordJsSlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder as DiscordJsSlashCommandSubcommandsOnlyBuilder } from 'discord.js';
|
|
4
|
+
import { ChatInputCommandInteraction, PermissionResolvable, RestOrArray, SlashCommandBuilder as DiscordJsSlashCommandBuilder, SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandsOnlyBuilder as DiscordJsSlashCommandSubcommandsOnlyBuilder } from 'discord.js';
|
|
5
5
|
/**
|
|
6
6
|
* Execute data for interaction command
|
|
7
7
|
*/
|
|
@@ -10,12 +10,6 @@ export interface SlashCommandExecuteData {
|
|
|
10
10
|
builder: SlashCommandBuilder;
|
|
11
11
|
client: RecipleClient<true>;
|
|
12
12
|
}
|
|
13
|
-
export interface SlashCommandSubcommandsOnlyBuilder extends DiscordJsSlashCommandSubcommandsOnlyBuilder, Pick<SlashCommandBuilder, "setCooldown" | "setRequiredBotPermissions" | "setRequiredMemberPermissions" | "setHalt" | "setExecute"> {
|
|
14
|
-
}
|
|
15
|
-
export interface SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
|
|
16
|
-
addSubcommandGroup(input: SlashCommandSubcommandGroupBuilder | ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder)): SlashCommandSubcommandsOnlyBuilder;
|
|
17
|
-
addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): SlashCommandSubcommandsOnlyBuilder;
|
|
18
|
-
}
|
|
19
13
|
/**
|
|
20
14
|
* Slash command halt data
|
|
21
15
|
*/
|
|
@@ -28,10 +22,16 @@ export declare type SlashCommandHaltFunction = CommandHaltFunction<CommandBuilde
|
|
|
28
22
|
* Slash command execute function
|
|
29
23
|
*/
|
|
30
24
|
export declare type SlashCommandExecuteFunction = CommandExecuteFunction<CommandBuilderType.SlashCommand>;
|
|
25
|
+
export interface SlashCommandSubcommandsOnlyBuilder extends DiscordJsSlashCommandSubcommandsOnlyBuilder, Pick<SlashCommandBuilder, "setCooldown" | "setRequiredBotPermissions" | "setRequiredMemberPermissions" | "setHalt" | "setExecute"> {
|
|
26
|
+
}
|
|
27
|
+
export interface SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
|
|
28
|
+
addSubcommandGroup(input: SlashCommandSubcommandGroupBuilder | ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder)): SlashCommandSubcommandsOnlyBuilder;
|
|
29
|
+
addSubcommand(input: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder)): SlashCommandSubcommandsOnlyBuilder;
|
|
30
|
+
}
|
|
31
31
|
/**
|
|
32
32
|
* Reciple builder for interaction/slash command
|
|
33
33
|
*/
|
|
34
|
-
export declare class SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
|
|
34
|
+
export declare class SlashCommandBuilder extends DiscordJsSlashCommandBuilder implements SharedCommandBuilderProperties {
|
|
35
35
|
readonly type = CommandBuilderType.SlashCommand;
|
|
36
36
|
cooldown: number;
|
|
37
37
|
requiredBotPermissions: PermissionResolvable[];
|
|
@@ -39,31 +39,10 @@ export declare class SlashCommandBuilder extends DiscordJsSlashCommandBuilder {
|
|
|
39
39
|
allowExecuteInDM: boolean;
|
|
40
40
|
halt?: SlashCommandHaltFunction;
|
|
41
41
|
execute: SlashCommandExecuteFunction;
|
|
42
|
-
/**
|
|
43
|
-
* Sets the execute cooldown for this command.
|
|
44
|
-
* - `0` means no cooldown
|
|
45
|
-
* @param cooldown Command cooldown in milliseconds
|
|
46
|
-
*/
|
|
47
42
|
setCooldown(cooldown: number): this;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* @param permissions Bot's required permissions
|
|
51
|
-
*/
|
|
52
|
-
setRequiredBotPermissions(...permissions: PermissionResolvable[]): this;
|
|
53
|
-
/**
|
|
54
|
-
* Set required permissions to execute the command
|
|
55
|
-
* @param permissions User's return permissions
|
|
56
|
-
*/
|
|
57
|
-
setRequiredMemberPermissions(...permissions: PermissionResolvable[]): this;
|
|
58
|
-
/**
|
|
59
|
-
* Function when the command is interupted
|
|
60
|
-
* @param halt Function to execute when command is halted
|
|
61
|
-
*/
|
|
43
|
+
setRequiredBotPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
44
|
+
setRequiredMemberPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
62
45
|
setHalt(halt?: this["halt"]): this;
|
|
63
|
-
/**
|
|
64
|
-
* Function when the command is executed
|
|
65
|
-
* @param execute Function to execute when the command is called
|
|
66
|
-
*/
|
|
67
46
|
setExecute(execute: this["execute"]): this;
|
|
68
47
|
/**
|
|
69
48
|
* Is a slash command builder
|
|
@@ -16,43 +16,22 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
|
|
|
16
16
|
this.allowExecuteInDM = true;
|
|
17
17
|
this.execute = () => { };
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Sets the execute cooldown for this command.
|
|
21
|
-
* - `0` means no cooldown
|
|
22
|
-
* @param cooldown Command cooldown in milliseconds
|
|
23
|
-
*/
|
|
24
19
|
setCooldown(cooldown) {
|
|
25
20
|
this.cooldown = cooldown;
|
|
26
21
|
return this;
|
|
27
22
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Set required bot permissions to execute the command
|
|
30
|
-
* @param permissions Bot's required permissions
|
|
31
|
-
*/
|
|
32
23
|
setRequiredBotPermissions(...permissions) {
|
|
33
|
-
this.requiredBotPermissions = permissions;
|
|
24
|
+
this.requiredBotPermissions = (0, discord_js_1.normalizeArray)(permissions);
|
|
34
25
|
return this;
|
|
35
26
|
}
|
|
36
|
-
/**
|
|
37
|
-
* Set required permissions to execute the command
|
|
38
|
-
* @param permissions User's return permissions
|
|
39
|
-
*/
|
|
40
27
|
setRequiredMemberPermissions(...permissions) {
|
|
41
|
-
this.requiredMemberPermissions = permissions;
|
|
28
|
+
this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
|
|
42
29
|
return this;
|
|
43
30
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Function when the command is interupted
|
|
46
|
-
* @param halt Function to execute when command is halted
|
|
47
|
-
*/
|
|
48
31
|
setHalt(halt) {
|
|
49
32
|
this.halt = halt ? halt : undefined;
|
|
50
33
|
return this;
|
|
51
34
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Function when the command is executed
|
|
54
|
-
* @param execute Function to execute when the command is called
|
|
55
|
-
*/
|
|
56
35
|
setExecute(execute) {
|
|
57
36
|
if (!execute || typeof execute !== 'function')
|
|
58
37
|
throw new Error('execute must be a function.');
|
package/bin/reciple/flags.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* Commander
|
|
4
|
+
*/
|
|
5
|
+
export declare const commander: Command;
|
|
1
6
|
/**
|
|
2
7
|
* Used flags
|
|
3
8
|
*/
|
|
@@ -6,3 +11,7 @@ export declare const flags: import("commander").OptionValues;
|
|
|
6
11
|
* Temporary token flag
|
|
7
12
|
*/
|
|
8
13
|
export declare const token: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Current working directory
|
|
16
|
+
*/
|
|
17
|
+
export declare const cwd: string;
|
package/bin/reciple/flags.js
CHANGED
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.token = exports.flags = void 0;
|
|
6
|
+
exports.cwd = exports.token = exports.flags = exports.commander = void 0;
|
|
4
7
|
const version_1 = require("./version");
|
|
5
8
|
const commander_1 = require("commander");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
6
10
|
/**
|
|
7
|
-
*
|
|
11
|
+
* Commander
|
|
8
12
|
*/
|
|
9
|
-
exports.
|
|
13
|
+
exports.commander = new commander_1.Command()
|
|
10
14
|
.name('reciple')
|
|
11
15
|
.description('Reciple.js - Discord.js handler cli')
|
|
12
16
|
.version(`v${version_1.rawVersion}`, '-v, --version')
|
|
17
|
+
.argument('[current-working-directory]', 'Change the current working directory')
|
|
13
18
|
.option('-t, --token <token>', 'Replace used bot token')
|
|
14
19
|
.option('-c, --config <config>', 'Change path to config file')
|
|
15
20
|
.option('-D, --debugmode', 'Enabled debug mode')
|
|
16
21
|
.option('-y, --yes', 'Automatically agree to Reciple confirmation prompts')
|
|
17
22
|
.option('-v, --version', 'Display version')
|
|
18
|
-
.parse()
|
|
23
|
+
.parse();
|
|
24
|
+
/**
|
|
25
|
+
* Used flags
|
|
26
|
+
*/
|
|
27
|
+
exports.flags = exports.commander.opts();
|
|
19
28
|
/**
|
|
20
29
|
* Temporary token flag
|
|
21
30
|
*/
|
|
22
31
|
exports.token = exports.flags.token;
|
|
32
|
+
/**
|
|
33
|
+
* Current working directory
|
|
34
|
+
*/
|
|
35
|
+
exports.cwd = path_1.default.join(process.cwd(), exports.commander.args[0] || '.');
|
package/bin/reciple/modules.d.ts
CHANGED
|
@@ -29,4 +29,4 @@ export interface RecipleModule {
|
|
|
29
29
|
* @param client Reciple client
|
|
30
30
|
* @param folder Modules folder
|
|
31
31
|
*/
|
|
32
|
-
export declare function
|
|
32
|
+
export declare function getModules(client: RecipleClient, folder?: string): Promise<LoadedModules>;
|
package/bin/reciple/modules.js
CHANGED
|
@@ -12,22 +12,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.getModules = void 0;
|
|
16
16
|
const builders_1 = require("./types/builders");
|
|
17
17
|
const version_1 = require("./version");
|
|
18
18
|
const fs_1 = require("fs");
|
|
19
19
|
const wildcard_match_1 = __importDefault(require("wildcard-match"));
|
|
20
20
|
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const discord_js_1 = require("discord.js");
|
|
21
22
|
/**
|
|
22
23
|
* Load modules from folder
|
|
23
24
|
* @param client Reciple client
|
|
24
25
|
* @param folder Modules folder
|
|
25
26
|
*/
|
|
26
|
-
function
|
|
27
|
-
var _a
|
|
27
|
+
function getModules(client, folder) {
|
|
28
|
+
var _a;
|
|
28
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
30
|
const response = { commands: [], modules: [] };
|
|
30
|
-
const modulesDir =
|
|
31
|
+
const modulesDir = folder || 'modules';
|
|
31
32
|
if (!(0, fs_1.existsSync)(modulesDir))
|
|
32
33
|
(0, fs_1.mkdirSync)(modulesDir, { recursive: true });
|
|
33
34
|
const ignoredFiles = (client.config.ignoredFiles || []).map(file => file.endsWith('.js') ? file : `${file}.js`);
|
|
@@ -35,19 +36,19 @@ function loadModules(client, folder) {
|
|
|
35
36
|
return file.endsWith('.js') && (!file.startsWith('_') && !file.startsWith('.')) && !ignoredFiles.some(f => (0, wildcard_match_1.default)(f)(file));
|
|
36
37
|
});
|
|
37
38
|
for (const script of scripts) {
|
|
38
|
-
const modulePath = path_1.default.join(
|
|
39
|
+
const modulePath = path_1.default.join(modulesDir, script);
|
|
39
40
|
const commands = [];
|
|
40
41
|
let module_;
|
|
41
42
|
try {
|
|
42
43
|
const reqMod = require(modulePath);
|
|
43
|
-
module_ =
|
|
44
|
-
if (!(
|
|
45
|
-
throw new Error(
|
|
46
|
-
const versions =
|
|
44
|
+
module_ = (reqMod === null || reqMod === void 0 ? void 0 : reqMod.default) !== undefined ? reqMod.default : reqMod;
|
|
45
|
+
if (!(module_ === null || module_ === void 0 ? void 0 : module_.versions.length))
|
|
46
|
+
throw new Error(`${modulePath} does not have supported versions.`);
|
|
47
|
+
const versions = (0, discord_js_1.normalizeArray)([module_.versions]);
|
|
47
48
|
if (!client.config.disableVersionCheck && !versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
|
|
48
|
-
throw new Error((
|
|
49
|
-
if (!(yield Promise.resolve(module_.onStart(client))))
|
|
50
|
-
throw new Error(script + ' onStart
|
|
49
|
+
throw new Error((_a = `${modulePath} is unsupported; current version: ${version_1.version}; module supported versions: ` + versions.join(', ')) !== null && _a !== void 0 ? _a : 'none');
|
|
50
|
+
if (!(yield Promise.resolve(module_.onStart(client)).catch(() => null)))
|
|
51
|
+
throw new Error(script + ' onStart returned false or undefined.');
|
|
51
52
|
if (module_.commands) {
|
|
52
53
|
for (const command of module_.commands) {
|
|
53
54
|
if (command.type === builders_1.CommandBuilderType.MessageCommand || command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
@@ -66,12 +67,12 @@ function loadModules(client, folder) {
|
|
|
66
67
|
response.commands.push(...commands.filter((c) => {
|
|
67
68
|
if (!c.name) {
|
|
68
69
|
if (client.isClientLogsEnabled())
|
|
69
|
-
client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} command name is not defined in ${
|
|
70
|
+
client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} command name is not defined in ${modulePath}`);
|
|
70
71
|
return false;
|
|
71
72
|
}
|
|
72
73
|
if (c.type === builders_1.CommandBuilderType.MessageCommand && c.options.length && c.options.some(o => !o.name)) {
|
|
73
74
|
if (client.isClientLogsEnabled())
|
|
74
|
-
client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} option name is not defined in ${
|
|
75
|
+
client.logger.error(`A ${builders_1.CommandBuilderType[c.type]} option name is not defined in ${modulePath}`);
|
|
75
76
|
return false;
|
|
76
77
|
}
|
|
77
78
|
return true;
|
|
@@ -80,14 +81,14 @@ function loadModules(client, folder) {
|
|
|
80
81
|
script: module_,
|
|
81
82
|
info: {
|
|
82
83
|
filename: script,
|
|
83
|
-
versions:
|
|
84
|
+
versions: (0, discord_js_1.normalizeArray)([module_.versions]),
|
|
84
85
|
path: modulePath
|
|
85
86
|
}
|
|
86
87
|
});
|
|
87
88
|
if (client.isClientLogsEnabled())
|
|
88
|
-
client.logger.info(`Loaded module ${
|
|
89
|
+
client.logger.info(`Loaded module ${modulePath}`);
|
|
89
90
|
}
|
|
90
91
|
return response;
|
|
91
92
|
});
|
|
92
93
|
}
|
|
93
|
-
exports.
|
|
94
|
+
exports.getModules = getModules;
|
|
@@ -25,7 +25,7 @@ function registerApplicationCommands(options) {
|
|
|
25
25
|
if (typeof (cmd === null || cmd === void 0 ? void 0 : cmd.toJSON) == 'undefined')
|
|
26
26
|
return cmd;
|
|
27
27
|
cmd = cmd;
|
|
28
|
-
if (
|
|
28
|
+
if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandBuilder(cmd) && client.config.commands.slashCommand.setRequiredPermissions) {
|
|
29
29
|
const permissions = client.config.commands.slashCommand.permissions.enabled
|
|
30
30
|
? (_a = client.config.commands.slashCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())) === null || _a === void 0 ? void 0 : _a.permissions
|
|
31
31
|
: undefined;
|
|
@@ -35,7 +35,6 @@ function registerApplicationCommands(options) {
|
|
|
35
35
|
client.logger.debug(`Set required permissions for ${cmd.name}`);
|
|
36
36
|
}
|
|
37
37
|
client.commands.slashCommands[cmd.name] = cmd;
|
|
38
|
-
return cmd.toJSON();
|
|
39
38
|
}
|
|
40
39
|
return cmd.toJSON();
|
|
41
40
|
})) !== null && _b !== void 0 ? _b : [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandHaltData, MessageCommandHaltFunction } from '../classes/builders/MessageCommandBuilder';
|
|
2
|
-
import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandHaltData, SlashCommandHaltFunction } from '../classes/builders/SlashCommandBuilder';
|
|
3
|
-
import { Awaitable } from 'discord.js';
|
|
1
|
+
import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandExecuteFunction, MessageCommandHaltData, MessageCommandHaltFunction } from '../classes/builders/MessageCommandBuilder';
|
|
2
|
+
import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandExecuteFunction, SlashCommandHaltData, SlashCommandHaltFunction } from '../classes/builders/SlashCommandBuilder';
|
|
3
|
+
import { Awaitable, PermissionResolvable, RestOrArray } from 'discord.js';
|
|
4
4
|
/**
|
|
5
5
|
* Any Reciple command builders
|
|
6
6
|
*/
|
|
@@ -13,6 +13,10 @@ export declare type AnyCommandExecuteData = SlashCommandExecuteData | MessageCom
|
|
|
13
13
|
* Any Reciple command halt functions
|
|
14
14
|
*/
|
|
15
15
|
export declare type AnyCommandHaltFunction = SlashCommandHaltFunction | MessageCommandHaltFunction;
|
|
16
|
+
/**
|
|
17
|
+
* Any reciple command execute function
|
|
18
|
+
*/
|
|
19
|
+
export declare type AnyCommandExecuteFunction = SlashCommandExecuteFunction | MessageCommandExecuteFunction;
|
|
16
20
|
/**
|
|
17
21
|
* Reciple command halt function
|
|
18
22
|
*/
|
|
@@ -28,3 +32,41 @@ export declare enum CommandBuilderType {
|
|
|
28
32
|
MessageCommand = 0,
|
|
29
33
|
SlashCommand = 1
|
|
30
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Shared command builder methods
|
|
37
|
+
*/
|
|
38
|
+
export interface SharedCommandBuilderProperties {
|
|
39
|
+
readonly type: CommandBuilderType;
|
|
40
|
+
cooldown: number;
|
|
41
|
+
requiredBotPermissions: PermissionResolvable[];
|
|
42
|
+
requiredMemberPermissions: PermissionResolvable[];
|
|
43
|
+
allowExecuteInDM: boolean;
|
|
44
|
+
halt?: AnyCommandHaltFunction;
|
|
45
|
+
execute: AnyCommandExecuteFunction;
|
|
46
|
+
/**
|
|
47
|
+
* Sets the execute cooldown for this command.
|
|
48
|
+
* - `0` means no cooldown
|
|
49
|
+
* @param cooldown Command cooldown in milliseconds
|
|
50
|
+
*/
|
|
51
|
+
setCooldown(cooldown: number): this;
|
|
52
|
+
/**
|
|
53
|
+
* Set required bot permissions to execute the command
|
|
54
|
+
* @param permissions Bot's required permissions
|
|
55
|
+
*/
|
|
56
|
+
setRequiredBotPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
57
|
+
/**
|
|
58
|
+
* Set required permissions to execute the command
|
|
59
|
+
* @param permissions User's return permissions
|
|
60
|
+
*/
|
|
61
|
+
setRequiredMemberPermissions(...permissions: RestOrArray<PermissionResolvable>): this;
|
|
62
|
+
/**
|
|
63
|
+
* Function when the command is interupted
|
|
64
|
+
* @param halt Function to execute when command is halted
|
|
65
|
+
*/
|
|
66
|
+
setHalt(halt?: this["halt"]): this;
|
|
67
|
+
/**
|
|
68
|
+
* Function when the command is executed
|
|
69
|
+
* @param execute Function to execute when the command is called
|
|
70
|
+
*/
|
|
71
|
+
setExecute(execute: this["execute"]): this;
|
|
72
|
+
}
|
package/package.json
CHANGED
package/resource/reciple.yml
CHANGED
|
@@ -60,7 +60,7 @@ fileLogging:
|
|
|
60
60
|
# stringify logged JSONs
|
|
61
61
|
stringifyLoggedJSON: false
|
|
62
62
|
# log file path
|
|
63
|
-
logFilePath:
|
|
63
|
+
logFilePath:
|
|
64
64
|
|
|
65
65
|
# Client options
|
|
66
66
|
# Learn more about client options at https://discord.js.org/#/docs/discord.js/main/typedef/ClientOptions
|