reciple 5.6.0 → 6.0.0-dev.10

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 (37) hide show
  1. package/dist/cjs/bin.js +13 -10
  2. package/dist/cjs/index.js +8 -7
  3. package/dist/cjs/reciple/classes/RecipleClient.js +90 -184
  4. package/dist/cjs/reciple/classes/RecipleConfig.js +9 -2
  5. package/dist/cjs/reciple/classes/RecipleModule.js +94 -0
  6. package/dist/cjs/reciple/classes/builders/MessageCommandBuilder.js +7 -5
  7. package/dist/cjs/reciple/classes/builders/SlashCommandBuilder.js +12 -23
  8. package/dist/cjs/reciple/classes/managers/ApplicationCommandManager.js +136 -0
  9. package/dist/cjs/reciple/classes/managers/ClientCommandManager.js +62 -0
  10. package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +167 -0
  11. package/dist/cjs/reciple/classes/{CommandCooldownManager.js → managers/CommandCooldownManager.js} +15 -6
  12. package/dist/cjs/reciple/classes/{MessageCommandOptionManager.js → managers/MessageCommandOptionManager.js} +0 -0
  13. package/dist/cjs/reciple/permissions.js +3 -4
  14. package/dist/cjs/reciple/types/builders.js +6 -6
  15. package/dist/cjs/reciple/util.js +44 -1
  16. package/dist/types/index.d.ts +8 -7
  17. package/dist/types/reciple/classes/RecipleClient.d.ts +17 -65
  18. package/dist/types/reciple/classes/RecipleModule.d.ts +56 -0
  19. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +7 -7
  20. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +17 -17
  21. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +15 -0
  22. package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +37 -0
  23. package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +19 -0
  24. package/dist/types/reciple/classes/{CommandCooldownManager.d.ts → managers/CommandCooldownManager.d.ts} +4 -3
  25. package/dist/types/reciple/classes/{MessageCommandOptionManager.d.ts → managers/MessageCommandOptionManager.d.ts} +1 -1
  26. package/dist/types/reciple/types/builders.d.ts +19 -19
  27. package/dist/types/reciple/types/commands.d.ts +12 -12
  28. package/dist/types/reciple/types/paramOptions.d.ts +6 -32
  29. package/dist/types/reciple/util.d.ts +10 -0
  30. package/package.json +30 -24
  31. package/dist/cjs/reciple/logger.js +0 -35
  32. package/dist/cjs/reciple/modules.js +0 -113
  33. package/dist/cjs/reciple/registerApplicationCommands.js +0 -49
  34. package/dist/types/reciple/logger.d.ts +0 -8
  35. package/dist/types/reciple/modules.d.ts +0 -64
  36. package/dist/types/reciple/registerApplicationCommands.d.ts +0 -9
  37. package/docs/README.md +0 -1
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,25 @@ 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.startModules(await client.modules.getModulesFromFiles({
38
+ files: await client.modules.getModuleFiles(),
39
+ }));
38
40
  client.on('ready', async () => {
39
- if (client.isClientLogsEnabled())
41
+ await client.modules.loadModules(client.modules.modules.toJSON(), true);
42
+ if (!client.isClientLogsSilent)
43
+ client.logger.log(`Loaded ${client.commands.slashCommands.size} slash commands`, `Loaded ${client.commands.messageCommands.size} message commands`);
44
+ if (client.config.commands.slashCommand.registerCommands)
45
+ await client.commands.registerApplicationCommands();
46
+ if (!client.isClientLogsSilent)
40
47
  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();
48
+ client.on('cacheSweep', () => client.cooldowns.clean());
46
49
  });
47
50
  client.login(config.token).catch(err => {
48
- if (client.isClientLogsEnabled())
51
+ if (!client.isClientLogsSilent)
49
52
  client.logger.error(err);
50
53
  });
51
54
  })();
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/ClientCommandManager"), exports);
22
+ __exportStar(require("./reciple/classes/managers/ClientModuleManager"), exports);
23
+ __exportStar(require("./reciple/classes/managers/CommandCooldownManager"), exports);
24
+ __exportStar(require("./reciple/classes/managers/MessageCommandOptionManager"), exports);
25
+ __exportStar(require("./reciple/classes/RecipleClient"), exports);
26
+ __exportStar(require("./reciple/classes/RecipleConfig"), exports);
27
+ __exportStar(require("./reciple/classes/RecipleModule"), exports);
24
28
  __exportStar(require("./reciple/types/builders"), exports);
25
29
  __exportStar(require("./reciple/types/commands"), exports);
26
30
  __exportStar(require("./reciple/types/paramOptions"), exports);
27
31
  __exportStar(require("./reciple/flags"), exports);
28
- __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 ClientCommandManager_1 = require("./managers/ClientCommandManager");
16
+ const ClientModuleManager_1 = require("./managers/ClientModuleManager");
17
+ const builders_1 = require("../types/builders");
15
18
  const RecipleConfig_1 = require("./RecipleConfig");
16
- const modules_1 = require("../modules");
17
19
  const fallout_utility_1 = require("fallout-utility");
18
- const logger_1 = require("../logger");
20
+ const util_1 = require("../util");
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
- this.logger = (0, logger_1.createLogger)(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
39
+ this.logger = (0, util_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.CommandType.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.CommandType.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.CommandType.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.CommandType.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.CommandType.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.CommandType.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,8 +278,8 @@ 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()) {
376
- this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandBuilderType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
281
+ if (!this.isClientLogsSilent) {
282
+ this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
377
283
  this.logger.error(err);
378
284
  }
379
285
  if (!err || !command)
@@ -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
  }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecipleModule = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const discord_js_1 = require("discord.js");
6
+ const builders_1 = require("../types/builders");
7
+ const util_1 = require("../util");
8
+ const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
9
+ const SlashCommandBuilder_1 = require("./builders/SlashCommandBuilder");
10
+ class RecipleModule {
11
+ constructor(options) {
12
+ this.commands = [];
13
+ this.id = (0, crypto_1.randomUUID)();
14
+ this.client = options.client;
15
+ this.script = options.script;
16
+ this.filePath = options.filePath;
17
+ this.metadata = options.metadata;
18
+ }
19
+ get displayName() {
20
+ return this.filePath ?? this.id;
21
+ }
22
+ async start() {
23
+ return Promise.resolve(this.script.onStart(this.client));
24
+ }
25
+ async load(resolveCommands = true) {
26
+ if (typeof this.script.onLoad === 'function')
27
+ await this.script.onLoad(this.client);
28
+ if (resolveCommands)
29
+ this.resolveCommands();
30
+ }
31
+ async unLoad(reason) {
32
+ if (typeof this.script.onUnLoad === 'function')
33
+ await this.script.onUnLoad(reason, this.client);
34
+ }
35
+ async registerSlashCommands(...guilds) {
36
+ for (const command of this.commands) {
37
+ if (command.type !== builders_1.CommandType.SlashCommand)
38
+ continue;
39
+ await this.client.applicationCommands.add(command, (0, discord_js_1.normalizeArray)(guilds));
40
+ }
41
+ }
42
+ async unregisterSlashCommands(...guilds) {
43
+ for (const builder of this.commands) {
44
+ if (builder.type !== builders_1.CommandType.SlashCommand)
45
+ continue;
46
+ if ((0, discord_js_1.normalizeArray)(guilds).length) {
47
+ for (const guild of (0, discord_js_1.normalizeArray)(guilds)) {
48
+ const command = this.client.applicationCommands.get(builder, guild);
49
+ if (command)
50
+ await this.client.applicationCommands.remove(command, guild);
51
+ }
52
+ continue;
53
+ }
54
+ const command = this.client.applicationCommands.get(builder);
55
+ if (command)
56
+ await this.client.applicationCommands.remove(command);
57
+ }
58
+ }
59
+ async updateSlashCommands(...guilds) {
60
+ for (const builder of this.commands) {
61
+ if (builder.type !== builders_1.CommandType.SlashCommand)
62
+ continue;
63
+ if ((0, discord_js_1.normalizeArray)(guilds).length) {
64
+ for (const guild of (0, discord_js_1.normalizeArray)(guilds)) {
65
+ const command = this.client.applicationCommands.get(builder, guild);
66
+ if (command)
67
+ await this.client.applicationCommands.edit(command, builder, guild);
68
+ }
69
+ continue;
70
+ }
71
+ const command = this.client.applicationCommands.get(builder);
72
+ if (command)
73
+ await this.client.applicationCommands.edit(command, builder);
74
+ }
75
+ }
76
+ resolveCommands() {
77
+ if (!Array.isArray(this.script?.commands))
78
+ return this.commands;
79
+ for (const command of this.script.commands) {
80
+ if (command?.type !== builders_1.CommandType.SlashCommand && command?.type !== builders_1.CommandType.MessageCommand)
81
+ continue;
82
+ const builder = command.type === builders_1.CommandType.SlashCommand ? SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command) : MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command);
83
+ if (!(0, util_1.validateCommandBuilder)(builder))
84
+ throw new Error('Invalid command builder, no name or contains option(s) without name');
85
+ this.commands.push(builder);
86
+ }
87
+ this.client.commands.add(this.commands);
88
+ return this.commands;
89
+ }
90
+ toString() {
91
+ return this.displayName;
92
+ }
93
+ }
94
+ exports.RecipleModule = RecipleModule;