reciple 6.0.0-dev.1 → 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 (33) hide show
  1. package/dist/cjs/bin.js +11 -7
  2. package/dist/cjs/index.js +3 -3
  3. package/dist/cjs/reciple/classes/RecipleClient.js +86 -45
  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 +6 -4
  7. package/dist/cjs/reciple/classes/builders/SlashCommandBuilder.js +12 -23
  8. package/dist/cjs/reciple/classes/managers/ApplicationCommandManager.js +32 -33
  9. package/dist/cjs/reciple/classes/managers/ClientCommandManager.js +14 -14
  10. package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +93 -115
  11. package/dist/cjs/reciple/classes/managers/CommandCooldownManager.js +7 -1
  12. package/dist/cjs/reciple/permissions.js +3 -4
  13. package/dist/cjs/reciple/types/builders.js +6 -6
  14. package/dist/cjs/reciple/util.js +36 -2
  15. package/dist/types/index.d.ts +3 -3
  16. package/dist/types/reciple/classes/RecipleClient.d.ts +3 -6
  17. package/dist/types/reciple/classes/RecipleModule.d.ts +56 -0
  18. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +6 -6
  19. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +17 -17
  20. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +6 -11
  21. package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +3 -3
  22. package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +10 -70
  23. package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +2 -2
  24. package/dist/types/reciple/types/builders.d.ts +19 -19
  25. package/dist/types/reciple/types/commands.d.ts +10 -10
  26. package/dist/types/reciple/types/paramOptions.d.ts +1 -16
  27. package/dist/types/reciple/util.d.ts +8 -0
  28. package/package.json +17 -13
  29. package/dist/cjs/reciple/logger.js +0 -35
  30. package/dist/cjs/reciple/modules.js +0 -113
  31. package/dist/types/reciple/logger.d.ts +0 -8
  32. package/dist/types/reciple/modules.d.ts +0 -64
  33. package/docs/README.md +0 -1
package/dist/cjs/bin.js CHANGED
@@ -30,21 +30,25 @@ catch (err) {
30
30
  }
31
31
  const config = configParser.getConfig();
32
32
  const client = new RecipleClient_1.RecipleClient({ config: config, ...config.client });
33
- if (config.fileLogging.clientLogs)
33
+ if (!client.isClientLogsSilent)
34
34
  client.logger.info('Starting Reciple client v' + version_1.rawVersion);
35
35
  (async () => {
36
36
  client.addCommandListeners();
37
- await client.modules.startModulesFromFiles({
38
- files: await client.modules.getModuleFiles()
39
- });
37
+ await client.modules.startModules(await client.modules.getModulesFromFiles({
38
+ files: await client.modules.getModuleFiles(),
39
+ }));
40
40
  client.on('ready', async () => {
41
- await client.modules.loadAll(true);
42
- 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)
43
47
  client.logger.warn(`Logged in as ${client.user?.tag || 'Unknown'}!`);
44
48
  client.on('cacheSweep', () => client.cooldowns.clean());
45
49
  });
46
50
  client.login(config.token).catch(err => {
47
- if (client.isClientLogsEnabled())
51
+ if (!client.isClientLogsSilent)
48
52
  client.logger.error(err);
49
53
  });
50
54
  })();
package/dist/cjs/index.js CHANGED
@@ -18,17 +18,17 @@ __exportStar(require("./reciple/classes/builders/MessageCommandBuilder"), export
18
18
  __exportStar(require("./reciple/classes/builders/MessageCommandOptionBuilder"), exports);
19
19
  __exportStar(require("./reciple/classes/builders/SlashCommandBuilder"), exports);
20
20
  __exportStar(require("./reciple/classes/managers/ApplicationCommandManager"), exports);
21
- __exportStar(require("./reciple/classes/managers/CommandCooldownManager"), exports);
22
21
  __exportStar(require("./reciple/classes/managers/ClientCommandManager"), exports);
22
+ __exportStar(require("./reciple/classes/managers/ClientModuleManager"), exports);
23
+ __exportStar(require("./reciple/classes/managers/CommandCooldownManager"), exports);
23
24
  __exportStar(require("./reciple/classes/managers/MessageCommandOptionManager"), exports);
24
25
  __exportStar(require("./reciple/classes/RecipleClient"), exports);
25
26
  __exportStar(require("./reciple/classes/RecipleConfig"), exports);
27
+ __exportStar(require("./reciple/classes/RecipleModule"), exports);
26
28
  __exportStar(require("./reciple/types/builders"), exports);
27
29
  __exportStar(require("./reciple/types/commands"), exports);
28
30
  __exportStar(require("./reciple/types/paramOptions"), exports);
29
31
  __exportStar(require("./reciple/flags"), exports);
30
- __exportStar(require("./reciple/logger"), exports);
31
- __exportStar(require("./reciple/modules"), exports);
32
32
  __exportStar(require("./reciple/permissions"), exports);
33
33
  __exportStar(require("./reciple/util"), exports);
34
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
10
  const commands_1 = require("../types/commands");
10
11
  const CommandCooldownManager_1 = require("./managers/CommandCooldownManager");
11
12
  const permissions_1 = require("../permissions");
12
13
  const MessageCommandOptionManager_1 = require("./managers/MessageCommandOptionManager");
13
14
  const ApplicationCommandManager_1 = require("./managers/ApplicationCommandManager");
14
- const builders_1 = require("../types/builders");
15
15
  const ClientCommandManager_1 = require("./managers/ClientCommandManager");
16
+ const ClientModuleManager_1 = require("./managers/ClientModuleManager");
17
+ const builders_1 = require("../types/builders");
16
18
  const RecipleConfig_1 = require("./RecipleConfig");
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 ClientModuleManager_1 = require("./managers/ClientModuleManager");
24
24
  class RecipleClient extends discord_js_1.Client {
25
25
  /**
26
26
  * @param options Client options
@@ -28,25 +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 = new ClientCommandManager_1.ClientCommandManager({ client: this });
31
+ this.commands = new ClientCommandManager_1.ClientCommandManager({
32
+ client: this,
33
+ });
32
34
  this.cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
33
- this.modules = new ClientModuleManager_1.ClientModuleManager({ client: this });
35
+ this.modules = new ClientModuleManager_1.ClientModuleManager({
36
+ client: this,
37
+ });
34
38
  this.version = version_1.version;
35
- 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);
36
40
  this.config = { ...this.config, ...(options.config ?? {}) };
37
41
  if (this.config.fileLogging.enabled)
38
42
  this.logger.logFile(path_1.default.join(flags_1.cwd, this.config.fileLogging.logFilePath ?? 'logs/latest.log'), false);
39
43
  this.applicationCommands = new ApplicationCommandManager_1.ApplicationCommandManager(this);
40
44
  }
45
+ get isClientLogsSilent() {
46
+ return !this.config.fileLogging.clientLogs;
47
+ }
41
48
  /**
42
49
  * Listed to command executions
43
50
  */
44
51
  addCommandListeners() {
45
- this.on('messageCreate', (message) => {
52
+ this.on('messageCreate', message => {
46
53
  if (this.config.commands.messageCommand.enabled)
47
54
  this.messageCommandExecute(message);
48
55
  });
49
- this.on('interactionCreate', (interaction) => {
56
+ this.on('interactionCreate', interaction => {
50
57
  if (this.config.commands.slashCommand.enabled)
51
58
  this.slashCommandExecute(interaction);
52
59
  });
@@ -61,23 +68,26 @@ class RecipleClient extends discord_js_1.Client {
61
68
  return;
62
69
  if (!this.config.commands.slashCommand.acceptRepliedInteractions && (interaction.replied || interaction.deferred))
63
70
  return;
64
- const command = this.commands.get(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
71
+ const command = this.commands.get(interaction.commandName, builders_1.CommandType.SlashCommand);
65
72
  if (!command)
66
73
  return;
67
74
  const executeData = {
68
75
  interaction,
69
76
  builder: command,
70
- client: this
77
+ client: this,
71
78
  };
72
79
  if ((0, permissions_1.userHasCommandPermissions)({
73
80
  builder: command,
74
81
  memberPermissions: interaction.memberPermissions ?? undefined,
75
- commandPermissions: this.config.commands.slashCommand.permissions
82
+ commandPermissions: this.config.commands.slashCommand.permissions,
76
83
  })) {
77
84
  if (!command)
78
85
  return;
79
86
  if (interaction.inCachedGuild() && !(0, permissions_1.botHasExecutePermissions)(interaction.channel || interaction.guild, command.requiredBotPermissions)) {
80
- 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
+ }))) {
81
91
  await interaction.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
82
92
  }
83
93
  return;
@@ -87,20 +97,30 @@ class RecipleClient extends discord_js_1.Client {
87
97
  command: command.name,
88
98
  channel: interaction.channel ?? undefined,
89
99
  guild: interaction.guild,
90
- type: builders_1.CommandBuilderType.SlashCommand
100
+ type: builders_1.CommandType.SlashCommand,
91
101
  };
92
102
  if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
93
- this.cooldowns.add({ ...userCooldown, expireTime: Date.now() + command.cooldown });
103
+ this.cooldowns.add({
104
+ ...userCooldown,
105
+ expireTime: Date.now() + command.cooldown,
106
+ });
94
107
  }
95
108
  else if (this.config.commands.slashCommand.enableCooldown && command.cooldown) {
96
- 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
+ }))) {
97
114
  await interaction.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
98
115
  }
99
116
  return;
100
117
  }
101
118
  return this._executeCommand(command, executeData);
102
119
  }
103
- 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
+ }))) {
104
124
  await interaction.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
105
125
  }
106
126
  }
@@ -115,7 +135,7 @@ class RecipleClient extends discord_js_1.Client {
115
135
  const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
116
136
  if (!parseCommand || !parseCommand?.command)
117
137
  return;
118
- const command = this.commands.get(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
138
+ const command = this.commands.get(parseCommand.command, builders_1.CommandType.MessageCommand);
119
139
  if (!command)
120
140
  return;
121
141
  const commandOptions = await (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
@@ -124,31 +144,42 @@ class RecipleClient extends discord_js_1.Client {
124
144
  options: commandOptions,
125
145
  command: parseCommand,
126
146
  builder: command,
127
- client: this
147
+ client: this,
128
148
  };
129
149
  if ((0, permissions_1.userHasCommandPermissions)({
130
150
  builder: command,
131
151
  memberPermissions: message.member?.permissions,
132
- commandPermissions: this.config.commands.messageCommand.permissions
152
+ commandPermissions: this.config.commands.messageCommand.permissions,
133
153
  })) {
134
- 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)))
135
155
  return;
136
156
  if (command.validateOptions) {
137
157
  if (commandOptions.some(o => o.invalid)) {
138
- 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
+ }))) {
139
163
  message.reply(this.getConfigMessage('invalidArguments', 'Invalid argument(s) given.')).catch(er => this._replyError(er));
140
164
  }
141
165
  return;
142
166
  }
143
167
  if (commandOptions.some(o => o.missing)) {
144
- 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
+ }))) {
145
173
  message.reply(this.getConfigMessage('missingArguments', 'Not enough arguments.')).catch(er => this._replyError(er));
146
174
  }
147
175
  return;
148
176
  }
149
177
  }
150
178
  if (message.inGuild() && !(0, permissions_1.botHasExecutePermissions)(message.channel || message.guild, command.requiredBotPermissions)) {
151
- 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
+ }))) {
152
183
  message.reply(this.getConfigMessage('insufficientBotPerms', 'Insufficient bot permissions.')).catch(er => this._replyError(er));
153
184
  }
154
185
  return;
@@ -158,20 +189,30 @@ class RecipleClient extends discord_js_1.Client {
158
189
  command: command.name,
159
190
  channel: message.channel,
160
191
  guild: message.guild,
161
- type: builders_1.CommandBuilderType.MessageCommand
192
+ type: builders_1.CommandType.MessageCommand,
162
193
  };
163
194
  if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
164
- this.cooldowns.add({ ...userCooldown, expireTime: Date.now() + command.cooldown });
195
+ this.cooldowns.add({
196
+ ...userCooldown,
197
+ expireTime: Date.now() + command.cooldown,
198
+ });
165
199
  }
166
200
  else if (this.config.commands.messageCommand.enableCooldown && command.cooldown) {
167
- 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
+ }))) {
168
206
  await message.reply(this.getConfigMessage('cooldown', 'You cannot execute this command right now due to the cooldown.')).catch(er => this._replyError(er));
169
207
  }
170
208
  return;
171
209
  }
172
210
  return this._executeCommand(command, executeData);
173
211
  }
174
- 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
+ }))) {
175
216
  message.reply(this.getConfigMessage('noPermissions', 'You do not have permission to use this command.')).catch(er => this._replyError(er));
176
217
  }
177
218
  }
@@ -183,12 +224,6 @@ class RecipleClient extends discord_js_1.Client {
183
224
  getConfigMessage(messageKey, defaultMessage) {
184
225
  return this.config.messages[messageKey] ?? defaultMessage ?? messageKey;
185
226
  }
186
- /**
187
- * Returns true if client logs is enabled
188
- */
189
- isClientLogsEnabled() {
190
- return !!this.config.fileLogging.clientLogs;
191
- }
192
227
  /**
193
228
  * Emits the {@link RecipleClientEvents["recipleReplyError"]} event
194
229
  * @param error Received Error
@@ -199,15 +234,15 @@ class RecipleClient extends discord_js_1.Client {
199
234
  async _haltCommand(command, haltData) {
200
235
  try {
201
236
  const haltResolved = (command.halt
202
- ? await Promise.resolve(command.type == builders_1.CommandBuilderType.SlashCommand
203
- ? command.halt(haltData)
204
- : 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
+ })
205
240
  : false) || false;
206
241
  this.emit('recipleCommandHalt', haltData);
207
242
  return haltResolved;
208
243
  }
209
244
  catch (err) {
210
- if (this.isClientLogsEnabled()) {
245
+ if (!this.isClientLogsSilent) {
211
246
  this.logger.error(`An error occured executing command halt for "${command.name}"`);
212
247
  this.logger.error(err);
213
248
  }
@@ -216,17 +251,23 @@ class RecipleClient extends discord_js_1.Client {
216
251
  }
217
252
  async _executeCommand(command, executeData) {
218
253
  try {
219
- await Promise.resolve(command.type === builders_1.CommandBuilderType.SlashCommand
220
- ? command.execute(executeData)
221
- : command.execute(executeData))
254
+ await Promise.resolve(command.type === builders_1.CommandType.SlashCommand ? command.execute(executeData) : command.execute(executeData))
222
255
  .then(() => this.emit('recipleCommandExecute', executeData))
223
- .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
+ }))
224
261
  ? this._commandExecuteError(err, executeData)
225
262
  : void 0);
226
263
  return executeData;
227
264
  }
228
265
  catch (err) {
229
- 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
+ }))
230
271
  return;
231
272
  await this._commandExecuteError(err, executeData);
232
273
  }
@@ -237,8 +278,8 @@ class RecipleClient extends discord_js_1.Client {
237
278
  * @param command Slash/Message command execute data
238
279
  */
239
280
  async _commandExecuteError(err, command) {
240
- if (this.isClientLogsEnabled()) {
241
- 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}"`);
242
283
  this.logger.error(err);
243
284
  }
244
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;
@@ -10,7 +10,7 @@ const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
10
10
  */
11
11
  class MessageCommandBuilder {
12
12
  constructor(data) {
13
- this.type = builders_1.CommandBuilderType.MessageCommand;
13
+ this.type = builders_1.CommandType.MessageCommand;
14
14
  this.name = '';
15
15
  this.description = '';
16
16
  this.cooldown = 0;
@@ -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;
@@ -10,11 +10,13 @@ const discord_js_1 = require("discord.js");
10
10
  class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
11
11
  constructor(data) {
12
12
  super();
13
- this.type = builders_1.CommandBuilderType.SlashCommand;
13
+ this.type = builders_1.CommandType.SlashCommand;
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,13 @@ 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) && !(builder instanceof discord_js_1.SlashCommandSubcommandGroupBuilder) && option.type !== discord_js_1.ApplicationCommandOptionType.Subcommand && option.type !== discord_js_1.ApplicationCommandOptionType.SubcommandGroup) {
197
186
  builder.setRequired(option.required ?? false);
198
187
  }
199
188
  return builder