reciple 6.0.0-dev.1 → 6.0.0-dev.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/cjs/bin.js +11 -7
  2. package/dist/cjs/index.js +3 -3
  3. package/dist/cjs/reciple/classes/RecipleClient.js +86 -45
  4. package/dist/cjs/reciple/classes/RecipleConfig.js +9 -2
  5. package/dist/cjs/reciple/classes/RecipleModule.js +94 -0
  6. package/dist/cjs/reciple/classes/builders/MessageCommandBuilder.js +6 -4
  7. package/dist/cjs/reciple/classes/builders/SlashCommandBuilder.js +12 -23
  8. package/dist/cjs/reciple/classes/managers/ApplicationCommandManager.js +32 -33
  9. package/dist/cjs/reciple/classes/managers/ClientCommandManager.js +14 -14
  10. package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +93 -115
  11. package/dist/cjs/reciple/classes/managers/CommandCooldownManager.js +7 -1
  12. package/dist/cjs/reciple/permissions.js +3 -4
  13. package/dist/cjs/reciple/types/builders.js +6 -6
  14. package/dist/cjs/reciple/util.js +36 -2
  15. package/dist/types/index.d.ts +3 -3
  16. package/dist/types/reciple/classes/RecipleClient.d.ts +3 -6
  17. package/dist/types/reciple/classes/RecipleModule.d.ts +56 -0
  18. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +6 -6
  19. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +17 -17
  20. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +6 -11
  21. package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +3 -3
  22. package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +10 -70
  23. package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +2 -2
  24. package/dist/types/reciple/types/builders.d.ts +19 -19
  25. package/dist/types/reciple/types/commands.d.ts +10 -10
  26. package/dist/types/reciple/types/paramOptions.d.ts +1 -16
  27. package/dist/types/reciple/util.d.ts +8 -0
  28. package/package.json +17 -13
  29. package/dist/cjs/reciple/logger.js +0 -35
  30. package/dist/cjs/reciple/modules.js +0 -113
  31. package/dist/types/reciple/logger.d.ts +0 -8
  32. package/dist/types/reciple/modules.d.ts +0 -64
  33. package/docs/README.md +0 -1
@@ -7,98 +7,101 @@ class ApplicationCommandManager {
7
7
  constructor(client) {
8
8
  this.client = client;
9
9
  }
10
- get commands() { return this.client.application?.commands; }
11
- async set(commands, guilds) {
10
+ async set(commands, ...guilds) {
11
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
12
12
  if (!this.client.isReady())
13
13
  throw new Error('Client is not ready');
14
14
  if (guilds && guilds.length > 1) {
15
15
  for (const guild of guilds) {
16
- await this.set(commands, [guild]);
16
+ await this.set(commands, guild);
17
17
  }
18
18
  return;
19
19
  }
20
20
  let guild = guilds?.shift();
21
21
  guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
22
22
  if (!guild) {
23
- this.client.application.commands.set(commands);
24
- if (this.client.isClientLogsEnabled())
23
+ await this.client.application.commands.set(commands);
24
+ if (!this.client.isClientLogsSilent)
25
25
  this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) globally...`);
26
26
  }
27
27
  else {
28
- this.client.application.commands.set(commands, guild);
29
- if (this.client.isClientLogsEnabled())
28
+ await this.client.application.commands.set(commands, guild);
29
+ if (!this.client.isClientLogsSilent)
30
30
  this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) to guild ${guild}...`);
31
31
  }
32
32
  }
33
- async add(command, guilds) {
33
+ async add(command, ...guilds) {
34
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
34
35
  if (!this.client.isReady())
35
36
  throw new Error('Client is not ready');
36
37
  if (!command)
37
38
  throw new Error('Command is undefined');
38
39
  if (guilds && guilds.length > 1) {
39
40
  for (const guild of guilds) {
40
- await this.add(command, [guild]);
41
+ await this.add(command, guild);
41
42
  }
42
43
  return;
43
44
  }
44
45
  let guild = guilds?.shift();
45
46
  guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
46
47
  if (!guild) {
47
- this.client.application.commands.create(command);
48
- if (this.client.isClientLogsEnabled())
48
+ await this.client.application.commands.create(command);
49
+ if (!this.client.isClientLogsSilent)
49
50
  this.client.logger.log(`Created application command '${command.name}' globally`);
50
51
  }
51
52
  else {
52
- this.client.application.commands.create(command, guild);
53
- if (this.client.isClientLogsEnabled())
53
+ await this.client.application.commands.create(command, guild);
54
+ if (!this.client.isClientLogsSilent)
54
55
  this.client.logger.log(`Created application command '${command.name}' to guild ${guild}`);
55
56
  }
56
57
  }
57
- async remove(command, guilds) {
58
+ async remove(command, ...guilds) {
59
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
58
60
  if (!this.client.isReady())
59
61
  throw new Error('Client is not ready');
60
62
  if (!command)
61
63
  throw new Error('Command is undefined');
62
64
  if (guilds && guilds.length > 1) {
63
65
  for (const guild of guilds) {
64
- await this.remove(command, [guild]);
66
+ await this.remove(command, guild);
65
67
  }
66
68
  return;
67
69
  }
68
70
  let guild = guilds?.shift();
69
71
  guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
70
72
  if (!guild) {
71
- this.client.application.commands.delete(command);
72
- if (this.client.isClientLogsEnabled())
73
+ await this.client.application.commands.delete(command);
74
+ if (!this.client.isClientLogsSilent)
73
75
  this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
74
76
  }
75
77
  else {
76
- this.client.application.commands.delete(command, guild);
77
- if (this.client.isClientLogsEnabled())
78
+ await this.client.application.commands.delete(command, guild);
79
+ if (!this.client.isClientLogsSilent)
78
80
  this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
79
81
  }
80
82
  }
81
- async edit(command, newCommand, guilds) {
83
+ async edit(command, newCommand, ...guilds) {
84
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
82
85
  if (!this.client.isReady())
83
86
  throw new Error('Client is not ready');
84
87
  if (!command)
85
88
  throw new Error('Command is undefined');
86
89
  if (guilds && guilds.length > 1) {
87
90
  for (const guild of guilds) {
88
- await this.edit(command, newCommand, [guild]);
91
+ await this.edit(command, newCommand, guild);
89
92
  }
90
93
  return;
91
94
  }
92
95
  let guild = guilds?.shift();
93
96
  guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
94
97
  if (!guild) {
95
- this.client.application.commands.edit(command, newCommand);
96
- if (this.client.isClientLogsEnabled())
98
+ await this.client.application.commands.edit(command, newCommand);
99
+ if (!this.client.isClientLogsSilent)
97
100
  this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
98
101
  }
99
102
  else {
100
- this.client.application.commands.edit(command, newCommand, guild);
101
- if (this.client.isClientLogsEnabled())
103
+ await this.client.application.commands.edit(command, newCommand, guild);
104
+ if (!this.client.isClientLogsSilent)
102
105
  this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
103
106
  }
104
107
  }
@@ -106,9 +109,7 @@ class ApplicationCommandManager {
106
109
  const commands = guild ? this.client.guilds.resolve(guild)?.commands.cache : this.client.application?.commands.cache;
107
110
  if (!commands)
108
111
  throw new Error('Guild not found in cache');
109
- return commands.find(cmd => typeof command === 'string'
110
- ? (cmd.id === command || cmd.name === command)
111
- : (cmd.name === command.name || (command instanceof discord_js_1.ApplicationCommand && cmd.id === command.id)));
112
+ 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
  }
113
114
  async fetch(commandId, guild) {
114
115
  const manager = guild ? this.client.guilds.resolve(guild)?.commands : this.client.application?.commands;
@@ -119,14 +120,12 @@ class ApplicationCommandManager {
119
120
  parseCommands(commands, setPermissions = true) {
120
121
  return commands.map(cmd => {
121
122
  if (cmd?.toJSON === undefined)
122
- return (cmd);
123
+ return cmd;
123
124
  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;
125
+ 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
126
  if (permissions) {
128
127
  cmd.setRequiredMemberPermissions(...permissions);
129
- if (this.client.isClientLogsEnabled())
128
+ if (!this.client.isClientLogsSilent)
130
129
  this.client.logger.debug(`Set required permissions for ${cmd.name}`);
131
130
  }
132
131
  }
@@ -14,31 +14,33 @@ class ClientCommandManager {
14
14
  options.slashCommands?.forEach(e => this.slashCommands.set(e.name, SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(e)));
15
15
  options.messageCommands?.forEach(e => this.messageCommands.set(e.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(e)));
16
16
  }
17
- get applicationCommandsSize() { return this.client.commands.slashCommands.size + this.client.commands.additionalApplicationCommands.length; }
17
+ get applicationCommandsSize() {
18
+ return this.client.commands.slashCommands.size + this.client.commands.additionalApplicationCommands.length;
19
+ }
18
20
  /**
19
21
  * Add command to command manager
20
22
  * @param commands Any command data or builder
21
23
  */
22
24
  add(...commands) {
23
25
  for (const command of (0, discord_js_1.normalizeArray)(commands)) {
24
- if (command.type === builders_1.CommandBuilderType.SlashCommand) {
26
+ if (command.type === builders_1.CommandType.SlashCommand) {
25
27
  this.slashCommands.set(command.name, SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
26
28
  }
27
- else if (command.type === builders_1.CommandBuilderType.MessageCommand) {
29
+ else if (command.type === builders_1.CommandType.MessageCommand) {
28
30
  this.messageCommands.set(command.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
29
31
  }
32
+ else {
33
+ throw new Error(`Unknown reciple command type`);
34
+ }
30
35
  }
31
36
  return this;
32
37
  }
33
38
  get(command, type) {
34
39
  switch (type) {
35
- case builders_1.CommandBuilderType.SlashCommand:
40
+ case builders_1.CommandType.SlashCommand:
36
41
  return this.slashCommands.get(command);
37
- case builders_1.CommandBuilderType.MessageCommand:
38
- return this.messageCommands.get(command.toLowerCase())
39
- ?? (this.client.config.commands.messageCommand.allowCommandAlias
40
- ? this.messageCommands.find(c => c.aliases.some(a => a == command?.toLowerCase()))
41
- : undefined);
42
+ case builders_1.CommandType.MessageCommand:
43
+ return this.messageCommands.get(command.toLowerCase()) ?? (this.client.config.commands.messageCommand.allowCommandAlias ? this.messageCommands.find(c => c.aliases.some(a => a == command?.toLowerCase())) : undefined);
42
44
  default:
43
45
  throw new TypeError('Unknown command type');
44
46
  }
@@ -49,13 +51,11 @@ class ClientCommandManager {
49
51
  */
50
52
  async registerApplicationCommands(...guilds) {
51
53
  guilds = (0, discord_js_1.normalizeArray)(guilds);
52
- guilds = guilds.length
53
- ? guilds
54
- : (0, discord_js_1.normalizeArray)([this.client.config.commands.slashCommand.guilds]);
55
- if (this.client.isClientLogsEnabled())
54
+ guilds = guilds.length ? guilds : (0, discord_js_1.normalizeArray)([this.client.config.commands.slashCommand.guilds]);
55
+ if (!this.client.isClientLogsSilent)
56
56
  this.client.logger.log(`Regestering ${this.applicationCommandsSize} application command(s) ${!guilds.length ? 'globaly' : 'to ' + guilds.length + ' guilds'}...`);
57
57
  await this.client.applicationCommands.set([...this.slashCommands.toJSON(), ...this.additionalApplicationCommands], guilds);
58
- this.client.emit('RegisterApplicationCommands');
58
+ this.client.emit('recipleRegisterApplicationCommands');
59
59
  return this;
60
60
  }
61
61
  }
@@ -27,163 +27,141 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.ClientModuleManager = void 0;
30
- const crypto_1 = require("crypto");
31
30
  const discord_js_1 = require("discord.js");
32
31
  const fs_1 = require("fs");
33
32
  const path_1 = __importDefault(require("path"));
33
+ const util_1 = require("util");
34
34
  const wildcard_match_1 = __importDefault(require("wildcard-match"));
35
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");
36
+ const RecipleModule_1 = require("../RecipleModule");
41
37
  class ClientModuleManager {
42
38
  constructor(options) {
43
39
  this.modules = new discord_js_1.Collection();
44
40
  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
- });
41
+ options.modules?.forEach(m => (m instanceof RecipleModule_1.RecipleModule ? m : new RecipleModule_1.RecipleModule({ client: this.client, script: m })));
50
42
  }
51
- async startModulesFromFiles(options) {
52
- const modules = await this.resolveModulesFromFiles(options);
43
+ async startModules(modules, ignoreErrors = true) {
53
44
  for (const module_ of modules) {
45
+ if (!this.client.isClientLogsSilent)
46
+ this.client.logger.log(`Starting module '${module_}'`);
54
47
  try {
55
- await this.startModule(module_);
48
+ let error;
49
+ const start = await module_.start().catch(err => {
50
+ error = err;
51
+ return false;
52
+ });
53
+ if (error)
54
+ throw new Error(`An error occured while loading module '${module_}': \n${(0, util_1.inspect)(error)}`);
55
+ if (!start) {
56
+ if (!this.client.isClientLogsSilent)
57
+ this.client.logger.error(`Module '${module_}' returned false onStart`);
58
+ continue;
59
+ }
60
+ this.modules.set(module_.id, module_);
56
61
  }
57
62
  catch (err) {
58
- if (options.dontSkipError)
63
+ if (!ignoreErrors)
59
64
  throw err;
60
- if (this.client.isClientLogsEnabled())
61
- this.client.logger.err(`Cannot start module ${ClientModuleManager.getModuleDisplayId(module_)}:`, err);
65
+ if (!this.client.isClientLogsSilent)
66
+ this.client.logger.error(`Failed to start module '${module_}': `, err);
62
67
  }
63
68
  }
64
69
  return modules;
65
70
  }
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;
71
+ async loadModules(modules, addModuleCommandsToClient = true, ignoreErrors = true) {
72
+ for (const module_ of this.modules.toJSON()) {
74
73
  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.isClientLogsEnabled())
87
- this.client.logger.log(`Resolved ${file}`);
74
+ await module_.load().catch(err => {
75
+ throw err;
76
+ });
77
+ if (!this.client.isClientLogsSilent)
78
+ this.client.logger.log(`Loaded module '${module_}'`);
79
+ if (addModuleCommandsToClient) {
80
+ this.client.commands.add(module_.commands);
81
+ }
88
82
  }
89
83
  catch (err) {
90
- if (options.dontSkipError)
84
+ if (!ignoreErrors)
91
85
  throw err;
92
- if (this.client.isClientLogsEnabled())
93
- this.client.logger.err(`Cannot resolve module file ${file}:`, err);
86
+ if (!this.client.isClientLogsSilent)
87
+ this.client.logger.error(`Failed to load module '${module_}': `, err);
94
88
  }
95
89
  }
96
90
  return modules;
97
91
  }
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
- }
92
+ async unLoadModules(modules, removeUnloadedModules = true, ignoreErrors = true) {
93
+ for (const module_ of this.modules.toJSON()) {
94
+ try {
95
+ await module_.unLoad().catch(err => {
96
+ throw err;
97
+ });
98
+ if (removeUnloadedModules)
99
+ this.modules.delete(module_.id);
100
+ if (!this.client.isClientLogsSilent)
101
+ this.client.logger.log(`Unloaded module '${module_}'`);
102
+ }
103
+ catch (err) {
104
+ if (!ignoreErrors)
105
+ throw err;
106
+ if (!this.client.isClientLogsSilent)
107
+ this.client.logger.error(`Failed to unLoad module '${module_}': `, err);
111
108
  }
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
109
  }
120
- return resolvedCommands;
110
+ return modules;
121
111
  }
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 => { throw err; });
127
- }
128
- catch (err) {
129
- this.modules.delete(m.id);
130
- if (this.client.isClientLogsEnabled())
131
- this.client.logger.error(`Error loading ${m.info.filename ?? 'unknown module'}:`, err);
132
- return;
112
+ async getModulesFromFiles(options) {
113
+ const modules = [];
114
+ for (const file of options.files) {
115
+ try {
116
+ const resolveFile = await Promise.resolve().then(() => __importStar(require(file)));
117
+ let script = resolveFile?.default ?? resolveFile;
118
+ if (script instanceof RecipleModule_1.RecipleModule) {
119
+ modules.push(script);
120
+ continue;
133
121
  }
122
+ if (!ClientModuleManager.validateScript(script))
123
+ throw new Error(`Invalid module script: ${file}`);
124
+ modules.push(new RecipleModule_1.RecipleModule({
125
+ client: this.client,
126
+ script,
127
+ filePath: file,
128
+ }));
129
+ }
130
+ catch (err) {
131
+ if (options.dontSkipError)
132
+ throw err;
133
+ if (!this.client.isClientLogsSilent)
134
+ this.client.logger.error(`Can't resolve module from: ${file}`, err);
134
135
  }
135
- this.client.commands.add(m.commands);
136
- if (this.client.isClientLogsEnabled())
137
- this.client.logger.log(`Loaded module: ${ClientModuleManager.getModuleDisplayId(m)}`);
138
- }));
139
- if (this.client.isClientLogsEnabled()) {
140
- this.client.logger.info(`${this.modules.size} modules loaded.`);
141
- this.client.logger.info(`${this.client.commands.messageCommands.size} message commands loaded.`);
142
- this.client.logger.info(`${this.client.commands.slashCommands.size} slash commands loaded.`);
143
136
  }
144
- if (registerApplicationCommands)
145
- this.client.commands.registerApplicationCommands((0, discord_js_1.normalizeArray)(registerApplicationCommandsGuilds));
146
- }
147
- async startModule(mod) {
148
- let err;
149
- const identifier = ClientModuleManager.getModuleDisplayId(mod);
150
- if (this.client.isClientLogsEnabled())
151
- this.client.logger.log(`Starting Module: ${identifier}`);
152
- const start = await Promise.resolve(mod.script.onStart(this.client)).catch(e => err = e);
153
- if (err)
154
- throw err;
155
- if (!start)
156
- throw new Error(`Module ${identifier} returned 'false' on start`);
157
- this.modules.set(mod.id, mod);
137
+ return modules;
158
138
  }
159
- resolveModule(mod, disabeVersionCheck) {
160
- const identifier = ClientModuleManager.getModuleDisplayId(mod);
161
- if (!disabeVersionCheck && !mod?.script?.versions?.length)
162
- throw new Error(`Module ${identifier} does not contain supported versions`);
163
- if (typeof mod.script?.onStart !== 'function')
164
- throw new Error(`Module ${identifier} does not have a valid 'onStart' method`);
165
- const versions = (0, discord_js_1.normalizeArray)([mod.script.versions]);
166
- const commands = this.resolveScriptCommands(mod.script)[0].commands;
167
- if (!disabeVersionCheck && !versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
168
- throw new Error(`Module ${identifier} does not support 'reciple@${version_1.rawVersion}'`);
169
- return {
170
- ...mod,
171
- commands,
172
- };
139
+ static validateScript(script) {
140
+ const s = script;
141
+ if (typeof s !== 'object')
142
+ return false;
143
+ if (typeof s.versions !== 'string' && !Array.isArray(s.versions))
144
+ return false;
145
+ if (typeof s.onStart !== 'function')
146
+ return false;
147
+ if (s.onLoad && typeof s.onLoad !== 'function')
148
+ return false;
149
+ if (s.onUnLoad && typeof s.onUnLoad !== 'function')
150
+ return false;
151
+ return true;
173
152
  }
174
153
  async getModuleFiles(...folders) {
175
154
  const modules = [];
176
- 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]))) {
155
+ 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])) {
177
156
  if (!(0, fs_1.existsSync)(dir))
178
157
  (0, fs_1.mkdirSync)(dir, { recursive: true });
179
158
  if (!(0, fs_1.lstatSync)(dir).isDirectory())
180
159
  continue;
181
- modules.push(...(0, fs_1.readdirSync)(dir).map(file => path_1.default.join(flags_1.cwd, dir, file)).filter(file => file.endsWith('.js') || file.endsWith('.cjs')));
160
+ modules.push(...(0, fs_1.readdirSync)(dir)
161
+ .map(file => path_1.default.join(flags_1.cwd, dir, file))
162
+ .filter(file => file.endsWith('.js') || file.endsWith('.cjs')));
182
163
  }
183
- return modules.filter(file => !this.client.config.ignoredFiles.some(ignored => (0, wildcard_match_1.default)(ignored, path_1.default.basename(file))));
184
- }
185
- static getModuleDisplayId(mod) {
186
- return mod.info.path && mod.info.filename ? path_1.default.join(mod.info.path, mod.info.filename) : mod.id;
164
+ return modules.filter(file => !this.client.config.ignoredFiles.some(ignored => (0, wildcard_match_1.default)(ignored)(path_1.default.basename(file))));
187
165
  }
188
166
  }
189
167
  exports.ClientModuleManager = ClientModuleManager;
@@ -47,7 +47,13 @@ class CommandCooldownManager extends Array {
47
47
  const data = this.get(options);
48
48
  if (!data)
49
49
  return false;
50
- 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
+ });
51
57
  if (data.expireTime < Date.now())
52
58
  return false;
53
59
  return true;
@@ -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,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommandBuilderType = void 0;
3
+ exports.CommandType = void 0;
4
4
  /**
5
5
  * Types of command builders
6
6
  */
7
- var CommandBuilderType;
8
- (function (CommandBuilderType) {
9
- CommandBuilderType[CommandBuilderType["MessageCommand"] = 0] = "MessageCommand";
10
- CommandBuilderType[CommandBuilderType["SlashCommand"] = 1] = "SlashCommand";
11
- })(CommandBuilderType = exports.CommandBuilderType || (exports.CommandBuilderType = {}));
7
+ var CommandType;
8
+ (function (CommandType) {
9
+ CommandType[CommandType["MessageCommand"] = 0] = "MessageCommand";
10
+ CommandType[CommandType["SlashCommand"] = 1] = "SlashCommand";
11
+ })(CommandType = exports.CommandType || (exports.CommandType = {}));
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateCommandBuilder = exports.deprecationWarning = exports.isClass = void 0;
6
+ exports.createLogger = exports.validateCommandBuilder = exports.deprecationWarning = exports.isClass = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const fallout_utility_1 = require("fallout-utility");
9
+ const flags_1 = require("./flags");
4
10
  const builders_1 = require("./types/builders");
5
11
  /**
6
12
  * Check if an object is a class
@@ -25,8 +31,36 @@ exports.deprecationWarning = deprecationWarning;
25
31
  function validateCommandBuilder(command) {
26
32
  if (!command.name)
27
33
  return false;
28
- if (command.type === builders_1.CommandBuilderType.MessageCommand && command.options.length && command.options.some(o => !o.name))
34
+ if (command.type === builders_1.CommandType.MessageCommand && command.options.length && command.options.some(o => !o.name))
29
35
  return false;
30
36
  return true;
31
37
  }
32
38
  exports.validateCommandBuilder = validateCommandBuilder;
39
+ /**
40
+ * Create new logger
41
+ * @param stringifyJSON stringify json objects in console
42
+ * @param debugmode display debug messages
43
+ * @param colorizeMessage add logger colours to messages
44
+ */
45
+ function createLogger(stringifyJSON, debugmode = false, colorizeMessage = true) {
46
+ return new fallout_utility_1.Logger({
47
+ stringifyJSON: stringifyJSON,
48
+ enableDebugMode: flags_1.flags.debugmode ?? debugmode,
49
+ loggerName: 'Main',
50
+ prefixes: {
51
+ [fallout_utility_1.LogLevels.INFO]: (name) => `[${new Date().toLocaleTimeString(undefined, {
52
+ hour12: false,
53
+ })}][${(name ? name + '/' : '') + 'INFO'}]`,
54
+ [fallout_utility_1.LogLevels.WARN]: (name) => `[${chalk_1.default.yellow(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.yellow((name ? name + '/' : '') + 'WARN')}]`,
55
+ [fallout_utility_1.LogLevels.ERROR]: (name) => `[${chalk_1.default.red(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.red((name ? name + '/' : '') + 'ERROR')}]`,
56
+ [fallout_utility_1.LogLevels.DEBUG]: (name) => `[${chalk_1.default.blue(new Date().toLocaleTimeString(undefined, { hour12: false }))}][${chalk_1.default.blue((name ? name + '/' : '') + 'DEBUG')}]`,
57
+ },
58
+ colorMessages: {
59
+ [fallout_utility_1.LogLevels.INFO]: (message) => message,
60
+ [fallout_utility_1.LogLevels.WARN]: (message) => (!colorizeMessage ? message : chalk_1.default.yellow(message)),
61
+ [fallout_utility_1.LogLevels.ERROR]: (message) => (!colorizeMessage ? message : chalk_1.default.red(message)),
62
+ [fallout_utility_1.LogLevels.DEBUG]: (message) => (!colorizeMessage ? message : chalk_1.default.blue(message)),
63
+ },
64
+ });
65
+ }
66
+ exports.createLogger = createLogger;
@@ -2,17 +2,17 @@ export * from './reciple/classes/builders/MessageCommandBuilder';
2
2
  export * from './reciple/classes/builders/MessageCommandOptionBuilder';
3
3
  export * from './reciple/classes/builders/SlashCommandBuilder';
4
4
  export * from './reciple/classes/managers/ApplicationCommandManager';
5
- export * from './reciple/classes/managers/CommandCooldownManager';
6
5
  export * from './reciple/classes/managers/ClientCommandManager';
6
+ export * from './reciple/classes/managers/ClientModuleManager';
7
+ export * from './reciple/classes/managers/CommandCooldownManager';
7
8
  export * from './reciple/classes/managers/MessageCommandOptionManager';
8
9
  export * from './reciple/classes/RecipleClient';
9
10
  export * from './reciple/classes/RecipleConfig';
11
+ export * from './reciple/classes/RecipleModule';
10
12
  export * from './reciple/types/builders';
11
13
  export * from './reciple/types/commands';
12
14
  export * from './reciple/types/paramOptions';
13
15
  export * from './reciple/flags';
14
- export * from './reciple/logger';
15
- export * from './reciple/modules';
16
16
  export * from './reciple/permissions';
17
17
  export * from './reciple/util';
18
18
  export * from './reciple/version';
@@ -1,13 +1,13 @@
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
4
  import { AnyCommandExecuteData, AnyCommandHaltData } from '../types/commands';
4
5
  import { CommandCooldownManager } from './managers/CommandCooldownManager';
5
6
  import { ApplicationCommandManager } from './managers/ApplicationCommandManager';
6
7
  import { ClientCommandManager } from './managers/ClientCommandManager';
8
+ import { ClientModuleManager } from './managers/ClientModuleManager';
7
9
  import { Config } from './RecipleConfig';
8
10
  import { Logger } from 'fallout-utility';
9
- import { Awaitable, ChatInputCommandInteraction, Client, ClientEvents, ClientOptions, Interaction, Message } from 'discord.js';
10
- import { ClientModuleManager } from './managers/ClientModuleManager';
11
11
  /**
12
12
  * Options for {@link RecipleClient}
13
13
  */
@@ -47,6 +47,7 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
47
47
  readonly modules: ClientModuleManager;
48
48
  readonly logger: Logger;
49
49
  readonly version: string;
50
+ get isClientLogsSilent(): boolean;
50
51
  /**
51
52
  * @param options Client options
52
53
  */
@@ -72,10 +73,6 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
72
73
  * @param defaultMessage Default message when the key does not exists
73
74
  */
74
75
  getConfigMessage<T = unknown>(messageKey: string, defaultMessage?: T): T;
75
- /**
76
- * Returns true if client logs is enabled
77
- */
78
- isClientLogsEnabled(): boolean;
79
76
  /**
80
77
  * Emits the {@link RecipleClientEvents["recipleReplyError"]} event
81
78
  * @param error Received Error