reciple 5.4.1-pre.5 → 5.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/{types/bin.d.ts → bin.d.ts} +0 -0
- package/bin/{cjs/bin.js → bin.js} +11 -22
- package/bin/{types/index.d.ts → index.d.ts} +0 -0
- package/bin/{cjs/index.js → index.js} +0 -0
- package/bin/{types/reciple → reciple}/classes/CommandCooldownManager.d.ts +0 -0
- package/bin/{mjs/reciple → reciple}/classes/CommandCooldownManager.js +12 -8
- package/bin/{types/reciple → reciple}/classes/MessageCommandOptionManager.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/classes/MessageCommandOptionManager.js +4 -5
- package/bin/{types/reciple → reciple}/classes/RecipleClient.d.ts +4 -4
- package/bin/{mjs/reciple → reciple}/classes/RecipleClient.js +68 -61
- package/bin/{types/reciple → reciple}/classes/RecipleConfig.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/classes/RecipleConfig.js +6 -9
- package/bin/{types/reciple → reciple}/classes/builders/MessageCommandBuilder.d.ts +0 -0
- package/bin/{mjs/reciple → reciple}/classes/builders/MessageCommandBuilder.js +22 -17
- package/bin/{types/reciple → reciple}/classes/builders/MessageCommandOptionBuilder.d.ts +0 -0
- package/bin/{mjs/reciple → reciple}/classes/builders/MessageCommandOptionBuilder.js +5 -1
- package/bin/{types/reciple → reciple}/classes/builders/SlashCommandBuilder.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/classes/builders/SlashCommandBuilder.js +29 -29
- package/bin/{types/reciple → reciple}/flags.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/flags.js +0 -0
- package/bin/{types/reciple → reciple}/logger.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/logger.js +1 -2
- package/bin/{types/reciple → reciple}/modules.d.ts +0 -0
- package/bin/reciple/modules.js +113 -0
- package/bin/{types/reciple → reciple}/permissions.d.ts +6 -2
- package/bin/reciple/permissions.js +34 -0
- package/bin/{types/reciple → reciple}/registerApplicationCommands.d.ts +0 -0
- package/bin/{mjs/reciple → reciple}/registerApplicationCommands.js +9 -5
- package/bin/{types/reciple → reciple}/types/builders.d.ts +1 -1
- package/bin/{cjs/reciple → reciple}/types/builders.js +0 -0
- package/bin/{types/reciple → reciple}/types/commands.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/types/commands.js +0 -0
- package/bin/{types/reciple → reciple}/types/paramOptions.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/types/paramOptions.js +0 -0
- package/bin/{types/reciple → reciple}/util.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/util.js +0 -0
- package/bin/{types/reciple → reciple}/version.d.ts +0 -0
- package/bin/{cjs/reciple → reciple}/version.js +0 -0
- package/package.json +10 -14
- package/bin/cjs/package.json +0 -3
- package/bin/cjs/reciple/classes/CommandCooldownManager.js +0 -92
- package/bin/cjs/reciple/classes/RecipleClient.js +0 -400
- package/bin/cjs/reciple/classes/builders/MessageCommandBuilder.js +0 -233
- package/bin/cjs/reciple/classes/builders/MessageCommandOptionBuilder.js +0 -71
- package/bin/cjs/reciple/modules.js +0 -100
- package/bin/cjs/reciple/permissions.js +0 -28
- package/bin/cjs/reciple/registerApplicationCommands.js +0 -64
- package/bin/mjs/bin.js +0 -46
- package/bin/mjs/index.js +0 -17
- package/bin/mjs/package.json +0 -3
- package/bin/mjs/reciple/classes/MessageCommandOptionManager.js +0 -21
- package/bin/mjs/reciple/classes/RecipleConfig.js +0 -92
- package/bin/mjs/reciple/classes/builders/SlashCommandBuilder.js +0 -204
- package/bin/mjs/reciple/flags.js +0 -28
- package/bin/mjs/reciple/logger.js +0 -28
- package/bin/mjs/reciple/modules.js +0 -81
- package/bin/mjs/reciple/permissions.js +0 -23
- package/bin/mjs/reciple/types/builders.js +0 -8
- package/bin/mjs/reciple/types/commands.js +0 -12
- package/bin/mjs/reciple/types/paramOptions.js +0 -1
- package/bin/mjs/reciple/util.js +0 -7
- package/bin/mjs/reciple/version.js +0 -38
|
@@ -1,400 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.RecipleClient = void 0;
|
|
16
|
-
const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
|
|
17
|
-
const SlashCommandBuilder_1 = require("./builders/SlashCommandBuilder");
|
|
18
|
-
const builders_1 = require("../types/builders");
|
|
19
|
-
const registerApplicationCommands_1 = require("../registerApplicationCommands");
|
|
20
|
-
const commands_1 = require("../types/commands");
|
|
21
|
-
const permissions_1 = require("../permissions");
|
|
22
|
-
const CommandCooldownManager_1 = require("./CommandCooldownManager");
|
|
23
|
-
const MessageCommandOptionManager_1 = require("./MessageCommandOptionManager");
|
|
24
|
-
const fallout_utility_1 = require("fallout-utility");
|
|
25
|
-
const RecipleConfig_1 = require("./RecipleConfig");
|
|
26
|
-
const modules_1 = require("../modules");
|
|
27
|
-
const logger_1 = require("../logger");
|
|
28
|
-
const version_1 = require("../version");
|
|
29
|
-
const flags_1 = require("../flags");
|
|
30
|
-
const path_1 = __importDefault(require("path"));
|
|
31
|
-
const discord_js_1 = require("discord.js");
|
|
32
|
-
class RecipleClient extends discord_js_1.Client {
|
|
33
|
-
/**
|
|
34
|
-
* @param options Client options
|
|
35
|
-
*/
|
|
36
|
-
constructor(options) {
|
|
37
|
-
var _a, _b, _c, _d;
|
|
38
|
-
super(options);
|
|
39
|
-
this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
|
|
40
|
-
this.commands = { slashCommands: {}, messageCommands: {} };
|
|
41
|
-
this.additionalApplicationCommands = [];
|
|
42
|
-
this.cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
|
|
43
|
-
this.modules = [];
|
|
44
|
-
this.version = version_1.version;
|
|
45
|
-
this.logger = (0, logger_1.createLogger)(!!((_a = options.config) === null || _a === void 0 ? void 0 : _a.fileLogging.stringifyLoggedJSON), (_b = options.config) === null || _b === void 0 ? void 0 : _b.fileLogging.debugmode);
|
|
46
|
-
if (!options.config)
|
|
47
|
-
throw new Error('Config is not defined.');
|
|
48
|
-
this.config = Object.assign(Object.assign({}, this.config), ((_c = options.config) !== null && _c !== void 0 ? _c : {}));
|
|
49
|
-
if (this.config.fileLogging.enabled)
|
|
50
|
-
this.logger.logFile(path_1.default.join(flags_1.cwd, (_d = this.config.fileLogging.logFilePath) !== null && _d !== void 0 ? _d : 'logs/latest.log'), false);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Load modules from modules folder
|
|
54
|
-
* @param folders List of folders that contains the modules you want to load
|
|
55
|
-
*/
|
|
56
|
-
startModules(...folders) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
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.push(...modules.modules);
|
|
69
|
-
}
|
|
70
|
-
return this;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Execute `onLoad()` from client modules and register application commands if enabled
|
|
75
|
-
*/
|
|
76
|
-
loadModules() {
|
|
77
|
-
var _a, _b;
|
|
78
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
for (const m in this.modules) {
|
|
80
|
-
const module_ = this.modules[m];
|
|
81
|
-
if (typeof ((_a = module_.script) === null || _a === void 0 ? void 0 : _a.onLoad) === 'function') {
|
|
82
|
-
yield Promise.resolve(module_.script.onLoad(this)).catch(err => {
|
|
83
|
-
var _a;
|
|
84
|
-
if (this.isClientLogsEnabled()) {
|
|
85
|
-
this.logger.error(`Error loading ${(_a = module_.info.filename) !== null && _a !== void 0 ? _a : 'unknown module'}:`);
|
|
86
|
-
this.logger.error(err);
|
|
87
|
-
}
|
|
88
|
-
this.modules = this.modules.filter((_r, i) => i.toString() !== m.toString());
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if (typeof ((_b = module_.script) === null || _b === void 0 ? void 0 : _b.commands) !== 'undefined') {
|
|
92
|
-
for (const command of module_.script.commands) {
|
|
93
|
-
this.addCommand(command);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (this.isClientLogsEnabled()) {
|
|
98
|
-
this.logger.info(`${this.modules.length} modules loaded.`);
|
|
99
|
-
this.logger.info(`${Object.keys(this.commands.messageCommands).length} message commands loaded.`);
|
|
100
|
-
this.logger.info(`${Object.keys(this.commands.slashCommands).length} slash commands loaded.`);
|
|
101
|
-
}
|
|
102
|
-
if (this.config.commands.slashCommand.registerCommands) {
|
|
103
|
-
yield (0, registerApplicationCommands_1.registerApplicationCommands)({
|
|
104
|
-
client: this,
|
|
105
|
-
commands: [...Object.values(this.commands.slashCommands), ...this.additionalApplicationCommands],
|
|
106
|
-
guilds: this.config.commands.slashCommand.guilds
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
return this;
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Add module
|
|
114
|
-
* @param options Module options
|
|
115
|
-
*/
|
|
116
|
-
addModule(options) {
|
|
117
|
-
var _a;
|
|
118
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
-
const { script } = options;
|
|
120
|
-
const registerCommands = options.registerApplicationCommands;
|
|
121
|
-
const info = options.moduleInfo;
|
|
122
|
-
this.modules.push({
|
|
123
|
-
script,
|
|
124
|
-
info: Object.assign({ filename: undefined, versions: typeof script.versions == 'string' ? [script.versions] : script.versions, path: undefined }, info)
|
|
125
|
-
});
|
|
126
|
-
if (typeof (script === null || script === void 0 ? void 0 : script.onLoad) === 'function')
|
|
127
|
-
yield Promise.resolve(script.onLoad(this));
|
|
128
|
-
if (this.isClientLogsEnabled())
|
|
129
|
-
this.logger.info(`${this.modules.length} modules loaded.`);
|
|
130
|
-
for (const command of (_a = script.commands) !== null && _a !== void 0 ? _a : []) {
|
|
131
|
-
if (!command.name)
|
|
132
|
-
continue;
|
|
133
|
-
this.addCommand(command);
|
|
134
|
-
}
|
|
135
|
-
if (registerCommands)
|
|
136
|
-
yield (0, registerApplicationCommands_1.registerApplicationCommands)({
|
|
137
|
-
client: this,
|
|
138
|
-
commands: [...Object.values(this.commands.slashCommands), ...this.additionalApplicationCommands],
|
|
139
|
-
guilds: this.config.commands.slashCommand.guilds
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Add slash or message command to client
|
|
145
|
-
* @param command Slash/Message command builder
|
|
146
|
-
*/
|
|
147
|
-
addCommand(command) {
|
|
148
|
-
var _a;
|
|
149
|
-
if (command.type === builders_1.CommandBuilderType.SlashCommand) {
|
|
150
|
-
this.commands.slashCommands[command.name] = SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command);
|
|
151
|
-
}
|
|
152
|
-
else if (command.type === builders_1.CommandBuilderType.MessageCommand) {
|
|
153
|
-
this.commands.messageCommands[command.name] = MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command);
|
|
154
|
-
}
|
|
155
|
-
else if (this.isClientLogsEnabled()) {
|
|
156
|
-
this.logger.error(`Unknow command "${(_a = typeof command) !== null && _a !== void 0 ? _a : 'unknown'}".`);
|
|
157
|
-
}
|
|
158
|
-
return this;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Listed to command executions
|
|
162
|
-
*/
|
|
163
|
-
addCommandListeners() {
|
|
164
|
-
if (this.config.commands.messageCommand.enabled)
|
|
165
|
-
this.on('messageCreate', (message) => { this.messageCommandExecute(message); });
|
|
166
|
-
if (this.config.commands.slashCommand.enabled)
|
|
167
|
-
this.on('interactionCreate', (interaction) => { this.slashCommandExecute(interaction); });
|
|
168
|
-
return this;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Execute a slash command
|
|
172
|
-
* @param interaction Slash command interaction
|
|
173
|
-
*/
|
|
174
|
-
slashCommandExecute(interaction) {
|
|
175
|
-
var _a, _b;
|
|
176
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
-
if (!interaction || !interaction.isChatInputCommand() || !this.isReady())
|
|
178
|
-
return;
|
|
179
|
-
const command = this.findCommand(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
|
|
180
|
-
if (!command)
|
|
181
|
-
return;
|
|
182
|
-
const executeData = {
|
|
183
|
-
interaction,
|
|
184
|
-
builder: command,
|
|
185
|
-
client: this
|
|
186
|
-
};
|
|
187
|
-
if ((0, permissions_1.userHasCommandPermissions)({
|
|
188
|
-
builder: command,
|
|
189
|
-
memberPermissions: (_a = interaction.memberPermissions) !== null && _a !== void 0 ? _a : undefined,
|
|
190
|
-
commandPermissions: this.config.commands.slashCommand.permissions
|
|
191
|
-
})) {
|
|
192
|
-
if (!command)
|
|
193
|
-
return;
|
|
194
|
-
if (interaction.guild && !(0, permissions_1.botHasExecutePermissions)(interaction.guild, command.requiredBotPermissions)) {
|
|
195
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
|
|
196
|
-
yield interaction.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
|
|
197
|
-
}
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
const userCooldown = {
|
|
201
|
-
user: interaction.user,
|
|
202
|
-
command: command.name,
|
|
203
|
-
channel: (_b = interaction.channel) !== null && _b !== void 0 ? _b : undefined,
|
|
204
|
-
guild: interaction.guild,
|
|
205
|
-
type: builders_1.CommandBuilderType.SlashCommand
|
|
206
|
-
};
|
|
207
|
-
if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
|
|
208
|
-
this.cooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
|
|
209
|
-
}
|
|
210
|
-
else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
|
|
211
|
-
if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.cooldowns.get(userCooldown))))) {
|
|
212
|
-
yield interaction.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
|
|
213
|
-
}
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
return this._executeCommand(command, executeData);
|
|
217
|
-
}
|
|
218
|
-
else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
|
|
219
|
-
yield interaction.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Execute a Message command
|
|
225
|
-
* @param message Message command executor
|
|
226
|
-
* @param prefix Message command prefix
|
|
227
|
-
*/
|
|
228
|
-
messageCommandExecute(message, prefix) {
|
|
229
|
-
var _a;
|
|
230
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
-
if (!message.content || !this.isReady())
|
|
232
|
-
return;
|
|
233
|
-
const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
|
|
234
|
-
if (!parseCommand || !(parseCommand === null || parseCommand === void 0 ? void 0 : parseCommand.command))
|
|
235
|
-
return;
|
|
236
|
-
const command = this.findCommand(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
|
|
237
|
-
if (!command)
|
|
238
|
-
return;
|
|
239
|
-
const commandOptions = yield (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
|
|
240
|
-
const executeData = {
|
|
241
|
-
message: message,
|
|
242
|
-
options: commandOptions,
|
|
243
|
-
command: parseCommand,
|
|
244
|
-
builder: command,
|
|
245
|
-
client: this
|
|
246
|
-
};
|
|
247
|
-
if ((0, permissions_1.userHasCommandPermissions)({
|
|
248
|
-
builder: command,
|
|
249
|
-
memberPermissions: (_a = message.member) === null || _a === void 0 ? void 0 : _a.permissions,
|
|
250
|
-
commandPermissions: this.config.commands.messageCommand.permissions
|
|
251
|
-
})) {
|
|
252
|
-
if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM || !command.allowExecuteByBots && (message.author.bot || message.author.system))
|
|
253
|
-
return;
|
|
254
|
-
if (command.validateOptions) {
|
|
255
|
-
if (commandOptions.some(o => o.invalid)) {
|
|
256
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)) }))) {
|
|
257
|
-
message.reply(this.getConfigMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
|
|
258
|
-
}
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
if (commandOptions.some(o => o.missing)) {
|
|
262
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)) }))) {
|
|
263
|
-
message.reply(this.getConfigMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
|
|
264
|
-
}
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (message.guild && !(0, permissions_1.botHasExecutePermissions)(message.guild, command.requiredBotPermissions)) {
|
|
269
|
-
if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions }))) {
|
|
270
|
-
message.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
|
|
271
|
-
}
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
const userCooldown = {
|
|
275
|
-
user: message.author,
|
|
276
|
-
command: command.name,
|
|
277
|
-
channel: message.channel,
|
|
278
|
-
guild: message.guild,
|
|
279
|
-
type: builders_1.CommandBuilderType.MessageCommand
|
|
280
|
-
};
|
|
281
|
-
if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
|
|
282
|
-
this.cooldowns.add(Object.assign(Object.assign({}, userCooldown), { expireTime: Date.now() + command.cooldown }));
|
|
283
|
-
}
|
|
284
|
-
else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
|
|
285
|
-
if (!(yield this._haltCommand(command, Object.assign({ executeData, reason: commands_1.CommandHaltReason.Cooldown }, this.cooldowns.get(userCooldown))))) {
|
|
286
|
-
yield message.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
|
|
287
|
-
}
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
return this._executeCommand(command, executeData);
|
|
291
|
-
}
|
|
292
|
-
else if (!(yield this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions }))) {
|
|
293
|
-
message.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Get a message from config
|
|
299
|
-
* @param messageKey Config messages key
|
|
300
|
-
* @param defaultMessage Default message when the key does not exists
|
|
301
|
-
*/
|
|
302
|
-
getConfigMessage(messageKey, defaultMessage) {
|
|
303
|
-
var _a, _b;
|
|
304
|
-
return (_b = (_a = this.config.messages[messageKey]) !== null && _a !== void 0 ? _a : defaultMessage) !== null && _b !== void 0 ? _b : messageKey;
|
|
305
|
-
}
|
|
306
|
-
findCommand(command, type) {
|
|
307
|
-
var _a;
|
|
308
|
-
switch (type) {
|
|
309
|
-
case builders_1.CommandBuilderType.SlashCommand:
|
|
310
|
-
return this.commands.slashCommands[command];
|
|
311
|
-
case builders_1.CommandBuilderType.MessageCommand:
|
|
312
|
-
return (_a = this.commands.messageCommands[command.toLowerCase()]) !== null && _a !== void 0 ? _a : (this.config.commands.messageCommand.allowCommandAlias
|
|
313
|
-
? Object.values(this.commands.messageCommands).find(c => c.aliases.some(a => a == (command === null || command === void 0 ? void 0 : command.toLowerCase())))
|
|
314
|
-
: undefined);
|
|
315
|
-
default:
|
|
316
|
-
throw new TypeError('Unknown command type');
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Returns true if client logs is enabled
|
|
321
|
-
*/
|
|
322
|
-
isClientLogsEnabled() {
|
|
323
|
-
return !!this.config.fileLogging.clientLogs;
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Emits the "recipleReplyError" event
|
|
327
|
-
* @param error Received Error
|
|
328
|
-
*/
|
|
329
|
-
_replyError(error) {
|
|
330
|
-
this.emit('recipleReplyError', error);
|
|
331
|
-
}
|
|
332
|
-
_haltCommand(command, haltData) {
|
|
333
|
-
var _a;
|
|
334
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
335
|
-
try {
|
|
336
|
-
const haltResolved = (_a = (command.halt
|
|
337
|
-
? yield (command.type == builders_1.CommandBuilderType.SlashCommand
|
|
338
|
-
? Promise.resolve(command.halt(haltData))
|
|
339
|
-
: Promise.resolve(command.halt(haltData))).catch(err => { throw err; })
|
|
340
|
-
: false)) !== null && _a !== void 0 ? _a : false;
|
|
341
|
-
this.emit('recipleCommandHalt', haltData);
|
|
342
|
-
return haltResolved;
|
|
343
|
-
}
|
|
344
|
-
catch (err) {
|
|
345
|
-
if (this.isClientLogsEnabled()) {
|
|
346
|
-
this.logger.error(`An error occured executing command halt for "${command.name}"`);
|
|
347
|
-
this.logger.error(err);
|
|
348
|
-
}
|
|
349
|
-
return false;
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
_executeCommand(command, executeData) {
|
|
354
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
355
|
-
try {
|
|
356
|
-
yield Promise.resolve(command.type === builders_1.CommandBuilderType.SlashCommand
|
|
357
|
-
? command.execute(executeData)
|
|
358
|
-
: command.execute(executeData))
|
|
359
|
-
.then(() => this.emit('recipleCommandExecute', executeData))
|
|
360
|
-
.catch((err) => __awaiter(this, void 0, void 0, function* () {
|
|
361
|
-
return (yield this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err }))
|
|
362
|
-
? this._commandExecuteError(err, executeData)
|
|
363
|
-
: void 0;
|
|
364
|
-
}));
|
|
365
|
-
return executeData;
|
|
366
|
-
}
|
|
367
|
-
catch (err) {
|
|
368
|
-
if (!(yield this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err }))) {
|
|
369
|
-
this._commandExecuteError(err, executeData);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Error message when a command fails to execute
|
|
376
|
-
* @param err Received error
|
|
377
|
-
* @param command Slash/Message command execute data
|
|
378
|
-
*/
|
|
379
|
-
_commandExecuteError(err, command) {
|
|
380
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
381
|
-
if (this.isClientLogsEnabled()) {
|
|
382
|
-
this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandBuilderType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
|
|
383
|
-
this.logger.error(err);
|
|
384
|
-
}
|
|
385
|
-
if (!err || !command)
|
|
386
|
-
return;
|
|
387
|
-
if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandExecuteData(command)) {
|
|
388
|
-
if (!this.config.commands.slashCommand.replyOnError)
|
|
389
|
-
return;
|
|
390
|
-
yield command.interaction.followUp(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
|
|
391
|
-
}
|
|
392
|
-
else if (MessageCommandBuilder_1.MessageCommandBuilder.isMessageCommandExecuteData(command)) {
|
|
393
|
-
if (!this.config.commands.messageCommand.replyOnError)
|
|
394
|
-
return;
|
|
395
|
-
yield command.message.reply(this.getConfigMessage('error', 'An error occurred.')).catch(er => this._replyError(er));
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
exports.RecipleClient = RecipleClient;
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
|
|
13
|
-
const builders_1 = require("../../types/builders");
|
|
14
|
-
const discord_js_1 = require("discord.js");
|
|
15
|
-
const MessageCommandOptionManager_1 = require("../MessageCommandOptionManager");
|
|
16
|
-
const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
|
|
17
|
-
/**
|
|
18
|
-
* Reciple builder for message command
|
|
19
|
-
*/
|
|
20
|
-
class MessageCommandBuilder {
|
|
21
|
-
constructor(data) {
|
|
22
|
-
this.type = builders_1.CommandBuilderType.MessageCommand;
|
|
23
|
-
this.name = '';
|
|
24
|
-
this.description = '';
|
|
25
|
-
this.cooldown = 0;
|
|
26
|
-
this.aliases = [];
|
|
27
|
-
this.validateOptions = false;
|
|
28
|
-
this.options = [];
|
|
29
|
-
this.requiredBotPermissions = [];
|
|
30
|
-
this.requiredMemberPermissions = [];
|
|
31
|
-
this.allowExecuteInDM = true;
|
|
32
|
-
this.allowExecuteByBots = false;
|
|
33
|
-
this.execute = () => { };
|
|
34
|
-
if ((data === null || data === void 0 ? void 0 : data.name) !== undefined)
|
|
35
|
-
this.setName(data.name);
|
|
36
|
-
if ((data === null || data === void 0 ? void 0 : data.description) !== undefined)
|
|
37
|
-
this.setDescription(data.description);
|
|
38
|
-
if ((data === null || data === void 0 ? void 0 : data.cooldown) !== undefined)
|
|
39
|
-
this.setCooldown(Number(data === null || data === void 0 ? void 0 : data.cooldown));
|
|
40
|
-
if ((data === null || data === void 0 ? void 0 : data.requiredBotPermissions) !== undefined)
|
|
41
|
-
this.setRequiredBotPermissions(data.requiredBotPermissions);
|
|
42
|
-
if ((data === null || data === void 0 ? void 0 : data.requiredMemberPermissions) !== undefined)
|
|
43
|
-
this.setRequiredMemberPermissions(data.requiredMemberPermissions);
|
|
44
|
-
if ((data === null || data === void 0 ? void 0 : data.halt) !== undefined)
|
|
45
|
-
this.setHalt(this.halt);
|
|
46
|
-
if ((data === null || data === void 0 ? void 0 : data.execute) !== undefined)
|
|
47
|
-
this.setExecute(data.execute);
|
|
48
|
-
if ((data === null || data === void 0 ? void 0 : data.aliases) !== undefined)
|
|
49
|
-
this.addAliases(data.aliases);
|
|
50
|
-
if (data === null || data === void 0 ? void 0 : data.allowExecuteByBots)
|
|
51
|
-
this.setAllowExecuteByBots(true);
|
|
52
|
-
if (data === null || data === void 0 ? void 0 : data.allowExecuteInDM)
|
|
53
|
-
this.setAllowExecuteInDM(true);
|
|
54
|
-
if (data === null || data === void 0 ? void 0 : data.validateOptions)
|
|
55
|
-
this.setValidateOptions(true);
|
|
56
|
-
if ((data === null || data === void 0 ? void 0 : data.options) !== undefined)
|
|
57
|
-
this.options = data.options.map(o => o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o));
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Sets the command name
|
|
61
|
-
* @param name Command name
|
|
62
|
-
*/
|
|
63
|
-
setName(name) {
|
|
64
|
-
if (!name || typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
|
|
65
|
-
throw new TypeError('name must be a string and match the regex /^[\\w-]{1,32}$/');
|
|
66
|
-
this.name = name;
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Sets the command description
|
|
71
|
-
* @param description Command description
|
|
72
|
-
*/
|
|
73
|
-
setDescription(description) {
|
|
74
|
-
if (!description || typeof description !== 'string')
|
|
75
|
-
throw new TypeError('description must be a string.');
|
|
76
|
-
this.description = description;
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Add aliases to the command
|
|
81
|
-
* @param aliases Command aliases
|
|
82
|
-
*/
|
|
83
|
-
addAliases(...aliases) {
|
|
84
|
-
aliases = (0, discord_js_1.normalizeArray)(aliases);
|
|
85
|
-
if (!aliases.length)
|
|
86
|
-
throw new TypeError('Provide atleast one alias');
|
|
87
|
-
if (aliases.some(a => !a || typeof a !== 'string' || a.match(/^\s+$/)))
|
|
88
|
-
throw new TypeError('aliases must be strings and should not contain whitespaces');
|
|
89
|
-
if (this.name && aliases.some(a => a == this.name))
|
|
90
|
-
throw new TypeError('alias cannot have same name to its real command name');
|
|
91
|
-
this.aliases = [...new Set(aliases.map(s => s.toLowerCase()))];
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Set if command can be executed in dms
|
|
96
|
-
* @param allowExecuteInDM `true` if the command can execute in DMs
|
|
97
|
-
*/
|
|
98
|
-
setAllowExecuteInDM(allowExecuteInDM) {
|
|
99
|
-
if (typeof allowExecuteInDM !== 'boolean')
|
|
100
|
-
throw new TypeError('allowExecuteInDM must be a boolean.');
|
|
101
|
-
this.allowExecuteInDM = allowExecuteInDM;
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Allow command to be executed by bots
|
|
106
|
-
* @param allowExecuteByBots `true` if the command can be executed by bots
|
|
107
|
-
*/
|
|
108
|
-
setAllowExecuteByBots(allowExecuteByBots) {
|
|
109
|
-
if (typeof allowExecuteByBots !== 'boolean')
|
|
110
|
-
throw new TypeError('allowExecuteByBots must be a boolean.');
|
|
111
|
-
this.allowExecuteByBots = allowExecuteByBots;
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Add option to the command
|
|
116
|
-
* @param option Message option builder
|
|
117
|
-
*/
|
|
118
|
-
addOption(option) {
|
|
119
|
-
if (!option)
|
|
120
|
-
throw new TypeError('option must be a MessageOption.');
|
|
121
|
-
option = typeof option === 'function' ? option(new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder()) : option;
|
|
122
|
-
if (this.options.find(o => o.name === option.name))
|
|
123
|
-
throw new TypeError('option with name "' + option.name + '" already exists.');
|
|
124
|
-
if (this.options.length > 0 && !this.options[this.options.length - 1 < 0 ? 0 : this.options.length - 1].required && option.required)
|
|
125
|
-
throw new TypeError('All required options must be before optional options.');
|
|
126
|
-
this.options = [...this.options, option];
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Validate options before executing
|
|
131
|
-
* @param validateOptions `true` if the command options needs to be validated before executing
|
|
132
|
-
*/
|
|
133
|
-
setValidateOptions(validateOptions) {
|
|
134
|
-
if (typeof validateOptions !== 'boolean')
|
|
135
|
-
throw new TypeError('validateOptions must be a boolean.');
|
|
136
|
-
this.validateOptions = validateOptions;
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
setCooldown(cooldown) {
|
|
140
|
-
this.cooldown = cooldown;
|
|
141
|
-
return this;
|
|
142
|
-
}
|
|
143
|
-
setRequiredBotPermissions(...permissions) {
|
|
144
|
-
this.requiredBotPermissions = (0, discord_js_1.normalizeArray)(permissions);
|
|
145
|
-
return this;
|
|
146
|
-
}
|
|
147
|
-
setRequiredMemberPermissions(...permissions) {
|
|
148
|
-
this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
|
|
149
|
-
return this;
|
|
150
|
-
}
|
|
151
|
-
setHalt(halt) {
|
|
152
|
-
this.halt = halt !== null && halt !== void 0 ? halt : undefined;
|
|
153
|
-
return this;
|
|
154
|
-
}
|
|
155
|
-
setExecute(execute) {
|
|
156
|
-
if (!execute || typeof execute !== 'function')
|
|
157
|
-
throw new TypeError('execute must be a function.');
|
|
158
|
-
this.execute = execute;
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Returns JSON object of this builder
|
|
163
|
-
*/
|
|
164
|
-
toJSON() {
|
|
165
|
-
return {
|
|
166
|
-
type: this.type,
|
|
167
|
-
name: this.name,
|
|
168
|
-
description: this.description,
|
|
169
|
-
aliases: this.aliases,
|
|
170
|
-
cooldown: this.cooldown,
|
|
171
|
-
requiredBotPermissions: this.requiredBotPermissions,
|
|
172
|
-
requiredMemberPermissions: this.requiredMemberPermissions,
|
|
173
|
-
halt: this.halt,
|
|
174
|
-
execute: this.execute,
|
|
175
|
-
allowExecuteByBots: this.allowExecuteByBots,
|
|
176
|
-
allowExecuteInDM: this.allowExecuteInDM,
|
|
177
|
-
validateOptions: this.validateOptions,
|
|
178
|
-
options: this.options.map(o => o.toJSON()),
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
static resolveMessageCommand(commandData) {
|
|
182
|
-
return this.isMessageCommandBuilder(commandData) ? commandData : new MessageCommandBuilder(commandData);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Is a message command builder
|
|
186
|
-
*/
|
|
187
|
-
static isMessageCommandBuilder(builder) {
|
|
188
|
-
return builder instanceof MessageCommandBuilder;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Is a message command execute data
|
|
192
|
-
*/
|
|
193
|
-
static isMessageCommandExecuteData(executeData) {
|
|
194
|
-
return executeData.builder !== undefined && this.isMessageCommandBuilder(executeData.builder);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
exports.MessageCommandBuilder = MessageCommandBuilder;
|
|
198
|
-
function validateMessageCommandOptions(builder, options) {
|
|
199
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
200
|
-
const args = options.args || [];
|
|
201
|
-
const required = builder.options.filter(o => o.required);
|
|
202
|
-
const optional = builder.options.filter(o => !o.required);
|
|
203
|
-
const allOptions = [...required, ...optional];
|
|
204
|
-
const result = [];
|
|
205
|
-
let i = 0;
|
|
206
|
-
for (const option of allOptions) {
|
|
207
|
-
const arg = args[i];
|
|
208
|
-
const value = {
|
|
209
|
-
name: option.name,
|
|
210
|
-
value: arg !== null && arg !== void 0 ? arg : undefined,
|
|
211
|
-
required: option.required,
|
|
212
|
-
invalid: false,
|
|
213
|
-
missing: false
|
|
214
|
-
};
|
|
215
|
-
if (arg == undefined && option.required) {
|
|
216
|
-
value.missing = true;
|
|
217
|
-
result.push(value);
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
if (arg == undefined && !option.required) {
|
|
221
|
-
result.push(value);
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
const validate = option.validator ? yield Promise.resolve(option.validator(arg)) : true;
|
|
225
|
-
if (!validate)
|
|
226
|
-
value.invalid = true;
|
|
227
|
-
result.push(value);
|
|
228
|
-
i++;
|
|
229
|
-
}
|
|
230
|
-
return new MessageCommandOptionManager_1.MessageCommandOptionManager(...result);
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
exports.validateMessageCommandOptions = validateMessageCommandOptions;
|