reciple 5.6.0 → 6.0.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/cjs/bin.js +9 -10
  2. package/dist/cjs/index.js +7 -6
  3. package/dist/cjs/reciple/classes/RecipleClient.js +87 -181
  4. package/dist/cjs/reciple/classes/RecipleConfig.js +9 -2
  5. package/dist/cjs/reciple/classes/builders/MessageCommandBuilder.js +6 -4
  6. package/dist/cjs/reciple/classes/builders/SlashCommandBuilder.js +14 -22
  7. package/dist/cjs/reciple/classes/managers/ApplicationCommandManager.js +137 -0
  8. package/dist/cjs/reciple/classes/managers/ClientCommandManager.js +60 -0
  9. package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +193 -0
  10. package/dist/cjs/reciple/classes/{CommandCooldownManager.js → managers/CommandCooldownManager.js} +15 -6
  11. package/dist/cjs/reciple/classes/{MessageCommandOptionManager.js → managers/MessageCommandOptionManager.js} +0 -0
  12. package/dist/cjs/reciple/logger.js +10 -8
  13. package/dist/cjs/reciple/permissions.js +3 -4
  14. package/dist/cjs/reciple/util.js +10 -1
  15. package/dist/types/index.d.ts +7 -6
  16. package/dist/types/reciple/classes/RecipleClient.d.ts +17 -65
  17. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +2 -2
  18. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +12 -12
  19. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +20 -0
  20. package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +37 -0
  21. package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +79 -0
  22. package/dist/types/reciple/classes/{CommandCooldownManager.d.ts → managers/CommandCooldownManager.d.ts} +3 -2
  23. package/dist/types/reciple/classes/{MessageCommandOptionManager.d.ts → managers/MessageCommandOptionManager.d.ts} +1 -1
  24. package/dist/types/reciple/types/builders.d.ts +13 -13
  25. package/dist/types/reciple/types/commands.d.ts +2 -2
  26. package/dist/types/reciple/types/paramOptions.d.ts +8 -19
  27. package/dist/types/reciple/util.d.ts +2 -0
  28. package/package.json +21 -16
  29. package/dist/cjs/reciple/modules.js +0 -113
  30. package/dist/cjs/reciple/registerApplicationCommands.js +0 -49
  31. package/dist/types/reciple/modules.d.ts +0 -64
  32. package/dist/types/reciple/registerApplicationCommands.d.ts +0 -9
package/dist/cjs/bin.js CHANGED
@@ -12,7 +12,6 @@ const flags_1 = require("./reciple/flags");
12
12
  const fallout_utility_1 = require("fallout-utility");
13
13
  const chalk_1 = __importDefault(require("chalk"));
14
14
  require("dotenv/config");
15
- const discord_js_1 = require("discord.js");
16
15
  const path_1 = __importDefault(require("path"));
17
16
  const allowedFiles = ['node_modules', 'reciple.yml', 'package.json'];
18
17
  const configPath = path_1.default.join(flags_1.cwd, './reciple.yml');
@@ -31,21 +30,21 @@ catch (err) {
31
30
  }
32
31
  const config = configParser.getConfig();
33
32
  const client = new RecipleClient_1.RecipleClient({ config: config, ...config.client });
34
- if (config.fileLogging.clientLogs)
33
+ if (!client.isClientLogsSilent)
35
34
  client.logger.info('Starting Reciple client v' + version_1.rawVersion);
36
35
  (async () => {
37
- await client.startModules((0, discord_js_1.normalizeArray)([config.modulesFolder]));
36
+ client.addCommandListeners();
37
+ await client.modules.startModulesFromFiles({
38
+ files: await client.modules.getModuleFiles(),
39
+ });
38
40
  client.on('ready', async () => {
39
- if (client.isClientLogsEnabled())
41
+ await client.modules.loadAll(true);
42
+ if (!client.isClientLogsSilent)
40
43
  client.logger.warn(`Logged in as ${client.user?.tag || 'Unknown'}!`);
41
- client.on('cacheSweep', () => {
42
- client.cooldowns.clean();
43
- });
44
- await client.loadModules();
45
- client.addCommandListeners();
44
+ client.on('cacheSweep', () => client.cooldowns.clean());
46
45
  });
47
46
  client.login(config.token).catch(err => {
48
- if (client.isClientLogsEnabled())
47
+ if (!client.isClientLogsSilent)
49
48
  client.logger.error(err);
50
49
  });
51
50
  })();
package/dist/cjs/index.js CHANGED
@@ -14,20 +14,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./reciple/classes/CommandCooldownManager"), exports);
18
- __exportStar(require("./reciple/classes/MessageCommandOptionManager"), exports);
19
- __exportStar(require("./reciple/classes/RecipleClient"), exports);
20
- __exportStar(require("./reciple/classes/RecipleConfig"), exports);
21
17
  __exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), exports);
22
18
  __exportStar(require("./reciple/classes/builders/MessageCommandOptionBuilder"), exports);
23
19
  __exportStar(require("./reciple/classes/builders/SlashCommandBuilder"), exports);
20
+ __exportStar(require("./reciple/classes/managers/ApplicationCommandManager"), exports);
21
+ __exportStar(require("./reciple/classes/managers/CommandCooldownManager"), exports);
22
+ __exportStar(require("./reciple/classes/managers/ClientCommandManager"), exports);
23
+ __exportStar(require("./reciple/classes/managers/ClientModuleManager"), exports);
24
+ __exportStar(require("./reciple/classes/managers/MessageCommandOptionManager"), exports);
25
+ __exportStar(require("./reciple/classes/RecipleClient"), exports);
26
+ __exportStar(require("./reciple/classes/RecipleConfig"), exports);
24
27
  __exportStar(require("./reciple/types/builders"), exports);
25
28
  __exportStar(require("./reciple/types/commands"), exports);
26
29
  __exportStar(require("./reciple/types/paramOptions"), exports);
27
30
  __exportStar(require("./reciple/flags"), exports);
28
31
  __exportStar(require("./reciple/logger"), exports);
29
- __exportStar(require("./reciple/modules"), exports);
30
32
  __exportStar(require("./reciple/permissions"), exports);
31
- __exportStar(require("./reciple/registerApplicationCommands"), exports);
32
33
  __exportStar(require("./reciple/util"), exports);
33
34
  __exportStar(require("./reciple/version"), exports);
@@ -5,22 +5,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RecipleClient = void 0;
7
7
  const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
8
+ const discord_js_1 = require("discord.js");
8
9
  const SlashCommandBuilder_1 = require("./builders/SlashCommandBuilder");
9
- const builders_1 = require("../types/builders");
10
- const registerApplicationCommands_1 = require("../registerApplicationCommands");
11
10
  const commands_1 = require("../types/commands");
11
+ const CommandCooldownManager_1 = require("./managers/CommandCooldownManager");
12
12
  const permissions_1 = require("../permissions");
13
- const CommandCooldownManager_1 = require("./CommandCooldownManager");
14
- const MessageCommandOptionManager_1 = require("./MessageCommandOptionManager");
13
+ const MessageCommandOptionManager_1 = require("./managers/MessageCommandOptionManager");
14
+ const ApplicationCommandManager_1 = require("./managers/ApplicationCommandManager");
15
+ const builders_1 = require("../types/builders");
16
+ const ClientCommandManager_1 = require("./managers/ClientCommandManager");
17
+ const ClientModuleManager_1 = require("./managers/ClientModuleManager");
15
18
  const RecipleConfig_1 = require("./RecipleConfig");
16
- const modules_1 = require("../modules");
17
19
  const fallout_utility_1 = require("fallout-utility");
18
20
  const logger_1 = require("../logger");
19
21
  const version_1 = require("../version");
20
22
  const flags_1 = require("../flags");
21
23
  const path_1 = __importDefault(require("path"));
22
- const discord_js_1 = require("discord.js");
23
- const util_1 = require("../util");
24
24
  class RecipleClient extends discord_js_1.Client {
25
25
  /**
26
26
  * @param options Client options
@@ -28,136 +28,32 @@ class RecipleClient extends discord_js_1.Client {
28
28
  constructor(options) {
29
29
  super(options);
30
30
  this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
31
- this.commands = { slashCommands: new discord_js_1.Collection(), messageCommands: new discord_js_1.Collection() };
32
- this.additionalApplicationCommands = [];
31
+ this.commands = new ClientCommandManager_1.ClientCommandManager({
32
+ client: this,
33
+ });
33
34
  this.cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
34
- this.modules = [];
35
+ this.modules = new ClientModuleManager_1.ClientModuleManager({
36
+ client: this,
37
+ });
35
38
  this.version = version_1.version;
36
39
  this.logger = (0, logger_1.createLogger)(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
37
40
  this.config = { ...this.config, ...(options.config ?? {}) };
38
41
  if (this.config.fileLogging.enabled)
39
42
  this.logger.logFile(path_1.default.join(flags_1.cwd, this.config.fileLogging.logFilePath ?? 'logs/latest.log'), false);
43
+ this.applicationCommands = new ApplicationCommandManager_1.ApplicationCommandManager(this);
40
44
  }
41
- /**
42
- * Load and start modules from given folders
43
- * @param folders folders that contains the modules you want to load
44
- */
45
- async startModules(...folders) {
46
- folders = (0, discord_js_1.normalizeArray)(folders).map(f => path_1.default.join(flags_1.cwd, f));
47
- for (const folder of folders) {
48
- if (this.isClientLogsEnabled())
49
- this.logger.info(`Loading Modules from ${folder}`);
50
- const modules = await (0, modules_1.getModules)(this, folder).catch(() => null);
51
- if (!modules) {
52
- if (this.isClientLogsEnabled())
53
- this.logger.error(`Failed to load modules from ${folder}`);
54
- continue;
55
- }
56
- this.modules.push(...modules.modules);
57
- }
58
- return this;
59
- }
60
- /**
61
- * Execute {@link RecipleModule['onLoad']} from client modules and register application commands if enabled
62
- */
63
- async loadModules() {
64
- if (!this.isReady())
65
- throw new Error('Client is not ready');
66
- for (const m in this.modules) {
67
- const index = (m);
68
- const module_ = this.modules[index];
69
- try {
70
- if (typeof module_.script?.onLoad === 'function') {
71
- await Promise.resolve(module_.script.onLoad(this)).catch(err => {
72
- if (this.isClientLogsEnabled()) {
73
- this.logger.error(`Error loading ${module_.info.filename ?? 'unknown module'}:`);
74
- this.logger.error(err);
75
- }
76
- this.modules.splice(index);
77
- });
78
- }
79
- }
80
- catch (err) {
81
- if (this.isClientLogsEnabled()) {
82
- this.logger.error(`Error loading ${module_.info.filename ?? 'unknown module'}:`);
83
- this.logger.error(err);
84
- }
85
- this.modules.splice(index);
86
- }
87
- if (module_.script?.commands && Array.isArray(module_.script?.commands)) {
88
- for (const command of module_.script.commands) {
89
- this.addCommand(command);
90
- }
91
- }
92
- }
93
- if (this.isClientLogsEnabled()) {
94
- this.logger.info(`${this.modules.length} modules loaded.`);
95
- this.logger.info(`${this.commands.messageCommands.size} message commands loaded.`);
96
- this.logger.info(`${this.commands.slashCommands.size} slash commands loaded.`);
97
- }
98
- if (this.config.commands.slashCommand.registerCommands)
99
- await this.registerClientApplicationCommands();
100
- return this;
101
- }
102
- /**
103
- * Add module
104
- * @param options Module options
105
- * @deprecated This is very stupid, Just add it manually
106
- */
107
- async addModule(options) {
108
- (0, util_1.deprecationWarning)('Add modules manually It\'s not that hard');
109
- // TODO: DEPRECATED!
110
- const { script } = options;
111
- const registerCommands = options.registerApplicationCommands;
112
- const info = options.moduleInfo;
113
- if (!this.isReady())
114
- throw new Error('Client is not ready');
115
- this.modules.push({
116
- script,
117
- info: {
118
- filename: undefined,
119
- versions: typeof script.versions == 'string' ? [script.versions] : script.versions,
120
- path: undefined,
121
- ...info
122
- }
123
- });
124
- if (typeof script?.onLoad === 'function')
125
- await Promise.resolve(script.onLoad(this));
126
- if (this.isClientLogsEnabled())
127
- this.logger.info(`${this.modules.length} modules loaded.`);
128
- for (const command of script.commands ?? []) {
129
- if (!command.name)
130
- continue;
131
- this.addCommand(command);
132
- }
133
- if (registerCommands)
134
- await this.registerClientApplicationCommands();
135
- }
136
- /**
137
- * Add slash or message command to client
138
- * @param command Slash/Message command builder
139
- */
140
- addCommand(command) {
141
- if (command.type === builders_1.CommandBuilderType.SlashCommand) {
142
- this.commands.slashCommands.set(command.name, SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
143
- }
144
- else if (command.type === builders_1.CommandBuilderType.MessageCommand) {
145
- this.commands.messageCommands.set(command.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
146
- }
147
- else if (this.isClientLogsEnabled()) {
148
- this.logger.error(`Unknow command "${typeof command ?? 'unknown'}".`);
149
- }
150
- return this;
45
+ get isClientLogsSilent() {
46
+ return !this.config.fileLogging.clientLogs;
151
47
  }
152
48
  /**
153
49
  * Listed to command executions
154
50
  */
155
51
  addCommandListeners() {
156
- this.on('messageCreate', (message) => {
52
+ this.on('messageCreate', message => {
157
53
  if (this.config.commands.messageCommand.enabled)
158
54
  this.messageCommandExecute(message);
159
55
  });
160
- this.on('interactionCreate', (interaction) => {
56
+ this.on('interactionCreate', interaction => {
161
57
  if (this.config.commands.slashCommand.enabled)
162
58
  this.slashCommandExecute(interaction);
163
59
  });
@@ -172,23 +68,26 @@ class RecipleClient extends discord_js_1.Client {
172
68
  return;
173
69
  if (!this.config.commands.slashCommand.acceptRepliedInteractions && (interaction.replied || interaction.deferred))
174
70
  return;
175
- const command = this.findCommand(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
71
+ const command = this.commands.get(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
176
72
  if (!command)
177
73
  return;
178
74
  const executeData = {
179
75
  interaction,
180
76
  builder: command,
181
- client: this
77
+ client: this,
182
78
  };
183
79
  if ((0, permissions_1.userHasCommandPermissions)({
184
80
  builder: command,
185
81
  memberPermissions: interaction.memberPermissions ?? undefined,
186
- commandPermissions: this.config.commands.slashCommand.permissions
82
+ commandPermissions: this.config.commands.slashCommand.permissions,
187
83
  })) {
188
84
  if (!command)
189
85
  return;
190
86
  if (interaction.inCachedGuild() && !(0, permissions_1.botHasExecutePermissions)(interaction.channel || interaction.guild, command.requiredBotPermissions)) {
191
- if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions })) {
87
+ if (!(await this._haltCommand(command, {
88
+ executeData,
89
+ reason: commands_1.CommandHaltReason.MissingBotPermissions,
90
+ }))) {
192
91
  await interaction.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
193
92
  }
194
93
  return;
@@ -198,20 +97,30 @@ class RecipleClient extends discord_js_1.Client {
198
97
  command: command.name,
199
98
  channel: interaction.channel ?? undefined,
200
99
  guild: interaction.guild,
201
- type: builders_1.CommandBuilderType.SlashCommand
100
+ type: builders_1.CommandBuilderType.SlashCommand,
202
101
  };
203
102
  if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
204
- this.cooldowns.add({ ...userCooldown, expireTime: Date.now() + command.cooldown });
103
+ this.cooldowns.add({
104
+ ...userCooldown,
105
+ expireTime: Date.now() + command.cooldown,
106
+ });
205
107
  }
206
108
  else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
207
- if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Cooldown, ...this.cooldowns.get(userCooldown) })) {
109
+ if (!(await this._haltCommand(command, {
110
+ executeData,
111
+ reason: commands_1.CommandHaltReason.Cooldown,
112
+ ...this.cooldowns.get(userCooldown),
113
+ }))) {
208
114
  await interaction.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
209
115
  }
210
116
  return;
211
117
  }
212
118
  return this._executeCommand(command, executeData);
213
119
  }
214
- else if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions })) {
120
+ else if (!(await this._haltCommand(command, {
121
+ executeData,
122
+ reason: commands_1.CommandHaltReason.MissingMemberPermissions,
123
+ }))) {
215
124
  await interaction.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
216
125
  }
217
126
  }
@@ -226,7 +135,7 @@ class RecipleClient extends discord_js_1.Client {
226
135
  const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
227
136
  if (!parseCommand || !parseCommand?.command)
228
137
  return;
229
- const command = this.findCommand(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
138
+ const command = this.commands.get(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
230
139
  if (!command)
231
140
  return;
232
141
  const commandOptions = await (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
@@ -235,31 +144,42 @@ class RecipleClient extends discord_js_1.Client {
235
144
  options: commandOptions,
236
145
  command: parseCommand,
237
146
  builder: command,
238
- client: this
147
+ client: this,
239
148
  };
240
149
  if ((0, permissions_1.userHasCommandPermissions)({
241
150
  builder: command,
242
151
  memberPermissions: message.member?.permissions,
243
- commandPermissions: this.config.commands.messageCommand.permissions
152
+ commandPermissions: this.config.commands.messageCommand.permissions,
244
153
  })) {
245
- if (!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM || !command.allowExecuteByBots && (message.author.bot || message.author.system))
154
+ if ((!command.allowExecuteInDM && message.channel.type === discord_js_1.ChannelType.DM) || (!command.allowExecuteByBots && (message.author.bot || message.author.system)))
246
155
  return;
247
156
  if (command.validateOptions) {
248
157
  if (commandOptions.some(o => o.invalid)) {
249
- if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.InvalidArguments, invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)) })) {
158
+ if (!(await this._haltCommand(command, {
159
+ executeData,
160
+ reason: commands_1.CommandHaltReason.InvalidArguments,
161
+ invalidArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.invalid)),
162
+ }))) {
250
163
  message.reply(this.getConfigMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
251
164
  }
252
165
  return;
253
166
  }
254
167
  if (commandOptions.some(o => o.missing)) {
255
- if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingArguments, missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)) })) {
168
+ if (!(await this._haltCommand(command, {
169
+ executeData,
170
+ reason: commands_1.CommandHaltReason.MissingArguments,
171
+ missingArguments: new MessageCommandOptionManager_1.MessageCommandOptionManager(...executeData.options.filter(o => o.missing)),
172
+ }))) {
256
173
  message.reply(this.getConfigMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
257
174
  }
258
175
  return;
259
176
  }
260
177
  }
261
178
  if (message.inGuild() && !(0, permissions_1.botHasExecutePermissions)(message.channel || message.guild, command.requiredBotPermissions)) {
262
- if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingBotPermissions })) {
179
+ if (!(await this._haltCommand(command, {
180
+ executeData,
181
+ reason: commands_1.CommandHaltReason.MissingBotPermissions,
182
+ }))) {
263
183
  message.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
264
184
  }
265
185
  return;
@@ -269,34 +189,33 @@ class RecipleClient extends discord_js_1.Client {
269
189
  command: command.name,
270
190
  channel: message.channel,
271
191
  guild: message.guild,
272
- type: builders_1.CommandBuilderType.MessageCommand
192
+ type: builders_1.CommandBuilderType.MessageCommand,
273
193
  };
274
194
  if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
275
- this.cooldowns.add({ ...userCooldown, expireTime: Date.now() + command.cooldown });
195
+ this.cooldowns.add({
196
+ ...userCooldown,
197
+ expireTime: Date.now() + command.cooldown,
198
+ });
276
199
  }
277
200
  else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
278
- if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.Cooldown, ...this.cooldowns.get(userCooldown) })) {
201
+ if (!(await this._haltCommand(command, {
202
+ executeData,
203
+ reason: commands_1.CommandHaltReason.Cooldown,
204
+ ...this.cooldowns.get(userCooldown),
205
+ }))) {
279
206
  await message.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
280
207
  }
281
208
  return;
282
209
  }
283
210
  return this._executeCommand(command, executeData);
284
211
  }
285
- else if (!await this._haltCommand(command, { executeData, reason: commands_1.CommandHaltReason.MissingMemberPermissions })) {
212
+ else if (!(await this._haltCommand(command, {
213
+ executeData,
214
+ reason: commands_1.CommandHaltReason.MissingMemberPermissions,
215
+ }))) {
286
216
  message.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
287
217
  }
288
218
  }
289
- /**
290
- * Registers client slash commands and other application commands
291
- */
292
- async registerClientApplicationCommands() {
293
- await (0, registerApplicationCommands_1.registerApplicationCommands)({
294
- client: this,
295
- commands: [...this.commands.slashCommands.toJSON(), ...this.additionalApplicationCommands],
296
- guilds: this.config.commands.slashCommand.guilds
297
- });
298
- this.emit('recipleRegisterApplicationCommands');
299
- }
300
219
  /**
301
220
  * Get a message from config
302
221
  * @param messageKey Config messages key
@@ -305,25 +224,6 @@ class RecipleClient extends discord_js_1.Client {
305
224
  getConfigMessage(messageKey, defaultMessage) {
306
225
  return this.config.messages[messageKey] ?? defaultMessage ?? messageKey;
307
226
  }
308
- findCommand(command, type) {
309
- switch (type) {
310
- case builders_1.CommandBuilderType.SlashCommand:
311
- return this.commands.slashCommands.get(command);
312
- case builders_1.CommandBuilderType.MessageCommand:
313
- return this.commands.messageCommands.get(command.toLowerCase())
314
- ?? (this.config.commands.messageCommand.allowCommandAlias
315
- ? this.commands.messageCommands.find(c => c.aliases.some(a => a == command?.toLowerCase()))
316
- : undefined);
317
- default:
318
- throw new TypeError('Unknown command type');
319
- }
320
- }
321
- /**
322
- * Returns true if client logs is enabled
323
- */
324
- isClientLogsEnabled() {
325
- return !!this.config.fileLogging.clientLogs;
326
- }
327
227
  /**
328
228
  * Emits the {@link RecipleClientEvents["recipleReplyError"]} event
329
229
  * @param error Received Error
@@ -334,15 +234,15 @@ class RecipleClient extends discord_js_1.Client {
334
234
  async _haltCommand(command, haltData) {
335
235
  try {
336
236
  const haltResolved = (command.halt
337
- ? await Promise.resolve(command.type == builders_1.CommandBuilderType.SlashCommand
338
- ? command.halt(haltData)
339
- : command.halt(haltData)).catch(err => { console.log(err); })
237
+ ? await Promise.resolve(command.type == builders_1.CommandBuilderType.SlashCommand ? command.halt(haltData) : command.halt(haltData)).catch(err => {
238
+ console.log(err);
239
+ })
340
240
  : false) || false;
341
241
  this.emit('recipleCommandHalt', haltData);
342
242
  return haltResolved;
343
243
  }
344
244
  catch (err) {
345
- if (this.isClientLogsEnabled()) {
245
+ if (!this.isClientLogsSilent) {
346
246
  this.logger.error(`An error occured executing command halt for "${command.name}"`);
347
247
  this.logger.error(err);
348
248
  }
@@ -351,17 +251,23 @@ class RecipleClient extends discord_js_1.Client {
351
251
  }
352
252
  async _executeCommand(command, executeData) {
353
253
  try {
354
- await Promise.resolve(command.type === builders_1.CommandBuilderType.SlashCommand
355
- ? command.execute(executeData)
356
- : command.execute(executeData))
254
+ await Promise.resolve(command.type === builders_1.CommandBuilderType.SlashCommand ? command.execute(executeData) : command.execute(executeData))
357
255
  .then(() => this.emit('recipleCommandExecute', executeData))
358
- .catch(async (err) => !await this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err })
256
+ .catch(async (err) => !(await this._haltCommand(command, {
257
+ executeData: executeData,
258
+ reason: commands_1.CommandHaltReason.Error,
259
+ error: err,
260
+ }))
359
261
  ? this._commandExecuteError(err, executeData)
360
262
  : void 0);
361
263
  return executeData;
362
264
  }
363
265
  catch (err) {
364
- if (await this._haltCommand(command, { executeData: executeData, reason: commands_1.CommandHaltReason.Error, error: err }))
266
+ if (await this._haltCommand(command, {
267
+ executeData: executeData,
268
+ reason: commands_1.CommandHaltReason.Error,
269
+ error: err,
270
+ }))
365
271
  return;
366
272
  await this._commandExecuteError(err, executeData);
367
273
  }
@@ -372,7 +278,7 @@ class RecipleClient extends discord_js_1.Client {
372
278
  * @param command Slash/Message command execute data
373
279
  */
374
280
  async _commandExecuteError(err, command) {
375
- if (this.isClientLogsEnabled()) {
281
+ if (!this.isClientLogsSilent) {
376
282
  this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandBuilderType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
377
283
  this.logger.error(err);
378
284
  }
@@ -84,14 +84,21 @@ class RecipleConfig {
84
84
  * Ask for a token
85
85
  */
86
86
  _askToken() {
87
- return flags_1.token || (0, fallout_utility_1.input)({ text: 'Bot Token >>> ', echo: '*', repeatIfEmpty: true, sigint: true }) || null;
87
+ return (flags_1.token ||
88
+ (0, fallout_utility_1.input)({
89
+ text: 'Bot Token >>> ',
90
+ echo: '*',
91
+ repeatIfEmpty: true,
92
+ sigint: true,
93
+ }) ||
94
+ null);
88
95
  }
89
96
  /**
90
97
  * Get default config
91
98
  */
92
99
  static getDefaultConfig() {
93
100
  if (!(0, fs_1.existsSync)(this.defaultConfigPath))
94
- throw new Error("Default config file does not exists.");
101
+ throw new Error('Default config file does not exists.');
95
102
  return yaml_1.default.parse((0, fs_1.readFileSync)(this.defaultConfigPath, 'utf-8'));
96
103
  }
97
104
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
4
4
  const builders_1 = require("../../types/builders");
5
5
  const discord_js_1 = require("discord.js");
6
- const MessageCommandOptionManager_1 = require("../MessageCommandOptionManager");
6
+ const MessageCommandOptionManager_1 = require("../managers/MessageCommandOptionManager");
7
7
  const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
8
8
  /**
9
9
  * Reciple builder for message command
@@ -21,7 +21,9 @@ class MessageCommandBuilder {
21
21
  this.requiredMemberPermissions = [];
22
22
  this.allowExecuteInDM = true;
23
23
  this.allowExecuteByBots = false;
24
- this.execute = () => { };
24
+ this.execute = () => {
25
+ /* Execute */
26
+ };
25
27
  if (data?.name !== undefined)
26
28
  this.setName(data.name);
27
29
  if (data?.description !== undefined)
@@ -47,7 +49,7 @@ class MessageCommandBuilder {
47
49
  if (data?.validateOptions !== undefined)
48
50
  this.setValidateOptions(true);
49
51
  if (data?.options !== undefined)
50
- this.options = data.options.map(o => o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o));
52
+ this.options = data.options.map(o => (o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o)));
51
53
  }
52
54
  /**
53
55
  * Sets the command name
@@ -218,7 +220,7 @@ async function validateMessageCommandOptions(builder, options) {
218
220
  value: arg ?? undefined,
219
221
  required: option.required,
220
222
  invalid: false,
221
- missing: false
223
+ missing: false,
222
224
  };
223
225
  if (arg == undefined && option.required) {
224
226
  value.missing = true;
@@ -14,7 +14,9 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
14
14
  this.cooldown = 0;
15
15
  this.requiredBotPermissions = [];
16
16
  this.requiredMemberPermissions = [];
17
- this.execute = () => { };
17
+ this.execute = () => {
18
+ /* Execute */
19
+ };
18
20
  // TODO: WTH
19
21
  if (data?.name !== undefined)
20
22
  this.setName(data.name);
@@ -58,9 +60,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
58
60
  }
59
61
  setRequiredMemberPermissions(...permissions) {
60
62
  this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
61
- this.setDefaultMemberPermissions(this.requiredMemberPermissions.length
62
- ? new discord_js_1.PermissionsBitField(this.requiredMemberPermissions).bitfield
63
- : undefined);
63
+ this.setDefaultMemberPermissions(this.requiredMemberPermissions.length ? new discord_js_1.PermissionsBitField(this.requiredMemberPermissions).bitfield : undefined);
64
64
  return this;
65
65
  }
66
66
  setHalt(halt) {
@@ -135,13 +135,10 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
135
135
  builder = new discord_js_1.SlashCommandBooleanOption();
136
136
  break;
137
137
  case discord_js_1.ApplicationCommandOptionType.Channel:
138
- builder = new discord_js_1.SlashCommandChannelOption()
139
- .addChannelTypes(...(option.channelTypes ?? []));
138
+ builder = new discord_js_1.SlashCommandChannelOption().addChannelTypes(...(option.channelTypes ?? []));
140
139
  break;
141
140
  case discord_js_1.ApplicationCommandOptionType.Integer:
142
- builder = new discord_js_1.SlashCommandIntegerOption()
143
- .addChoices(...(option.choices ?? []))
144
- .setAutocomplete(!!option.autocomplete);
141
+ builder = new discord_js_1.SlashCommandIntegerOption().addChoices(...(option.choices ?? [])).setAutocomplete(!!option.autocomplete);
145
142
  if (option.maxValue)
146
143
  builder.setMaxValue(option.maxValue);
147
144
  if (option.minValue)
@@ -151,9 +148,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
151
148
  builder = new discord_js_1.SlashCommandMentionableOption();
152
149
  break;
153
150
  case discord_js_1.ApplicationCommandOptionType.Number:
154
- builder = new discord_js_1.SlashCommandNumberOption()
155
- .addChoices(...(option.choices ?? []))
156
- .setAutocomplete(!!option.autocomplete);
151
+ builder = new discord_js_1.SlashCommandNumberOption().addChoices(...(option.choices ?? [])).setAutocomplete(!!option.autocomplete);
157
152
  if (option.maxValue)
158
153
  builder.setMaxValue(option.maxValue);
159
154
  if (option.minValue)
@@ -163,9 +158,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
163
158
  builder = new discord_js_1.SlashCommandRoleOption();
164
159
  break;
165
160
  case discord_js_1.ApplicationCommandOptionType.String:
166
- builder = new discord_js_1.SlashCommandStringOption()
167
- .addChoices(...(option.choices ?? []))
168
- .setAutocomplete(!!option.autocomplete);
161
+ builder = new discord_js_1.SlashCommandStringOption().addChoices(...(option.choices ?? [])).setAutocomplete(!!option.autocomplete);
169
162
  if (option.maxLength)
170
163
  builder.setMaxLength(option.maxLength);
171
164
  if (option.minLength)
@@ -183,17 +176,16 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
183
176
  case discord_js_1.ApplicationCommandOptionType.SubcommandGroup:
184
177
  builder = new discord_js_1.SlashCommandSubcommandGroupBuilder();
185
178
  for (const subCommandData of option.options) {
186
- builder.addSubcommand(subCommandData instanceof discord_js_1.SlashCommandSubcommandBuilder
187
- ? subCommandData
188
- : this.resolveOption(subCommandData));
179
+ builder.addSubcommand(subCommandData instanceof discord_js_1.SlashCommandSubcommandBuilder ? subCommandData : this.resolveOption(subCommandData));
189
180
  }
190
181
  break;
191
182
  default:
192
- throw new TypeError("Unknown option data");
183
+ throw new TypeError('Unknown option data');
193
184
  }
194
- if (!(builder instanceof discord_js_1.SlashCommandSubcommandBuilder) && !(builder instanceof discord_js_1.SlashCommandSubcommandGroupBuilder)
195
- &&
196
- option.type !== discord_js_1.ApplicationCommandOptionType.Subcommand && option.type !== discord_js_1.ApplicationCommandOptionType.SubcommandGroup) {
185
+ if (!(builder instanceof discord_js_1.SlashCommandSubcommandBuilder) &&
186
+ !(builder instanceof discord_js_1.SlashCommandSubcommandGroupBuilder) &&
187
+ option.type !== discord_js_1.ApplicationCommandOptionType.Subcommand &&
188
+ option.type !== discord_js_1.ApplicationCommandOptionType.SubcommandGroup) {
197
189
  builder.setRequired(option.required ?? false);
198
190
  }
199
191
  return builder