reciple 6.0.0-dev.2 → 6.0.0-dev.20

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 +65 -0
  2. package/dist/lib/esm.mjs +1 -0
  3. package/dist/{cjs → lib}/index.js +18 -17
  4. package/dist/{cjs → lib}/reciple/classes/RecipleClient.js +17 -20
  5. package/dist/{cjs → lib}/reciple/classes/RecipleConfig.js +10 -10
  6. package/dist/lib/reciple/classes/RecipleModule.js +94 -0
  7. package/dist/{cjs → lib}/reciple/classes/builders/MessageCommandBuilder.js +1 -1
  8. package/dist/{cjs → lib}/reciple/classes/builders/MessageCommandOptionBuilder.js +0 -0
  9. package/dist/{cjs → lib}/reciple/classes/builders/SlashCommandBuilder.js +2 -5
  10. package/dist/{cjs → lib}/reciple/classes/managers/ApplicationCommandManager.js +64 -23
  11. package/dist/{cjs → lib}/reciple/classes/managers/CommandCooldownManager.js +0 -0
  12. package/dist/{cjs/reciple/classes/managers/ClientCommandManager.js → lib/reciple/classes/managers/CommandManager.js} +14 -15
  13. package/dist/{cjs → lib}/reciple/classes/managers/MessageCommandOptionManager.js +0 -0
  14. package/dist/lib/reciple/classes/managers/ModuleManager.js +179 -0
  15. package/dist/{cjs → lib}/reciple/flags.js +2 -2
  16. package/dist/{cjs → lib}/reciple/permissions.js +0 -0
  17. package/dist/lib/reciple/types/builders.js +11 -0
  18. package/dist/{cjs → lib}/reciple/types/commands.js +6 -6
  19. package/dist/{cjs → lib}/reciple/types/paramOptions.js +0 -0
  20. package/dist/{cjs/reciple/logger.js → lib/reciple/util.js} +33 -2
  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 -17
  25. package/dist/types/reciple/classes/RecipleClient.d.ts +6 -4
  26. package/dist/types/reciple/classes/RecipleConfig.d.ts +3 -2
  27. package/dist/types/reciple/classes/RecipleModule.d.ts +56 -0
  28. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +5 -5
  29. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +5 -5
  30. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +43 -10
  31. package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +2 -2
  32. package/dist/types/reciple/classes/managers/{ClientCommandManager.d.ts → CommandManager.d.ts} +6 -7
  33. package/dist/types/reciple/classes/managers/ModuleManager.d.ts +49 -0
  34. package/dist/types/reciple/types/builders.d.ts +8 -8
  35. package/dist/types/reciple/types/commands.d.ts +16 -16
  36. package/dist/types/reciple/types/paramOptions.d.ts +79 -18
  37. package/dist/types/reciple/util.d.ts +11 -0
  38. package/package.json +26 -19
  39. package/resource/reciple.yml +25 -22
  40. package/dist/cjs/bin.js +0 -50
  41. package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +0 -193
  42. package/dist/cjs/reciple/types/builders.js +0 -11
  43. package/dist/cjs/reciple/util.js +0 -32
  44. package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +0 -79
  45. package/dist/types/reciple/logger.d.ts +0 -8
  46. package/docs/README.md +0 -1
@@ -0,0 +1,65 @@
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, mkdirSync, readdirSync } from 'fs';
6
+ import { cwd, flags } from './reciple/flags.js';
7
+ import { input } from 'fallout-utility';
8
+ import { path } from './reciple/util.js';
9
+ import chalk from 'chalk';
10
+ import 'dotenv/config';
11
+ import { inspect } from 'util';
12
+ const allowedFiles = ['node_modules', 'reciple.yml', 'package.json'];
13
+ const configPath = path.join(cwd, 'reciple.yml');
14
+ if (!existsSync(cwd))
15
+ mkdirSync(cwd, { recursive: true });
16
+ if (readdirSync(cwd).filter(f => !f.startsWith('.') && allowedFiles.indexOf(f)).length > 0 && !existsSync(flags.config ?? configPath)) {
17
+ const ask = (flags.yes ? 'y' : null) ?? input('This directory does not contain reciple.yml. Would you like to init axis here? [y/n] ') ?? '';
18
+ if (ask.toString().toLowerCase() !== 'y')
19
+ process.exit(0);
20
+ }
21
+ let configParser;
22
+ try {
23
+ configParser = new RecipleConfig(flags.config ?? configPath).parseConfig();
24
+ }
25
+ catch (err) {
26
+ console.error(`${chalk.bold.red('Config Error')}: ${inspect(err)}`);
27
+ process.exit(1);
28
+ }
29
+ const config = configParser.getConfig();
30
+ const client = new RecipleClient({ config: config, cwd, ...config.client });
31
+ /**
32
+ * Start
33
+ */
34
+ if (!client.isClientLogsSilent)
35
+ client.logger.info('Starting Reciple client v' + rawVersion);
36
+ client.addCommandListeners();
37
+ await client.modules.startModules({
38
+ modules: await client.modules.resolveModuleFiles({
39
+ files: await client.modules.getModulePaths({
40
+ filter: file => file.endsWith('.js') || file.endsWith('.cjs') || file.endsWith('.mjs'),
41
+ }),
42
+ }),
43
+ });
44
+ client.on('ready', async () => {
45
+ await client.modules.loadModules();
46
+ const unloadModulesAndStopProcess = async (signal) => {
47
+ await client.modules.unloadModules({ reason: 'ProcessExit' });
48
+ client.logger.warn(`Exitting process${signal === 'SIGINT' ? ': keyboard interrupt' : signal === 'SIGTERM' ? ': terminate' : signal}`);
49
+ process.exit();
50
+ };
51
+ process.once('SIGINT', signal => unloadModulesAndStopProcess(signal));
52
+ process.once('SIGTERM', signal => unloadModulesAndStopProcess(signal));
53
+ if (!client.isClientLogsSilent)
54
+ client.logger.log(`Loaded ${client.commands.slashCommands.size} slash commands`, `Loaded ${client.commands.messageCommands.size} message commands`);
55
+ if (client.config.commands.slashCommand.registerCommands && (client.config.commands.slashCommand.allowRegisterEmptyCommandList || client.applicationCommands.size)) {
56
+ await client.commands.registerApplicationCommands();
57
+ }
58
+ if (!client.isClientLogsSilent)
59
+ client.logger.warn(`Logged in as ${client.user?.tag || 'Unknown'}!`);
60
+ client.on('cacheSweep', () => client.cooldowns.clean());
61
+ });
62
+ client.login(config.token).catch(err => {
63
+ if (!client.isClientLogsSilent)
64
+ client.logger.error(err);
65
+ });
@@ -0,0 +1 @@
1
+ export * from './index.js';
@@ -14,21 +14,22 @@ 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/ClientModuleManager"), 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/types/builders"), exports);
28
- __exportStar(require("./reciple/types/commands"), exports);
29
- __exportStar(require("./reciple/types/paramOptions"), 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/CommandManager.js"), exports);
22
+ __exportStar(require("./reciple/classes/managers/ModuleManager.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);
30
32
  __exportStar(require("./reciple/flags"), exports);
31
- __exportStar(require("./reciple/logger"), exports);
32
- __exportStar(require("./reciple/permissions"), exports);
33
- __exportStar(require("./reciple/util"), exports);
34
- __exportStar(require("./reciple/version"), exports);
33
+ __exportStar(require("./reciple/permissions.js"), exports);
34
+ __exportStar(require("./reciple/util.js"), exports);
35
+ __exportStar(require("./reciple/version.js"), exports);
@@ -1,7 +1,4 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.RecipleClient = void 0;
7
4
  const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
@@ -12,15 +9,14 @@ const CommandCooldownManager_1 = require("./managers/CommandCooldownManager");
12
9
  const permissions_1 = require("../permissions");
13
10
  const MessageCommandOptionManager_1 = require("./managers/MessageCommandOptionManager");
14
11
  const ApplicationCommandManager_1 = require("./managers/ApplicationCommandManager");
12
+ const CommandManager_1 = require("./managers/CommandManager");
15
13
  const builders_1 = require("../types/builders");
16
- const ClientCommandManager_1 = require("./managers/ClientCommandManager");
17
- const ClientModuleManager_1 = require("./managers/ClientModuleManager");
14
+ const ModuleManager_1 = require("./managers/ModuleManager");
18
15
  const RecipleConfig_1 = require("./RecipleConfig");
19
16
  const fallout_utility_1 = require("fallout-utility");
20
- const logger_1 = require("../logger");
21
- const version_1 = require("../version");
17
+ const util_1 = require("../util");
18
+ const version_js_1 = require("../version.js");
22
19
  const flags_1 = require("../flags");
23
- const path_1 = __importDefault(require("path"));
24
20
  class RecipleClient extends discord_js_1.Client {
25
21
  /**
26
22
  * @param options Client options
@@ -28,18 +24,19 @@ class RecipleClient extends discord_js_1.Client {
28
24
  constructor(options) {
29
25
  super(options);
30
26
  this.config = RecipleConfig_1.RecipleConfig.getDefaultConfig();
31
- this.commands = new ClientCommandManager_1.ClientCommandManager({
27
+ this.commands = new CommandManager_1.CommandManager({
32
28
  client: this,
33
29
  });
34
30
  this.cooldowns = new CommandCooldownManager_1.CommandCooldownManager();
35
- this.modules = new ClientModuleManager_1.ClientModuleManager({
31
+ this.modules = new ModuleManager_1.ModuleManager({
36
32
  client: this,
37
33
  });
38
- this.version = version_1.version;
39
- this.logger = (0, logger_1.createLogger)(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
34
+ this.version = version_js_1.version;
35
+ this.logger = (0, util_1.createLogger)(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
40
36
  this.config = { ...this.config, ...(options.config ?? {}) };
41
37
  if (this.config.fileLogging.enabled)
42
- this.logger.logFile(path_1.default.join(flags_1.cwd, this.config.fileLogging.logFilePath ?? 'logs/latest.log'), false);
38
+ this.logger.logFile(util_1.path.join(flags_1.cwd, this.config.fileLogging.logFilePath ?? 'logs/latest.log'), false);
39
+ this.cwd = options.cwd ?? process.cwd();
43
40
  this.applicationCommands = new ApplicationCommandManager_1.ApplicationCommandManager(this);
44
41
  }
45
42
  get isClientLogsSilent() {
@@ -68,7 +65,7 @@ class RecipleClient extends discord_js_1.Client {
68
65
  return;
69
66
  if (!this.config.commands.slashCommand.acceptRepliedInteractions && (interaction.replied || interaction.deferred))
70
67
  return;
71
- const command = this.commands.get(interaction.commandName, builders_1.CommandBuilderType.SlashCommand);
68
+ const command = this.commands.get(interaction.commandName, builders_1.CommandType.SlashCommand);
72
69
  if (!command)
73
70
  return;
74
71
  const executeData = {
@@ -97,7 +94,7 @@ class RecipleClient extends discord_js_1.Client {
97
94
  command: command.name,
98
95
  channel: interaction.channel ?? undefined,
99
96
  guild: interaction.guild,
100
- type: builders_1.CommandBuilderType.SlashCommand,
97
+ type: builders_1.CommandType.SlashCommand,
101
98
  };
102
99
  if (this.config.commands.slashCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
103
100
  this.cooldowns.add({
@@ -135,7 +132,7 @@ class RecipleClient extends discord_js_1.Client {
135
132
  const parseCommand = (0, fallout_utility_1.getCommand)(message.content, prefix || this.config.commands.messageCommand.prefix || '!', this.config.commands.messageCommand.commandArgumentSeparator || ' ');
136
133
  if (!parseCommand || !parseCommand?.command)
137
134
  return;
138
- const command = this.commands.get(parseCommand.command, builders_1.CommandBuilderType.MessageCommand);
135
+ const command = this.commands.get(parseCommand.command, builders_1.CommandType.MessageCommand);
139
136
  if (!command)
140
137
  return;
141
138
  const commandOptions = await (0, MessageCommandBuilder_1.validateMessageCommandOptions)(command, parseCommand);
@@ -189,7 +186,7 @@ class RecipleClient extends discord_js_1.Client {
189
186
  command: command.name,
190
187
  channel: message.channel,
191
188
  guild: message.guild,
192
- type: builders_1.CommandBuilderType.MessageCommand,
189
+ type: builders_1.CommandType.MessageCommand,
193
190
  };
194
191
  if (this.config.commands.messageCommand.enableCooldown && command.cooldown && !this.cooldowns.isCooledDown(userCooldown)) {
195
192
  this.cooldowns.add({
@@ -234,7 +231,7 @@ class RecipleClient extends discord_js_1.Client {
234
231
  async _haltCommand(command, haltData) {
235
232
  try {
236
233
  const haltResolved = (command.halt
237
- ? await Promise.resolve(command.type == builders_1.CommandBuilderType.SlashCommand ? command.halt(haltData) : command.halt(haltData)).catch(err => {
234
+ ? await Promise.resolve(command.type == builders_1.CommandType.SlashCommand ? command.halt(haltData) : command.halt(haltData)).catch(err => {
238
235
  console.log(err);
239
236
  })
240
237
  : false) || false;
@@ -251,7 +248,7 @@ class RecipleClient extends discord_js_1.Client {
251
248
  }
252
249
  async _executeCommand(command, executeData) {
253
250
  try {
254
- await Promise.resolve(command.type === builders_1.CommandBuilderType.SlashCommand ? command.execute(executeData) : command.execute(executeData))
251
+ await Promise.resolve(command.type === builders_1.CommandType.SlashCommand ? command.execute(executeData) : command.execute(executeData))
255
252
  .then(() => this.emit('recipleCommandExecute', executeData))
256
253
  .catch(async (err) => !(await this._haltCommand(command, {
257
254
  executeData: executeData,
@@ -279,7 +276,7 @@ class RecipleClient extends discord_js_1.Client {
279
276
  */
280
277
  async _commandExecuteError(err, command) {
281
278
  if (!this.isClientLogsSilent) {
282
- this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandBuilderType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
279
+ this.logger.error(`An error occured executing ${command.builder.type == builders_1.CommandType.MessageCommand ? 'message' : 'slash'} command "${command.builder.name}"`);
283
280
  this.logger.error(err);
284
281
  }
285
282
  if (!err || !command)
@@ -8,7 +8,7 @@ const fs_1 = require("fs");
8
8
  const version_1 = require("../version");
9
9
  const fallout_utility_1 = require("fallout-utility");
10
10
  const flags_1 = require("../flags");
11
- const path_1 = __importDefault(require("path"));
11
+ const util_1 = require("../util");
12
12
  const yaml_1 = __importDefault(require("yaml"));
13
13
  /**
14
14
  * Create/parse reciple config
@@ -19,7 +19,7 @@ class RecipleConfig {
19
19
  */
20
20
  constructor(configPath) {
21
21
  this.config = RecipleConfig.getDefaultConfig();
22
- this.configPath = path_1.default.join(flags_1.cwd, 'reciple.yml');
22
+ this.configPath = util_1.path.join(process.cwd(), 'reciple.yml');
23
23
  if (!configPath)
24
24
  throw new Error('Config path is not defined');
25
25
  this.configPath = configPath;
@@ -62,17 +62,17 @@ class RecipleConfig {
62
62
  }
63
63
  /**
64
64
  * Parse token from config
65
- * @param askIfNull Ask for token if the token is null/undefined
65
+ * @param askIfEmpty Ask for token if the token is undefined
66
66
  */
67
- parseToken(askIfNull = true) {
68
- let token = flags_1.token || this.config?.token || null;
67
+ parseToken(askIfEmpty = true) {
68
+ let token = flags_1.token || this.config?.token || undefined;
69
69
  if (!token)
70
- return token || (askIfNull ? this._askToken() : null);
70
+ return token || (askIfEmpty ? this._askToken() : null);
71
71
  const envToken = token.toString().split(':');
72
72
  if (envToken.length === 2 && envToken[0].toLocaleLowerCase() === 'env' && envToken[1]) {
73
- token = process.env[envToken[1]] || null;
73
+ token = process.env[envToken[1]] || undefined;
74
74
  }
75
- return token || (askIfNull ? this._askToken() : null);
75
+ return token || (askIfEmpty == null ? this._askToken() : null);
76
76
  }
77
77
  /**
78
78
  * Check if the config version is supported
@@ -98,9 +98,9 @@ class RecipleConfig {
98
98
  */
99
99
  static getDefaultConfig() {
100
100
  if (!(0, fs_1.existsSync)(this.defaultConfigPath))
101
- throw new Error('Default config file does not exists.');
101
+ throw new Error(`Default config file does not exists: ${this.defaultConfigPath}`);
102
102
  return yaml_1.default.parse((0, fs_1.readFileSync)(this.defaultConfigPath, 'utf-8'));
103
103
  }
104
104
  }
105
105
  exports.RecipleConfig = RecipleConfig;
106
- RecipleConfig.defaultConfigPath = path_1.default.join(__dirname, '../../../../resource/reciple.yml');
106
+ RecipleConfig.defaultConfigPath = util_1.path.join(__dirname, '../../../../resource/reciple.yml');
@@ -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;
@@ -10,7 +10,7 @@ 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 = [];
@@ -182,10 +182,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
182
182
  default:
183
183
  throw new TypeError('Unknown option data');
184
184
  }
185
- if (!(builder instanceof discord_js_1.SlashCommandSubcommandBuilder) &&
186
- !(builder instanceof discord_js_1.SlashCommandSubcommandGroupBuilder) &&
187
- option.type !== discord_js_1.ApplicationCommandOptionType.Subcommand &&
188
- option.type !== discord_js_1.ApplicationCommandOptionType.SubcommandGroup) {
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) {
189
186
  builder.setRequired(option.required ?? false);
190
187
  }
191
188
  return builder
@@ -8,122 +8,163 @@ class ApplicationCommandManager {
8
8
  this.client = client;
9
9
  }
10
10
  get commands() {
11
- return this.client.application?.commands;
11
+ return [...this.client.commands.additionalApplicationCommands, ...this.client.commands.slashCommands.toJSON()];
12
12
  }
13
- async set(commands, guilds) {
13
+ get size() {
14
+ return this.commands.length;
15
+ }
16
+ /**
17
+ * Sets application commands globally or in guilds
18
+ * @param commands Application commands
19
+ * @param guilds set only to guilds
20
+ */
21
+ async set(commands, ...guilds) {
22
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
14
23
  if (!this.client.isReady())
15
24
  throw new Error('Client is not ready');
16
25
  if (guilds && guilds.length > 1) {
17
26
  for (const guild of guilds) {
18
- await this.set(commands, [guild]);
27
+ await this.set(commands, guild);
19
28
  }
20
29
  return;
21
30
  }
22
31
  let guild = guilds?.shift();
23
32
  guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
24
33
  if (!guild) {
25
- this.client.application.commands.set(commands);
34
+ await this.client.application.commands.set(commands);
26
35
  if (!this.client.isClientLogsSilent)
27
- this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) globally...`);
36
+ this.client.logger.log(`Registered ${this.client.applicationCommands.size} application command(s) globally...`);
28
37
  }
29
38
  else {
30
- this.client.application.commands.set(commands, guild);
39
+ await this.client.application.commands.set(commands, guild);
31
40
  if (!this.client.isClientLogsSilent)
32
- this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) to guild ${guild}...`);
41
+ this.client.logger.log(`Registered ${this.client.applicationCommands.size} application command(s) to guild ${guild}`);
33
42
  }
34
43
  }
35
- async add(command, guilds) {
44
+ /**
45
+ * Add command globally or in guilds
46
+ * @param command Application command
47
+ * @param guilds add only in guilds
48
+ */
49
+ async add(command, ...guilds) {
50
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
36
51
  if (!this.client.isReady())
37
52
  throw new Error('Client is not ready');
38
53
  if (!command)
39
54
  throw new Error('Command is undefined');
40
55
  if (guilds && guilds.length > 1) {
41
56
  for (const guild of guilds) {
42
- await this.add(command, [guild]);
57
+ await this.add(command, guild);
43
58
  }
44
59
  return;
45
60
  }
46
61
  let guild = guilds?.shift();
47
62
  guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
48
63
  if (!guild) {
49
- this.client.application.commands.create(command);
64
+ await this.client.application.commands.create(command);
50
65
  if (!this.client.isClientLogsSilent)
51
66
  this.client.logger.log(`Created application command '${command.name}' globally`);
52
67
  }
53
68
  else {
54
- this.client.application.commands.create(command, guild);
69
+ await this.client.application.commands.create(command, guild);
55
70
  if (!this.client.isClientLogsSilent)
56
71
  this.client.logger.log(`Created application command '${command.name}' to guild ${guild}`);
57
72
  }
58
73
  }
59
- async remove(command, guilds) {
74
+ /**
75
+ * Remove application command globally or in guilds
76
+ * @param command id of application commmand or ApplicationCommand class
77
+ * @param guilds Remove from guilds
78
+ */
79
+ async remove(command, ...guilds) {
80
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
60
81
  if (!this.client.isReady())
61
82
  throw new Error('Client is not ready');
62
83
  if (!command)
63
84
  throw new Error('Command is undefined');
64
85
  if (guilds && guilds.length > 1) {
65
86
  for (const guild of guilds) {
66
- await this.remove(command, [guild]);
87
+ await this.remove(command, guild);
67
88
  }
68
89
  return;
69
90
  }
70
91
  let guild = guilds?.shift();
71
92
  guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
72
93
  if (!guild) {
73
- this.client.application.commands.delete(command);
94
+ await this.client.application.commands.delete(command);
74
95
  if (!this.client.isClientLogsSilent)
75
96
  this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
76
97
  }
77
98
  else {
78
- this.client.application.commands.delete(command, guild);
99
+ await this.client.application.commands.delete(command, guild);
79
100
  if (!this.client.isClientLogsSilent)
80
101
  this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
81
102
  }
82
103
  }
83
- async edit(command, newCommand, guilds) {
104
+ /**
105
+ * Edit application command globally or in guilds
106
+ * @param command id of application command or ApplicationCommand class
107
+ * @param newCommand new application command data
108
+ * @param guilds Edit only from guilds
109
+ */
110
+ async edit(command, newCommand, ...guilds) {
111
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
84
112
  if (!this.client.isReady())
85
113
  throw new Error('Client is not ready');
86
114
  if (!command)
87
115
  throw new Error('Command is undefined');
88
116
  if (guilds && guilds.length > 1) {
89
117
  for (const guild of guilds) {
90
- await this.edit(command, newCommand, [guild]);
118
+ await this.edit(command, newCommand, guild);
91
119
  }
92
120
  return;
93
121
  }
94
122
  let guild = guilds?.shift();
95
123
  guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
96
124
  if (!guild) {
97
- this.client.application.commands.edit(command, newCommand);
125
+ await this.client.application.commands.edit(command, newCommand);
98
126
  if (!this.client.isClientLogsSilent)
99
127
  this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
100
128
  }
101
129
  else {
102
- this.client.application.commands.edit(command, newCommand, guild);
130
+ await this.client.application.commands.edit(command, newCommand, guild);
103
131
  if (!this.client.isClientLogsSilent)
104
132
  this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
105
133
  }
106
134
  }
135
+ /**
136
+ * Get application command from cache by application command data, builder, id, or name globally or from guid
137
+ * @param command application command data, builder, id, or name
138
+ * @param guild get command from guild
139
+ */
107
140
  get(command, guild) {
108
141
  const commands = guild ? this.client.guilds.resolve(guild)?.commands.cache : this.client.application?.commands.cache;
109
142
  if (!commands)
110
143
  throw new Error('Guild not found in cache');
111
- return commands.find(cmd => typeof command === 'string' ? cmd.id === command || cmd.name === command : cmd.name === command.name || (command instanceof discord_js_1.ApplicationCommand && cmd.id === command.id));
144
+ return commands.find(cmd => (typeof command === 'string' ? cmd.id === command || cmd.name === command : cmd.name === command.name || (command instanceof discord_js_1.ApplicationCommand && cmd.id === command.id)));
112
145
  }
146
+ /**
147
+ * Fetch application command by id globally or from guild
148
+ * @param commandId command id
149
+ * @param guild fetch from guild
150
+ */
113
151
  async fetch(commandId, guild) {
114
152
  const manager = guild ? this.client.guilds.resolve(guild)?.commands : this.client.application?.commands;
115
153
  if (!manager)
116
154
  throw new Error('Guild not found in cache');
117
155
  return manager.fetch(commandId);
118
156
  }
157
+ /**
158
+ * Parse application command builders to command data
159
+ * @param commands Application command builders
160
+ * @param setPermissions set slash commands permissions
161
+ */
119
162
  parseCommands(commands, setPermissions = true) {
120
163
  return commands.map(cmd => {
121
164
  if (cmd?.toJSON === undefined)
122
165
  return cmd;
123
166
  if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandBuilder(cmd) && this.client.config.commands.slashCommand.setRequiredPermissions) {
124
- const permissions = setPermissions || this.client.config.commands.slashCommand.permissions.enabled
125
- ? this.client.config.commands.slashCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())?.permissions
126
- : undefined;
167
+ const permissions = setPermissions || this.client.config.commands.slashCommand.permissions.enabled ? this.client.config.commands.slashCommand.permissions.commands.find(cmd_ => cmd_.command.toLowerCase() === cmd.name.toLowerCase())?.permissions : undefined;
127
168
  if (permissions) {
128
169
  cmd.setRequiredMemberPermissions(...permissions);
129
170
  if (!this.client.isClientLogsSilent)