reciple 5.6.0 → 6.0.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/cjs/bin.js +9 -10
  2. package/dist/cjs/index.js +7 -6
  3. package/dist/cjs/reciple/classes/RecipleClient.js +87 -181
  4. package/dist/cjs/reciple/classes/RecipleConfig.js +9 -2
  5. package/dist/cjs/reciple/classes/builders/MessageCommandBuilder.js +6 -4
  6. package/dist/cjs/reciple/classes/builders/SlashCommandBuilder.js +14 -22
  7. package/dist/cjs/reciple/classes/managers/ApplicationCommandManager.js +137 -0
  8. package/dist/cjs/reciple/classes/managers/ClientCommandManager.js +60 -0
  9. package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +193 -0
  10. package/dist/cjs/reciple/classes/{CommandCooldownManager.js → managers/CommandCooldownManager.js} +15 -6
  11. package/dist/cjs/reciple/classes/{MessageCommandOptionManager.js → managers/MessageCommandOptionManager.js} +0 -0
  12. package/dist/cjs/reciple/logger.js +10 -8
  13. package/dist/cjs/reciple/permissions.js +3 -4
  14. package/dist/cjs/reciple/util.js +10 -1
  15. package/dist/types/index.d.ts +7 -6
  16. package/dist/types/reciple/classes/RecipleClient.d.ts +17 -65
  17. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +2 -2
  18. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +12 -12
  19. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +20 -0
  20. package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +37 -0
  21. package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +79 -0
  22. package/dist/types/reciple/classes/{CommandCooldownManager.d.ts → managers/CommandCooldownManager.d.ts} +3 -2
  23. package/dist/types/reciple/classes/{MessageCommandOptionManager.d.ts → managers/MessageCommandOptionManager.d.ts} +1 -1
  24. package/dist/types/reciple/types/builders.d.ts +13 -13
  25. package/dist/types/reciple/types/commands.d.ts +2 -2
  26. package/dist/types/reciple/types/paramOptions.d.ts +8 -19
  27. package/dist/types/reciple/util.d.ts +2 -0
  28. package/package.json +21 -16
  29. package/dist/cjs/reciple/modules.js +0 -113
  30. package/dist/cjs/reciple/registerApplicationCommands.js +0 -49
  31. package/dist/types/reciple/modules.d.ts +0 -64
  32. package/dist/types/reciple/registerApplicationCommands.d.ts +0 -9
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApplicationCommandManager = void 0;
4
+ const discord_js_1 = require("discord.js");
5
+ const SlashCommandBuilder_1 = require("../builders/SlashCommandBuilder");
6
+ class ApplicationCommandManager {
7
+ constructor(client) {
8
+ this.client = client;
9
+ }
10
+ get commands() {
11
+ return this.client.application?.commands;
12
+ }
13
+ async set(commands, guilds) {
14
+ if (!this.client.isReady())
15
+ throw new Error('Client is not ready');
16
+ if (guilds && guilds.length > 1) {
17
+ for (const guild of guilds) {
18
+ await this.set(commands, [guild]);
19
+ }
20
+ return;
21
+ }
22
+ let guild = guilds?.shift();
23
+ guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
24
+ if (!guild) {
25
+ this.client.application.commands.set(commands);
26
+ if (!this.client.isClientLogsSilent)
27
+ this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) globally...`);
28
+ }
29
+ else {
30
+ this.client.application.commands.set(commands, guild);
31
+ if (!this.client.isClientLogsSilent)
32
+ this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) to guild ${guild}...`);
33
+ }
34
+ }
35
+ async add(command, guilds) {
36
+ if (!this.client.isReady())
37
+ throw new Error('Client is not ready');
38
+ if (!command)
39
+ throw new Error('Command is undefined');
40
+ if (guilds && guilds.length > 1) {
41
+ for (const guild of guilds) {
42
+ await this.add(command, [guild]);
43
+ }
44
+ return;
45
+ }
46
+ let guild = guilds?.shift();
47
+ guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
48
+ if (!guild) {
49
+ this.client.application.commands.create(command);
50
+ if (!this.client.isClientLogsSilent)
51
+ this.client.logger.log(`Created application command '${command.name}' globally`);
52
+ }
53
+ else {
54
+ this.client.application.commands.create(command, guild);
55
+ if (!this.client.isClientLogsSilent)
56
+ this.client.logger.log(`Created application command '${command.name}' to guild ${guild}`);
57
+ }
58
+ }
59
+ async remove(command, guilds) {
60
+ if (!this.client.isReady())
61
+ throw new Error('Client is not ready');
62
+ if (!command)
63
+ throw new Error('Command is undefined');
64
+ if (guilds && guilds.length > 1) {
65
+ for (const guild of guilds) {
66
+ await this.remove(command, [guild]);
67
+ }
68
+ return;
69
+ }
70
+ let guild = guilds?.shift();
71
+ guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
72
+ if (!guild) {
73
+ this.client.application.commands.delete(command);
74
+ if (!this.client.isClientLogsSilent)
75
+ this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
76
+ }
77
+ else {
78
+ this.client.application.commands.delete(command, guild);
79
+ if (!this.client.isClientLogsSilent)
80
+ this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
81
+ }
82
+ }
83
+ async edit(command, newCommand, guilds) {
84
+ if (!this.client.isReady())
85
+ throw new Error('Client is not ready');
86
+ if (!command)
87
+ throw new Error('Command is undefined');
88
+ if (guilds && guilds.length > 1) {
89
+ for (const guild of guilds) {
90
+ await this.edit(command, newCommand, [guild]);
91
+ }
92
+ return;
93
+ }
94
+ let guild = guilds?.shift();
95
+ guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
96
+ if (!guild) {
97
+ this.client.application.commands.edit(command, newCommand);
98
+ if (!this.client.isClientLogsSilent)
99
+ this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
100
+ }
101
+ else {
102
+ this.client.application.commands.edit(command, newCommand, guild);
103
+ if (!this.client.isClientLogsSilent)
104
+ this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
105
+ }
106
+ }
107
+ get(command, guild) {
108
+ const commands = guild ? this.client.guilds.resolve(guild)?.commands.cache : this.client.application?.commands.cache;
109
+ if (!commands)
110
+ 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));
112
+ }
113
+ async fetch(commandId, guild) {
114
+ const manager = guild ? this.client.guilds.resolve(guild)?.commands : this.client.application?.commands;
115
+ if (!manager)
116
+ throw new Error('Guild not found in cache');
117
+ return manager.fetch(commandId);
118
+ }
119
+ parseCommands(commands, setPermissions = true) {
120
+ return commands.map(cmd => {
121
+ if (cmd?.toJSON === undefined)
122
+ return cmd;
123
+ 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;
127
+ if (permissions) {
128
+ cmd.setRequiredMemberPermissions(...permissions);
129
+ if (!this.client.isClientLogsSilent)
130
+ this.client.logger.debug(`Set required permissions for ${cmd.name}`);
131
+ }
132
+ }
133
+ return cmd.toJSON();
134
+ });
135
+ }
136
+ }
137
+ exports.ApplicationCommandManager = ApplicationCommandManager;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientCommandManager = void 0;
4
+ const discord_js_1 = require("discord.js");
5
+ const builders_1 = require("../../types/builders");
6
+ const MessageCommandBuilder_1 = require("../builders/MessageCommandBuilder");
7
+ const SlashCommandBuilder_1 = require("../builders/SlashCommandBuilder");
8
+ class ClientCommandManager {
9
+ constructor(options) {
10
+ this.slashCommands = new discord_js_1.Collection();
11
+ this.messageCommands = new discord_js_1.Collection();
12
+ this.additionalApplicationCommands = [];
13
+ this.client = options.client;
14
+ options.slashCommands?.forEach(e => this.slashCommands.set(e.name, SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(e)));
15
+ options.messageCommands?.forEach(e => this.messageCommands.set(e.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(e)));
16
+ }
17
+ get applicationCommandsSize() {
18
+ return this.client.commands.slashCommands.size + this.client.commands.additionalApplicationCommands.length;
19
+ }
20
+ /**
21
+ * Add command to command manager
22
+ * @param commands Any command data or builder
23
+ */
24
+ add(...commands) {
25
+ for (const command of (0, discord_js_1.normalizeArray)(commands)) {
26
+ if (command.type === builders_1.CommandBuilderType.SlashCommand) {
27
+ this.slashCommands.set(command.name, SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
28
+ }
29
+ else if (command.type === builders_1.CommandBuilderType.MessageCommand) {
30
+ this.messageCommands.set(command.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
31
+ }
32
+ }
33
+ return this;
34
+ }
35
+ get(command, type) {
36
+ switch (type) {
37
+ case builders_1.CommandBuilderType.SlashCommand:
38
+ return this.slashCommands.get(command);
39
+ case builders_1.CommandBuilderType.MessageCommand:
40
+ return (this.messageCommands.get(command.toLowerCase()) ??
41
+ (this.client.config.commands.messageCommand.allowCommandAlias ? this.messageCommands.find(c => c.aliases.some(a => a == command?.toLowerCase())) : undefined));
42
+ default:
43
+ throw new TypeError('Unknown command type');
44
+ }
45
+ }
46
+ /**
47
+ * Register application commands
48
+ * @param guilds Register application commands to guilds
49
+ */
50
+ async registerApplicationCommands(...guilds) {
51
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
52
+ guilds = guilds.length ? guilds : (0, discord_js_1.normalizeArray)([this.client.config.commands.slashCommand.guilds]);
53
+ if (!this.client.isClientLogsSilent)
54
+ this.client.logger.log(`Regestering ${this.applicationCommandsSize} application command(s) ${!guilds.length ? 'globaly' : 'to ' + guilds.length + ' guilds'}...`);
55
+ await this.client.applicationCommands.set([...this.slashCommands.toJSON(), ...this.additionalApplicationCommands], guilds);
56
+ this.client.emit('RegisterApplicationCommands');
57
+ return this;
58
+ }
59
+ }
60
+ exports.ClientCommandManager = ClientCommandManager;
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.ClientModuleManager = void 0;
30
+ const crypto_1 = require("crypto");
31
+ const discord_js_1 = require("discord.js");
32
+ const fs_1 = require("fs");
33
+ const path_1 = __importDefault(require("path"));
34
+ const wildcard_match_1 = __importDefault(require("wildcard-match"));
35
+ const flags_1 = require("../../flags");
36
+ const builders_1 = require("../../types/builders");
37
+ const util_1 = require("../../util");
38
+ const version_1 = require("../../version");
39
+ const MessageCommandBuilder_1 = require("../builders/MessageCommandBuilder");
40
+ const SlashCommandBuilder_1 = require("../builders/SlashCommandBuilder");
41
+ class ClientModuleManager {
42
+ constructor(options) {
43
+ this.modules = new discord_js_1.Collection();
44
+ this.client = options.client;
45
+ options.modules?.forEach(m => {
46
+ if (!m.id)
47
+ m.id = (0, crypto_1.randomUUID)();
48
+ this.modules.set(m.id, this.resolveModule(m));
49
+ });
50
+ }
51
+ async startModulesFromFiles(options) {
52
+ const modules = await this.resolveModulesFromFiles(options);
53
+ for (const module_ of modules) {
54
+ try {
55
+ await this.startModule(module_);
56
+ }
57
+ catch (err) {
58
+ if (options.dontSkipError)
59
+ throw err;
60
+ if (!this.client.isClientLogsSilent)
61
+ this.client.logger.err(`Cannot start module ${ClientModuleManager.getModuleDisplayId(module_)}:`, err);
62
+ }
63
+ }
64
+ return modules;
65
+ }
66
+ async resolveModulesFromFiles(options) {
67
+ const modules = [];
68
+ const isVersionCheckDisabled = options.disabeVersionCheck || this.client.config.disableVersionCheck;
69
+ for (const file of options.files) {
70
+ const moduleFileName = path_1.default.basename(file);
71
+ const moduleDirPath = path_1.default.dirname(file);
72
+ const id = (0, crypto_1.randomUUID)();
73
+ let script;
74
+ try {
75
+ const resolveModuleFile = await Promise.resolve().then(() => __importStar(require(file)));
76
+ script = resolveModuleFile?.default ?? resolveModuleFile;
77
+ const module_ = this.resolveModule({
78
+ id,
79
+ script,
80
+ info: {
81
+ filename: moduleFileName,
82
+ path: moduleDirPath,
83
+ },
84
+ }, isVersionCheckDisabled);
85
+ modules.push(module_);
86
+ if (!this.client.isClientLogsSilent)
87
+ this.client.logger.log(`Resolved ${file}`);
88
+ }
89
+ catch (err) {
90
+ if (options.dontSkipError)
91
+ throw err;
92
+ if (!this.client.isClientLogsSilent)
93
+ this.client.logger.err(`Cannot resolve module file ${file}:`, err);
94
+ }
95
+ }
96
+ return modules;
97
+ }
98
+ resolveScriptCommands(...modules) {
99
+ const resolvedCommands = [];
100
+ for (const script of (0, discord_js_1.normalizeArray)(modules)) {
101
+ const commands = [];
102
+ if (Array.isArray(script?.commands)) {
103
+ for (const command of script.commands) {
104
+ if (command.type === builders_1.CommandBuilderType.MessageCommand) {
105
+ commands.push(MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
106
+ }
107
+ else if (command.type === builders_1.CommandBuilderType.SlashCommand) {
108
+ commands.push(SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
109
+ }
110
+ }
111
+ }
112
+ const invalidBuilders = commands.some(c => !(0, util_1.validateCommandBuilder)(c));
113
+ if (invalidBuilders)
114
+ throw new Error(`Module script commands contains a command builder without name or option name`);
115
+ resolvedCommands.push({
116
+ script,
117
+ commands,
118
+ });
119
+ }
120
+ return resolvedCommands;
121
+ }
122
+ async loadAll(registerApplicationCommands, ...registerApplicationCommandsGuilds) {
123
+ await Promise.all(this.modules.map(async (m) => {
124
+ if (typeof m.script?.onLoad === 'function') {
125
+ try {
126
+ await Promise.resolve(m.script.onLoad(this.client)).catch(err => {
127
+ throw err;
128
+ });
129
+ }
130
+ catch (err) {
131
+ this.modules.delete(m.id);
132
+ if (!this.client.isClientLogsSilent)
133
+ this.client.logger.error(`Error loading ${m.info.filename ?? 'unknown module'}:`, err);
134
+ return;
135
+ }
136
+ }
137
+ this.client.commands.add(m.commands);
138
+ if (!this.client.isClientLogsSilent)
139
+ this.client.logger.log(`Loaded module: ${ClientModuleManager.getModuleDisplayId(m)}`);
140
+ }));
141
+ if (!this.client.isClientLogsSilent) {
142
+ this.client.logger.info(`${this.modules.size} modules loaded.`);
143
+ this.client.logger.info(`${this.client.commands.messageCommands.size} message commands loaded.`);
144
+ this.client.logger.info(`${this.client.commands.slashCommands.size} slash commands loaded.`);
145
+ }
146
+ if (registerApplicationCommands)
147
+ this.client.commands.registerApplicationCommands((0, discord_js_1.normalizeArray)(registerApplicationCommandsGuilds));
148
+ }
149
+ async startModule(mod) {
150
+ let err;
151
+ const identifier = ClientModuleManager.getModuleDisplayId(mod);
152
+ if (!this.client.isClientLogsSilent)
153
+ this.client.logger.log(`Starting Module: ${identifier}`);
154
+ const start = await Promise.resolve(mod.script.onStart(this.client)).catch(e => (err = e));
155
+ if (err)
156
+ throw err;
157
+ if (!start)
158
+ throw new Error(`Module ${identifier} returned 'false' on start`);
159
+ this.modules.set(mod.id, mod);
160
+ }
161
+ resolveModule(mod, disabeVersionCheck) {
162
+ const identifier = ClientModuleManager.getModuleDisplayId(mod);
163
+ if (!disabeVersionCheck && !mod?.script?.versions?.length)
164
+ throw new Error(`Module ${identifier} does not contain supported versions`);
165
+ if (typeof mod.script?.onStart !== 'function')
166
+ throw new Error(`Module ${identifier} does not have a valid 'onStart' method`);
167
+ const versions = (0, discord_js_1.normalizeArray)([mod.script.versions]);
168
+ const commands = this.resolveScriptCommands(mod.script)[0].commands;
169
+ if (!disabeVersionCheck && !versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
170
+ throw new Error(`Module ${identifier} does not support 'reciple@${version_1.rawVersion}'`);
171
+ return {
172
+ ...mod,
173
+ commands,
174
+ };
175
+ }
176
+ async getModuleFiles(...folders) {
177
+ const modules = [];
178
+ for (const dir of (0, discord_js_1.normalizeArray)(folders).length ? (0, discord_js_1.normalizeArray)(folders) : (0, discord_js_1.normalizeArray)([this.client.config.modulesFolder])) {
179
+ if (!(0, fs_1.existsSync)(dir))
180
+ (0, fs_1.mkdirSync)(dir, { recursive: true });
181
+ if (!(0, fs_1.lstatSync)(dir).isDirectory())
182
+ continue;
183
+ modules.push(...(0, fs_1.readdirSync)(dir)
184
+ .map(file => path_1.default.join(flags_1.cwd, dir, file))
185
+ .filter(file => file.endsWith('.js') || file.endsWith('.cjs')));
186
+ }
187
+ return modules.filter(file => !this.client.config.ignoredFiles.some(ignored => (0, wildcard_match_1.default)(ignored, path_1.default.basename(file))));
188
+ }
189
+ static getModuleDisplayId(mod) {
190
+ return mod.info.path && mod.info.filename ? path_1.default.join(mod.info.path, mod.info.filename) : mod.id;
191
+ }
192
+ }
193
+ exports.ClientModuleManager = ClientModuleManager;
@@ -20,21 +20,24 @@ class CommandCooldownManager extends Array {
20
20
  * Remove cooldown from specific user, channel or guild
21
21
  * @param options Remove cooldown data options
22
22
  * @param limit Remove cooldown data limit
23
+ * @returns Returns the removed values
23
24
  */
24
25
  remove(options, limit = 0) {
25
26
  if (!Object.keys(options).length)
26
27
  throw new TypeError('Provide atleast one option to remove cooldown data.');
28
+ const removed = [];
27
29
  let i = 0;
28
- for (const index in this) {
29
- if (!CommandCooldownManager.checkOptions(options, this[index]))
30
+ for (let i = 0; i < this.length; i++) {
31
+ if (!CommandCooldownManager.checkOptions(options, this[i]))
30
32
  continue;
31
- if (options.expireTime && this[index].expireTime > Date.now())
33
+ if (options.expireTime && this[i].expireTime > Date.now())
32
34
  continue;
33
35
  if (limit && i >= limit)
34
36
  continue;
35
- this.splice(Number(index));
36
- i++;
37
+ removed.push(this[i]);
38
+ this.splice(Number(i));
37
39
  }
40
+ return removed;
38
41
  }
39
42
  /**
40
43
  * Check if the given user is cooled-down
@@ -44,7 +47,13 @@ class CommandCooldownManager extends Array {
44
47
  const data = this.get(options);
45
48
  if (!data)
46
49
  return false;
47
- this.remove({ ...data, channel: undefined, guild: undefined, type: undefined, command: undefined });
50
+ this.remove({
51
+ ...data,
52
+ channel: undefined,
53
+ guild: undefined,
54
+ type: undefined,
55
+ command: undefined,
56
+ });
48
57
  if (data.expireTime < Date.now())
49
58
  return false;
50
59
  return true;
@@ -19,17 +19,19 @@ function createLogger(stringifyJSON, debugmode = false, colorizeMessage = true)
19
19
  enableDebugMode: flags_1.flags.debugmode ?? debugmode,
20
20
  loggerName: 'Main',
21
21
  prefixes: {
22
- [fallout_utility_1.LogLevels.INFO]: (name) => `[${new Date().toLocaleTimeString(undefined, { hour12: false })}][${(name ? name + "/" : '') + "INFO"}]`,
23
- [fallout_utility_1.LogLevels.WARN]: (name) => `[${chalk_1.default.yellow(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.yellow((name ? name + "/" : '') + "WARN")}]`,
24
- [fallout_utility_1.LogLevels.ERROR]: (name) => `[${chalk_1.default.red(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.red((name ? name + "/" : '') + "ERROR")}]`,
25
- [fallout_utility_1.LogLevels.DEBUG]: (name) => `[${chalk_1.default.blue(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.blue((name ? name + "/" : '') + "DEBUG")}]`
22
+ [fallout_utility_1.LogLevels.INFO]: (name) => `[${new Date().toLocaleTimeString(undefined, {
23
+ hour12: false,
24
+ })}][${(name ? name + '/' : '') + 'INFO'}]`,
25
+ [fallout_utility_1.LogLevels.WARN]: (name) => `[${chalk_1.default.yellow(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.yellow((name ? name + '/' : '') + 'WARN')}]`,
26
+ [fallout_utility_1.LogLevels.ERROR]: (name) => `[${chalk_1.default.red(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.red((name ? name + '/' : '') + 'ERROR')}]`,
27
+ [fallout_utility_1.LogLevels.DEBUG]: (name) => `[${chalk_1.default.blue(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.blue((name ? name + '/' : '') + 'DEBUG')}]`,
26
28
  },
27
29
  colorMessages: {
28
30
  [fallout_utility_1.LogLevels.INFO]: (message) => message,
29
- [fallout_utility_1.LogLevels.WARN]: (message) => !colorizeMessage ? message : chalk_1.default.yellow(message),
30
- [fallout_utility_1.LogLevels.ERROR]: (message) => !colorizeMessage ? message : chalk_1.default.red(message),
31
- [fallout_utility_1.LogLevels.DEBUG]: (message) => !colorizeMessage ? message : chalk_1.default.blue(message)
32
- }
31
+ [fallout_utility_1.LogLevels.WARN]: (message) => (!colorizeMessage ? message : chalk_1.default.yellow(message)),
32
+ [fallout_utility_1.LogLevels.ERROR]: (message) => (!colorizeMessage ? message : chalk_1.default.red(message)),
33
+ [fallout_utility_1.LogLevels.DEBUG]: (message) => (!colorizeMessage ? message : chalk_1.default.blue(message)),
34
+ },
33
35
  });
34
36
  }
35
37
  exports.createLogger = createLogger;
@@ -7,10 +7,9 @@ const discord_js_1 = require("discord.js");
7
7
  * @param options options
8
8
  */
9
9
  function userHasCommandPermissions(options) {
10
- const command = (options.commandPermissions?.enabled
11
- ? options.commandPermissions?.commands.find(c => c.command.toLowerCase() === options.builder.name.toLowerCase())
12
- : null)
13
- ?? { permissions: options.builder.requiredMemberPermissions };
10
+ const command = (options.commandPermissions?.enabled ? options.commandPermissions?.commands.find(c => c.command.toLowerCase() === options.builder.name.toLowerCase()) : null) ?? {
11
+ permissions: options.builder.requiredMemberPermissions,
12
+ };
14
13
  if (!command.permissions.length)
15
14
  return true;
16
15
  return options.memberPermissions ? options.memberPermissions.has(command.permissions) : false;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deprecationWarning = exports.isClass = void 0;
3
+ exports.validateCommandBuilder = exports.deprecationWarning = exports.isClass = void 0;
4
+ const builders_1 = require("./types/builders");
4
5
  /**
5
6
  * Check if an object is a class
6
7
  * @param object Object to identify
@@ -21,3 +22,11 @@ function deprecationWarning(content) {
21
22
  process.emitWarning(content, 'DeprecationWarning');
22
23
  }
23
24
  exports.deprecationWarning = deprecationWarning;
25
+ function validateCommandBuilder(command) {
26
+ if (!command.name)
27
+ return false;
28
+ if (command.type === builders_1.CommandBuilderType.MessageCommand && command.options.length && command.options.some(o => !o.name))
29
+ return false;
30
+ return true;
31
+ }
32
+ exports.validateCommandBuilder = validateCommandBuilder;
@@ -1,17 +1,18 @@
1
- export * from './reciple/classes/CommandCooldownManager';
2
- export * from './reciple/classes/MessageCommandOptionManager';
3
- export * from './reciple/classes/RecipleClient';
4
- export * from './reciple/classes/RecipleConfig';
5
1
  export * from './reciple/classes/builders/MessageCommandBuilder';
6
2
  export * from './reciple/classes/builders/MessageCommandOptionBuilder';
7
3
  export * from './reciple/classes/builders/SlashCommandBuilder';
4
+ export * from './reciple/classes/managers/ApplicationCommandManager';
5
+ export * from './reciple/classes/managers/CommandCooldownManager';
6
+ export * from './reciple/classes/managers/ClientCommandManager';
7
+ export * from './reciple/classes/managers/ClientModuleManager';
8
+ export * from './reciple/classes/managers/MessageCommandOptionManager';
9
+ export * from './reciple/classes/RecipleClient';
10
+ export * from './reciple/classes/RecipleConfig';
8
11
  export * from './reciple/types/builders';
9
12
  export * from './reciple/types/commands';
10
13
  export * from './reciple/types/paramOptions';
11
14
  export * from './reciple/flags';
12
15
  export * from './reciple/logger';
13
- export * from './reciple/modules';
14
16
  export * from './reciple/permissions';
15
- export * from './reciple/registerApplicationCommands';
16
17
  export * from './reciple/util';
17
18
  export * from './reciple/version';
@@ -1,33 +1,19 @@
1
1
  import { MessageCommandBuilder, MessageCommandExecuteData, MessageCommandHaltData } from './builders/MessageCommandBuilder';
2
+ import { Awaitable, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, Interaction, Message } from 'discord.js';
2
3
  import { SlashCommandBuilder, SlashCommandExecuteData, SlashCommandHaltData } from './builders/SlashCommandBuilder';
3
- import { AnyCommandBuilder, AnyCommandData, AnySlashCommandBuilder, CommandBuilderType } from '../types/builders';
4
- import { ApplicationCommandBuilder } from '../registerApplicationCommands';
5
4
  import { AnyCommandExecuteData, AnyCommandHaltData } from '../types/commands';
6
- import { CommandCooldownManager } from './CommandCooldownManager';
7
- import { RecipleClientAddModuleOptions } from '../types/paramOptions';
5
+ import { CommandCooldownManager } from './managers/CommandCooldownManager';
6
+ import { ApplicationCommandManager } from './managers/ApplicationCommandManager';
7
+ import { ClientCommandManager } from './managers/ClientCommandManager';
8
+ import { ClientModuleManager } from './managers/ClientModuleManager';
8
9
  import { Config } from './RecipleConfig';
9
- import { RecipleModule } from '../modules';
10
10
  import { Logger } from 'fallout-utility';
11
- import { ApplicationCommandData, Awaitable, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, Collection, Interaction, Message, RestOrArray } from 'discord.js';
12
11
  /**
13
12
  * Options for {@link RecipleClient}
14
13
  */
15
14
  export interface RecipleClientOptions extends ClientOptions {
16
15
  config?: Config;
17
16
  }
18
- /**
19
- * Reciple client commands
20
- */
21
- export interface RecipleClientCommands {
22
- /**
23
- * Collection of loaded slash commands
24
- */
25
- slashCommands: Collection<string, AnySlashCommandBuilder>;
26
- /**
27
- * Collection of loaded message commands
28
- */
29
- messageCommands: Collection<string, MessageCommandBuilder>;
30
- }
31
17
  /**
32
18
  * Reciple client events
33
19
  */
@@ -54,37 +40,18 @@ export interface RecipleClient<Ready extends boolean = boolean> extends Client<R
54
40
  isReady(): this is RecipleClient<true>;
55
41
  }
56
42
  export declare class RecipleClient<Ready extends boolean = boolean> extends Client<Ready> {
57
- config: Config;
58
- commands: RecipleClientCommands;
59
- additionalApplicationCommands: (ApplicationCommandBuilder | ApplicationCommandData)[];
60
- cooldowns: CommandCooldownManager;
61
- modules: RecipleModule[];
62
- logger: Logger;
63
- version: string;
43
+ readonly config: Config;
44
+ readonly commands: ClientCommandManager;
45
+ readonly applicationCommands: ApplicationCommandManager;
46
+ readonly cooldowns: CommandCooldownManager;
47
+ readonly modules: ClientModuleManager;
48
+ readonly logger: Logger;
49
+ readonly version: string;
50
+ get isClientLogsSilent(): boolean;
64
51
  /**
65
52
  * @param options Client options
66
53
  */
67
54
  constructor(options: RecipleClientOptions);
68
- /**
69
- * Load and start modules from given folders
70
- * @param folders folders that contains the modules you want to load
71
- */
72
- startModules(...folders: RestOrArray<string>): Promise<this>;
73
- /**
74
- * Execute {@link RecipleModule['onLoad']} from client modules and register application commands if enabled
75
- */
76
- loadModules(): Promise<this>;
77
- /**
78
- * Add module
79
- * @param options Module options
80
- * @deprecated This is very stupid, Just add it manually
81
- */
82
- addModule(options: RecipleClientAddModuleOptions): Promise<void>;
83
- /**
84
- * Add slash or message command to client
85
- * @param command Slash/Message command builder
86
- */
87
- addCommand(command: AnyCommandData | AnyCommandBuilder): RecipleClient<Ready>;
88
55
  /**
89
56
  * Listed to command executions
90
57
  */
@@ -93,34 +60,19 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
93
60
  * Execute a slash command
94
61
  * @param interaction Slash command interaction
95
62
  */
96
- slashCommandExecute(interaction: Interaction | ChatInputCommandInteraction): Promise<void | SlashCommandExecuteData>;
63
+ slashCommandExecute(interaction: Interaction | ChatInputCommandInteraction): Promise<undefined | SlashCommandExecuteData>;
97
64
  /**
98
65
  * Execute a Message command
99
66
  * @param message Message command executor
100
67
  * @param prefix Message command prefix
101
68
  */
102
- messageCommandExecute(message: Message, prefix?: string): Promise<void | MessageCommandExecuteData>;
103
- /**
104
- * Registers client slash commands and other application commands
105
- */
106
- registerClientApplicationCommands(): Promise<void>;
69
+ messageCommandExecute(message: Message, prefix?: string): Promise<undefined | MessageCommandExecuteData>;
107
70
  /**
108
71
  * Get a message from config
109
72
  * @param messageKey Config messages key
110
73
  * @param defaultMessage Default message when the key does not exists
111
74
  */
112
75
  getConfigMessage<T = unknown>(messageKey: string, defaultMessage?: T): T;
113
- /**
114
- * Get command builder by name or alias if it's a message command
115
- * @param command Command name
116
- * @param type Command type
117
- */
118
- findCommand(command: string, type: CommandBuilderType.MessageCommand): MessageCommandBuilder | undefined;
119
- findCommand(command: string, type: CommandBuilderType.SlashCommand): SlashCommandBuilder | undefined;
120
- /**
121
- * Returns true if client logs is enabled
122
- */
123
- isClientLogsEnabled(): boolean;
124
76
  /**
125
77
  * Emits the {@link RecipleClientEvents["recipleReplyError"]} event
126
78
  * @param error Received Error
@@ -138,8 +90,8 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
138
90
  * @param command Command builder
139
91
  * @param executeData Command execute data
140
92
  */
141
- protected _executeCommand(command: SlashCommandBuilder, executeData: SlashCommandExecuteData): Promise<SlashCommandExecuteData | void>;
142
- protected _executeCommand(command: MessageCommandBuilder, executeData: MessageCommandExecuteData): Promise<MessageCommandExecuteData | void>;
93
+ protected _executeCommand(command: SlashCommandBuilder, executeData: SlashCommandExecuteData): Promise<SlashCommandExecuteData | undefined>;
94
+ protected _executeCommand(command: MessageCommandBuilder, executeData: MessageCommandExecuteData): Promise<MessageCommandExecuteData | undefined>;
143
95
  /**
144
96
  * Error message when a command fails to execute
145
97
  * @param err Received error