reciple 6.0.0-dev.1 → 6.0.0-dev.12

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 (46) hide show
  1. package/dist/lib/bin.mjs +53 -0
  2. package/dist/lib/esm.mjs +1 -0
  3. package/dist/{cjs → lib}/index.js +18 -18
  4. package/dist/{cjs → lib}/reciple/classes/RecipleClient.js +88 -47
  5. package/dist/{cjs → lib}/reciple/classes/RecipleConfig.js +13 -6
  6. package/dist/lib/reciple/classes/RecipleModule.js +94 -0
  7. package/dist/{cjs → lib}/reciple/classes/builders/MessageCommandBuilder.js +6 -4
  8. package/dist/{cjs → lib}/reciple/classes/builders/MessageCommandOptionBuilder.js +0 -0
  9. package/dist/{cjs → lib}/reciple/classes/builders/SlashCommandBuilder.js +12 -23
  10. package/dist/{cjs → lib}/reciple/classes/managers/ApplicationCommandManager.js +32 -33
  11. package/dist/{cjs → lib}/reciple/classes/managers/ClientCommandManager.js +14 -14
  12. package/dist/lib/reciple/classes/managers/ClientModuleManager.js +144 -0
  13. package/dist/{cjs → lib}/reciple/classes/managers/CommandCooldownManager.js +7 -1
  14. package/dist/{cjs → lib}/reciple/classes/managers/MessageCommandOptionManager.js +0 -0
  15. package/dist/{cjs → lib}/reciple/flags.js +2 -2
  16. package/dist/{cjs → lib}/reciple/permissions.js +3 -4
  17. package/dist/lib/reciple/types/builders.js +11 -0
  18. package/dist/{cjs → lib}/reciple/types/commands.js +0 -0
  19. package/dist/{cjs → lib}/reciple/types/paramOptions.js +0 -0
  20. package/dist/lib/reciple/util.js +66 -0
  21. package/dist/{cjs → lib}/reciple/version.js +0 -1
  22. package/dist/types/{bin.d.ts → bin.d.mts} +0 -0
  23. package/dist/types/esm.d.mts +1 -0
  24. package/dist/types/index.d.ts +18 -18
  25. package/dist/types/reciple/classes/RecipleClient.d.ts +3 -6
  26. package/dist/types/reciple/classes/RecipleModule.d.ts +56 -0
  27. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +6 -6
  28. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +17 -17
  29. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +6 -11
  30. package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +3 -3
  31. package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +11 -71
  32. package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +2 -2
  33. package/dist/types/reciple/types/builders.d.ts +19 -19
  34. package/dist/types/reciple/types/commands.d.ts +10 -10
  35. package/dist/types/reciple/types/paramOptions.d.ts +7 -17
  36. package/dist/types/reciple/util.d.ts +8 -0
  37. package/package.json +28 -18
  38. package/dist/cjs/bin.js +0 -50
  39. package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +0 -189
  40. package/dist/cjs/reciple/logger.js +0 -35
  41. package/dist/cjs/reciple/modules.js +0 -113
  42. package/dist/cjs/reciple/types/builders.js +0 -11
  43. package/dist/cjs/reciple/util.js +0 -32
  44. package/dist/types/reciple/logger.d.ts +0 -8
  45. package/dist/types/reciple/modules.d.ts +0 -64
  46. package/docs/README.md +0 -1
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ import { RecipleClient } from './reciple/classes/RecipleClient.js';
3
+ import { RecipleConfig } from './reciple/classes/RecipleConfig.js';
4
+ import { rawVersion } from './reciple/version.js';
5
+ import { existsSync, readdirSync } from 'fs';
6
+ import { cwd, flags } from './reciple/flags.js';
7
+ import { input } from 'fallout-utility';
8
+ import chalk from 'chalk';
9
+ import 'dotenv/config';
10
+ import path from 'path';
11
+ import { inspect } from 'util';
12
+ const allowedFiles = ['node_modules', 'reciple.yml', 'package.json'];
13
+ const configPath = path.join(cwd, './reciple.yml');
14
+ if (readdirSync(cwd).filter(f => !f.startsWith('.') && allowedFiles.indexOf(f)).length > 0 && !existsSync(flags.config ?? configPath)) {
15
+ const ask = (flags.yes ? 'y' : null) ?? input('This directory does not contain reciple.yml. Would you like to init axis here? [y/n] ') ?? '';
16
+ if (ask.toString().toLowerCase() !== 'y')
17
+ process.exit(0);
18
+ }
19
+ let configParser;
20
+ try {
21
+ configParser = new RecipleConfig(flags.config ?? configPath).parseConfig();
22
+ }
23
+ catch (err) {
24
+ console.error(`${chalk.bold.red('Config Error')}: ${inspect(err)}`);
25
+ process.exit(1);
26
+ }
27
+ const config = configParser.getConfig();
28
+ const client = new RecipleClient({ config: config, ...config.client });
29
+ /**
30
+ * Start
31
+ */
32
+ if (!client.isClientLogsSilent)
33
+ client.logger.info('Starting Reciple client v' + rawVersion);
34
+ client.addCommandListeners();
35
+ await client.modules.startModules(await client.modules.getModulesFromFiles({
36
+ files: await client.modules.getModulePaths({
37
+ filter: file => file.endsWith('.js') || file.endsWith('.cjs') || file.endsWith('.mjs'),
38
+ }),
39
+ }));
40
+ client.on('ready', async () => {
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)
47
+ client.logger.warn(`Logged in as ${client.user?.tag || 'Unknown'}!`);
48
+ client.on('cacheSweep', () => client.cooldowns.clean());
49
+ });
50
+ client.login(config.token).catch(err => {
51
+ if (!client.isClientLogsSilent)
52
+ client.logger.error(err);
53
+ });
@@ -0,0 +1 @@
1
+ export * from './index.js';
@@ -14,21 +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/builders/MessageCommandBuilder"), exports);
18
- __exportStar(require("./reciple/classes/builders/MessageCommandOptionBuilder"), exports);
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/MessageCommandOptionManager"), exports);
24
- __exportStar(require("./reciple/classes/RecipleClient"), exports);
25
- __exportStar(require("./reciple/classes/RecipleConfig"), exports);
26
- __exportStar(require("./reciple/types/builders"), exports);
27
- __exportStar(require("./reciple/types/commands"), exports);
28
- __exportStar(require("./reciple/types/paramOptions"), exports);
29
- __exportStar(require("./reciple/flags"), exports);
30
- __exportStar(require("./reciple/logger"), exports);
31
- __exportStar(require("./reciple/modules"), exports);
32
- __exportStar(require("./reciple/permissions"), exports);
33
- __exportStar(require("./reciple/util"), exports);
34
- __exportStar(require("./reciple/version"), exports);
17
+ __exportStar(require("./reciple/classes/builders/MessageCommandBuilder.js"), exports);
18
+ __exportStar(require("./reciple/classes/builders/MessageCommandOptionBuilder.js"), exports);
19
+ __exportStar(require("./reciple/classes/builders/SlashCommandBuilder.js"), exports);
20
+ __exportStar(require("./reciple/classes/managers/ApplicationCommandManager.js"), exports);
21
+ __exportStar(require("./reciple/classes/managers/ClientCommandManager.js"), exports);
22
+ __exportStar(require("./reciple/classes/managers/ClientModuleManager.js"), exports);
23
+ __exportStar(require("./reciple/classes/managers/CommandCooldownManager.js"), exports);
24
+ __exportStar(require("./reciple/classes/managers/MessageCommandOptionManager.js"), exports);
25
+ __exportStar(require("./reciple/classes/RecipleClient.js"), exports);
26
+ __exportStar(require("./reciple/classes/RecipleConfig.js"), exports);
27
+ __exportStar(require("./reciple/classes/RecipleModule.js"), exports);
28
+ __exportStar(require("./reciple/types/builders.js"), exports);
29
+ __exportStar(require("./reciple/types/commands.js"), exports);
30
+ __exportStar(require("./reciple/types/builders.js"), exports);
31
+ __exportStar(require("./reciple/types/builders.js"), exports);
32
+ __exportStar(require("./reciple/permissions.js"), exports);
33
+ __exportStar(require("./reciple/util.js"), exports);
34
+ __exportStar(require("./reciple/version.js"), 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");
19
- const version_1 = require("../version");
20
+ const util_1 = require("../util");
21
+ const version_js_1 = require("../version.js");
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 });
34
- this.version = version_1.version;
35
- this.logger = (0, logger_1.createLogger)(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
35
+ this.modules = new ClientModuleManager_1.ClientModuleManager({
36
+ client: this,
37
+ });
38
+ this.version = version_js_1.version;
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)
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.RecipleConfig = void 0;
7
7
  const fs_1 = require("fs");
8
- const version_1 = require("../version");
8
+ const version_js_1 = require("../version.js");
9
9
  const fallout_utility_1 = require("fallout-utility");
10
10
  const flags_1 = require("../flags");
11
11
  const path_1 = __importDefault(require("path"));
@@ -32,7 +32,7 @@ class RecipleConfig {
32
32
  const defaultConfigPath = RecipleConfig.defaultConfigPath;
33
33
  if (!(0, fs_1.existsSync)(defaultConfigPath))
34
34
  throw new Error('Default Config file not found. Please reinstall Reciple.');
35
- const defaultConfig = (0, fallout_utility_1.replaceAll)((0, fs_1.readFileSync)(defaultConfigPath, 'utf-8'), 'VERSION', version_1.version);
35
+ const defaultConfig = (0, fallout_utility_1.replaceAll)((0, fs_1.readFileSync)(defaultConfigPath, 'utf-8'), 'VERSION', version_js_1.version);
36
36
  (0, fs_1.writeFileSync)(this.configPath, defaultConfig, 'utf-8');
37
37
  if (!(0, fs_1.existsSync)(this.configPath))
38
38
  throw new Error('Failed to create config file.');
@@ -48,7 +48,7 @@ class RecipleConfig {
48
48
  const config = (0, fs_1.readFileSync)(this.configPath, 'utf-8');
49
49
  this.config = yaml_1.default.parse(config);
50
50
  if (!this._isSupportedConfig())
51
- throw new Error('Unsupported config version. Your config version: ' + (this.config?.version || 'No version specified.') + ', Reciple version: ' + version_1.version);
51
+ throw new Error('Unsupported config version. Your config version: ' + (this.config?.version || 'No version specified.') + ', Reciple version: ' + version_js_1.version);
52
52
  return this;
53
53
  }
54
54
  /**
@@ -78,20 +78,27 @@ class RecipleConfig {
78
78
  * Check if the config version is supported
79
79
  */
80
80
  _isSupportedConfig() {
81
- return (0, version_1.isSupportedVersion)(this.config?.version || '0.0.0', version_1.version);
81
+ return (0, version_js_1.isSupportedVersion)(this.config?.version || '0.0.0', version_js_1.version);
82
82
  }
83
83
  /**
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;