reciple 6.0.0-dev.6 → 6.0.0-dev.7

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.
package/dist/cjs/bin.js CHANGED
@@ -34,11 +34,13 @@ if (!client.isClientLogsSilent)
34
34
  client.logger.info('Starting Reciple client v' + version_1.rawVersion);
35
35
  (async () => {
36
36
  client.addCommandListeners();
37
- await client.modules.startModulesFromFiles({
37
+ await client.modules.startModules(await client.modules.getModulesFromFiles({
38
38
  files: await client.modules.getModuleFiles(),
39
- });
39
+ }), true, true);
40
40
  client.on('ready', async () => {
41
- await client.modules.loadAll(true);
41
+ await client.modules.loadModules(client.modules.modules.toJSON());
42
+ if (client.config.commands.slashCommand.registerCommands)
43
+ client.commands.registerApplicationCommands();
42
44
  if (!client.isClientLogsSilent)
43
45
  client.logger.warn(`Logged in as ${client.user?.tag || 'Unknown'}!`);
44
46
  client.on('cacheSweep', () => client.cooldowns.clean());
package/dist/cjs/index.js CHANGED
@@ -24,11 +24,11 @@ __exportStar(require("./reciple/classes/managers/ClientModuleManager"), exports)
24
24
  __exportStar(require("./reciple/classes/managers/MessageCommandOptionManager"), exports);
25
25
  __exportStar(require("./reciple/classes/RecipleClient"), exports);
26
26
  __exportStar(require("./reciple/classes/RecipleConfig"), exports);
27
+ __exportStar(require("./reciple/classes/RecipleModule"), exports);
27
28
  __exportStar(require("./reciple/types/builders"), exports);
28
29
  __exportStar(require("./reciple/types/commands"), exports);
29
30
  __exportStar(require("./reciple/types/paramOptions"), exports);
30
31
  __exportStar(require("./reciple/flags"), exports);
31
- __exportStar(require("./reciple/logger"), exports);
32
32
  __exportStar(require("./reciple/permissions"), exports);
33
33
  __exportStar(require("./reciple/util"), exports);
34
34
  __exportStar(require("./reciple/version"), exports);
@@ -17,7 +17,7 @@ const ClientCommandManager_1 = require("./managers/ClientCommandManager");
17
17
  const ClientModuleManager_1 = require("./managers/ClientModuleManager");
18
18
  const RecipleConfig_1 = require("./RecipleConfig");
19
19
  const fallout_utility_1 = require("fallout-utility");
20
- const logger_1 = require("../logger");
20
+ const util_1 = require("../util");
21
21
  const version_1 = require("../version");
22
22
  const flags_1 = require("../flags");
23
23
  const path_1 = __importDefault(require("path"));
@@ -36,7 +36,7 @@ class RecipleClient extends discord_js_1.Client {
36
36
  client: this,
37
37
  });
38
38
  this.version = version_1.version;
39
- this.logger = (0, logger_1.createLogger)(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
39
+ this.logger = (0, util_1.createLogger)(!!options.config?.fileLogging.stringifyLoggedJSON, options.config?.fileLogging.debugmode);
40
40
  this.config = { ...this.config, ...(options.config ?? {}) };
41
41
  if (this.config.fileLogging.enabled)
42
42
  this.logger.logFile(path_1.default.join(flags_1.cwd, this.config.fileLogging.logFilePath ?? 'logs/latest.log'), false);
@@ -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 = new discord_js_1.Collection();
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(resolveCommands = true) {
23
+ if (resolveCommands)
24
+ this.resolveCommands();
25
+ return Promise.resolve(this.script.onStart(this.client));
26
+ }
27
+ async load() {
28
+ if (typeof this.script.onLoad === 'function')
29
+ this.script.onLoad(this.client);
30
+ }
31
+ async unLoad(reason) {
32
+ if (typeof this.script.onUnLoad === 'function')
33
+ this.script.onUnLoad(reason, this.client);
34
+ }
35
+ async registerSlashCommands(...guilds) {
36
+ for (const command of this.commands.toJSON()) {
37
+ if (command.type !== builders_1.CommandBuilderType.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.toJSON()) {
44
+ if (builder.type !== builders_1.CommandBuilderType.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.toJSON()) {
61
+ if (builder.type !== builders_1.CommandBuilderType.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.CommandBuilderType.SlashCommand && command?.type !== builders_1.CommandBuilderType.MessageCommand)
81
+ continue;
82
+ const builder = command.type === builders_1.CommandBuilderType.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.set(command.name, builder);
86
+ }
87
+ this.client.commands.add(this.commands.toJSON());
88
+ return this.commands;
89
+ }
90
+ toString() {
91
+ return this.displayName;
92
+ }
93
+ }
94
+ exports.RecipleModule = RecipleModule;
@@ -7,15 +7,13 @@ class ApplicationCommandManager {
7
7
  constructor(client) {
8
8
  this.client = client;
9
9
  }
10
- get commands() {
11
- return this.client.application?.commands;
12
- }
13
- async set(commands, guilds) {
10
+ async set(commands, ...guilds) {
11
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
14
12
  if (!this.client.isReady())
15
13
  throw new Error('Client is not ready');
16
14
  if (guilds && guilds.length > 1) {
17
15
  for (const guild of guilds) {
18
- await this.set(commands, [guild]);
16
+ await this.set(commands, guild);
19
17
  }
20
18
  return;
21
19
  }
@@ -32,14 +30,15 @@ class ApplicationCommandManager {
32
30
  this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) to guild ${guild}...`);
33
31
  }
34
32
  }
35
- async add(command, guilds) {
33
+ async add(command, ...guilds) {
34
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
36
35
  if (!this.client.isReady())
37
36
  throw new Error('Client is not ready');
38
37
  if (!command)
39
38
  throw new Error('Command is undefined');
40
39
  if (guilds && guilds.length > 1) {
41
40
  for (const guild of guilds) {
42
- await this.add(command, [guild]);
41
+ await this.add(command, guild);
43
42
  }
44
43
  return;
45
44
  }
@@ -56,14 +55,15 @@ class ApplicationCommandManager {
56
55
  this.client.logger.log(`Created application command '${command.name}' to guild ${guild}`);
57
56
  }
58
57
  }
59
- async remove(command, guilds) {
58
+ async remove(command, ...guilds) {
59
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
60
60
  if (!this.client.isReady())
61
61
  throw new Error('Client is not ready');
62
62
  if (!command)
63
63
  throw new Error('Command is undefined');
64
64
  if (guilds && guilds.length > 1) {
65
65
  for (const guild of guilds) {
66
- await this.remove(command, [guild]);
66
+ await this.remove(command, guild);
67
67
  }
68
68
  return;
69
69
  }
@@ -80,14 +80,15 @@ class ApplicationCommandManager {
80
80
  this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
81
81
  }
82
82
  }
83
- async edit(command, newCommand, guilds) {
83
+ async edit(command, newCommand, ...guilds) {
84
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
84
85
  if (!this.client.isReady())
85
86
  throw new Error('Client is not ready');
86
87
  if (!command)
87
88
  throw new Error('Command is undefined');
88
89
  if (guilds && guilds.length > 1) {
89
90
  for (const guild of guilds) {
90
- await this.edit(command, newCommand, [guild]);
91
+ await this.edit(command, newCommand, guild);
91
92
  }
92
93
  return;
93
94
  }
@@ -29,6 +29,9 @@ class ClientCommandManager {
29
29
  else if (command.type === builders_1.CommandBuilderType.MessageCommand) {
30
30
  this.messageCommands.set(command.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
31
31
  }
32
+ else {
33
+ throw new Error(`Unknown reciple command type`);
34
+ }
32
35
  }
33
36
  return this;
34
37
  }
@@ -27,151 +27,128 @@ 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, addModuleCommandsToClient = true, 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(true).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_);
61
+ if (addModuleCommandsToClient) {
62
+ this.client.commands.add(module_.commands.toJSON());
63
+ }
56
64
  }
57
65
  catch (err) {
58
- if (options.dontSkipError)
66
+ if (!ignoreErrors)
59
67
  throw err;
60
68
  if (!this.client.isClientLogsSilent)
61
- this.client.logger.err(`Cannot start module ${ClientModuleManager.getModuleDisplayId(module_)}:`, err);
69
+ this.client.logger.error(`Failed to start module '${module_}': `, err);
62
70
  }
63
71
  }
64
72
  return modules;
65
73
  }
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
+ async loadModules(modules, ignoreErrors = true) {
75
+ for (const module_ of this.modules.toJSON()) {
74
76
  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_);
77
+ await module_.load().catch(err => {
78
+ throw err;
79
+ });
86
80
  if (!this.client.isClientLogsSilent)
87
- this.client.logger.log(`Resolved ${file}`);
81
+ this.client.logger.log(`Loaded module '${module_}'`);
88
82
  }
89
83
  catch (err) {
90
- if (options.dontSkipError)
84
+ if (!ignoreErrors)
91
85
  throw err;
92
86
  if (!this.client.isClientLogsSilent)
93
- this.client.logger.err(`Cannot resolve module file ${file}:`, err);
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 => {
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;
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;
135
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);
136
135
  }
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
136
  }
146
- if (registerApplicationCommands)
147
- await 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);
137
+ return modules;
160
138
  }
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
- };
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;
175
152
  }
176
153
  async getModuleFiles(...folders) {
177
154
  const modules = [];
@@ -186,8 +163,5 @@ class ClientModuleManager {
186
163
  }
187
164
  return modules.filter(file => !this.client.config.ignoredFiles.some(ignored => (0, wildcard_match_1.default)(ignored)(path_1.default.basename(file))));
188
165
  }
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
166
  }
193
167
  exports.ClientModuleManager = ClientModuleManager;
@@ -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
@@ -30,3 +36,31 @@ function validateCommandBuilder(command) {
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;
@@ -8,11 +8,11 @@ export * from './reciple/classes/managers/ClientModuleManager';
8
8
  export * from './reciple/classes/managers/MessageCommandOptionManager';
9
9
  export * from './reciple/classes/RecipleClient';
10
10
  export * from './reciple/classes/RecipleConfig';
11
+ export * from './reciple/classes/RecipleModule';
11
12
  export * from './reciple/types/builders';
12
13
  export * from './reciple/types/commands';
13
14
  export * from './reciple/types/paramOptions';
14
15
  export * from './reciple/flags';
15
- export * from './reciple/logger';
16
16
  export * from './reciple/permissions';
17
17
  export * from './reciple/util';
18
18
  export * from './reciple/version';
@@ -0,0 +1,56 @@
1
+ import { Collection, GuildResolvable, RestOrArray } from 'discord.js';
2
+ import { AnyCommandBuilder, AnyCommandData } from '../types/builders';
3
+ import { RecipleClient } from './RecipleClient';
4
+ /**
5
+ * Reciple script object
6
+ */
7
+ export interface RecipleScript {
8
+ /**
9
+ * Supported reciple versions
10
+ */
11
+ versions: string | string[];
12
+ /**
13
+ * Module commands
14
+ */
15
+ commands?: (AnyCommandBuilder | AnyCommandData)[];
16
+ /**
17
+ * Action on module start
18
+ * @param client Bot client
19
+ */
20
+ onStart(client: RecipleClient<false>): boolean | Promise<boolean>;
21
+ /**
22
+ * Action on bot ready
23
+ * @param client Bot client
24
+ */
25
+ onLoad?(client: RecipleClient<true>): void | Promise<void>;
26
+ /**
27
+ * Action when unloading this module
28
+ * @param reason Unload reason
29
+ * @param client Bot client
30
+ */
31
+ onUnLoad?(reason: unknown, client: RecipleClient<true>): void | Promise<void>;
32
+ }
33
+ export interface RecipleModuleOptions<M = unknown> {
34
+ client: RecipleClient;
35
+ script: RecipleScript;
36
+ filePath?: string;
37
+ metadata?: M;
38
+ }
39
+ export declare class RecipleModule<M = unknown> {
40
+ readonly id: string;
41
+ readonly client: RecipleClient;
42
+ readonly commands: Collection<string, AnyCommandBuilder>;
43
+ readonly script: RecipleScript;
44
+ readonly filePath?: string;
45
+ metadata?: M;
46
+ get displayName(): string;
47
+ constructor(options: RecipleModuleOptions<M>);
48
+ start(resolveCommands?: boolean): Promise<boolean>;
49
+ load(): Promise<void>;
50
+ unLoad(reason?: any): Promise<void>;
51
+ registerSlashCommands(...guilds: RestOrArray<GuildResolvable>): Promise<void>;
52
+ unregisterSlashCommands(...guilds: RestOrArray<GuildResolvable>): Promise<void>;
53
+ updateSlashCommands(...guilds: RestOrArray<GuildResolvable>): Promise<void>;
54
+ resolveCommands(): Collection<string, AnyCommandBuilder>;
55
+ toString(): string;
56
+ }
@@ -1,19 +1,14 @@
1
- import { ApplicationCommand, ApplicationCommandData, ContextMenuCommandBuilder, GuildResolvable, RESTPostAPIApplicationCommandsJSONBody, SlashCommandBuilder as DiscordJsSlashCommandBuilder } from 'discord.js';
1
+ import { ApplicationCommand, ApplicationCommandData, ContextMenuCommandBuilder, GuildResolvable, RestOrArray, RESTPostAPIApplicationCommandsJSONBody, SlashCommandBuilder as DiscordJsSlashCommandBuilder } from 'discord.js';
2
2
  import { AnySlashCommandBuilder } from '../../types/builders';
3
3
  import { RecipleClient } from '../RecipleClient';
4
4
  export declare type ApplicationCommandBuilder = AnySlashCommandBuilder | ContextMenuCommandBuilder | DiscordJsSlashCommandBuilder;
5
5
  export declare class ApplicationCommandManager {
6
6
  readonly client: RecipleClient;
7
- get commands(): import("discord.js").ApplicationCommandManager<ApplicationCommand<{
8
- guild: GuildResolvable;
9
- }>, {
10
- guild: GuildResolvable;
11
- }, null> | undefined;
12
7
  constructor(client: RecipleClient);
13
- set(commands: (ApplicationCommandBuilder | ApplicationCommandData)[], guilds?: GuildResolvable[]): Promise<void>;
14
- add(command: ApplicationCommandBuilder | ApplicationCommandData, guilds?: GuildResolvable[]): Promise<void>;
15
- remove(command: string | ApplicationCommand, guilds?: GuildResolvable[]): Promise<void>;
16
- edit(command: string | ApplicationCommand, newCommand: ApplicationCommandBuilder | ApplicationCommandData, guilds?: GuildResolvable[]): Promise<void>;
8
+ set(commands: (ApplicationCommandBuilder | ApplicationCommandData)[], ...guilds: RestOrArray<GuildResolvable>): Promise<void>;
9
+ add(command: ApplicationCommandBuilder | ApplicationCommandData, ...guilds: RestOrArray<GuildResolvable>): Promise<void>;
10
+ remove(command: string | ApplicationCommand, ...guilds: RestOrArray<GuildResolvable>): Promise<void>;
11
+ edit(command: string | ApplicationCommand, newCommand: ApplicationCommandBuilder | ApplicationCommandData, ...guilds: RestOrArray<GuildResolvable>): Promise<void>;
17
12
  get(command: ApplicationCommandData | ApplicationCommandBuilder | string, guild?: GuildResolvable): ApplicationCommand | undefined;
18
13
  fetch(commandId: string, guild?: GuildResolvable): Promise<ApplicationCommand>;
19
14
  protected parseCommands(commands: (ApplicationCommandData | ApplicationCommandBuilder | RESTPostAPIApplicationCommandsJSONBody)[], setPermissions?: boolean): (ApplicationCommandData | RESTPostAPIApplicationCommandsJSONBody)[];
@@ -1,79 +1,19 @@
1
- import { Collection, GuildResolvable, RestOrArray } from 'discord.js';
2
- import { AnyCommandBuilder, AnyCommandData } from '../../types/builders';
3
- import { ModuleManagerResolveFilesOptions } from '../../types/paramOptions';
1
+ import { Collection, RestOrArray } from 'discord.js';
2
+ import { ClientModuleManagerGetModulesFromFilesOptions } from '../../types/paramOptions';
4
3
  import { RecipleClient } from '../RecipleClient';
5
- /**
6
- * Reciple script object
7
- */
8
- export interface RecipleScript {
9
- /**
10
- * Supported reciple versions
11
- */
12
- versions: string | string[];
13
- /**
14
- * Module commands
15
- */
16
- commands?: (AnyCommandBuilder | AnyCommandData)[];
17
- /**
18
- * Action on module start
19
- * @param client Bot client
20
- */
21
- onStart(client: RecipleClient<false>): boolean | Promise<boolean>;
22
- /**
23
- * Action on bot ready
24
- * @param client Bot client
25
- */
26
- onLoad?(client: RecipleClient<true>): void | Promise<void>;
27
- }
28
- /**
29
- * Reciple module object
30
- */
31
- export interface RecipleModule {
32
- /**
33
- * Module Id
34
- */
35
- id: string;
36
- /**
37
- * Module script
38
- */
39
- script: RecipleScript;
40
- /**
41
- * Module local information
42
- */
43
- info: {
44
- /**
45
- * Module file name
46
- */
47
- filename?: string;
48
- /**
49
- * Module local file path
50
- */
51
- path?: string;
52
- };
53
- }
54
- export interface ResolvedModule extends RecipleModule {
55
- commands: AnyCommandBuilder[];
56
- }
57
- export interface ResolvedScriptCommands {
58
- script: RecipleScript;
59
- commands: AnyCommandBuilder[];
60
- }
4
+ import { RecipleModule, RecipleScript } from '../RecipleModule';
61
5
  export interface ClientModuleManagerOptions {
62
6
  client: RecipleClient;
63
- modules?: (RecipleModule & {
64
- id?: string;
65
- })[];
7
+ modules?: (RecipleModule | RecipleScript)[];
66
8
  }
67
9
  export declare class ClientModuleManager {
68
10
  readonly client: RecipleClient;
69
- readonly modules: Collection<string, ResolvedModule>;
11
+ readonly modules: Collection<string, RecipleModule>;
70
12
  constructor(options: ClientModuleManagerOptions);
71
- startModulesFromFiles(options: ModuleManagerResolveFilesOptions): Promise<ResolvedModule[]>;
72
- resolveModulesFromFiles(options: ModuleManagerResolveFilesOptions): Promise<ResolvedModule[]>;
73
- resolveScriptCommands(...modules: RestOrArray<RecipleScript>): ResolvedScriptCommands[];
74
- loadAll(registerApplicationCommands?: boolean, ...registerApplicationCommandsGuilds: RestOrArray<GuildResolvable>): Promise<void>;
75
- startModule(mod: ResolvedModule): Promise<void>;
76
- resolveModule(mod: RecipleModule, disabeVersionCheck?: boolean): ResolvedModule;
13
+ startModules(modules: RecipleModule[], addModuleCommandsToClient?: boolean, ignoreErrors?: boolean): Promise<RecipleModule[]>;
14
+ loadModules(modules: RecipleModule[], ignoreErrors?: boolean): Promise<RecipleModule[]>;
15
+ unLoadModules(modules: RecipleModule[], removeUnloadedModules?: boolean, ignoreErrors?: boolean): Promise<RecipleModule[]>;
16
+ getModulesFromFiles(options: ClientModuleManagerGetModulesFromFilesOptions): Promise<RecipleModule[]>;
17
+ static validateScript(script: unknown): script is RecipleScript;
77
18
  getModuleFiles(...folders: RestOrArray<string>): Promise<string[]>;
78
- static getModuleDisplayId(mod: RecipleModule): string;
79
19
  }
@@ -1,21 +1,6 @@
1
- import { RecipleModule, RecipleScript } from '../classes/managers/ClientModuleManager';
2
1
  import { ConfigCommandPermissions } from '../classes/RecipleConfig';
3
2
  import { PermissionsBitField } from 'discord.js';
4
3
  import { AnyCommandBuilder } from './builders';
5
- export interface RecipleClientAddModuleOptions {
6
- /**
7
- * The module script
8
- */
9
- script: RecipleScript;
10
- /**
11
- * Register application commands if possible
12
- */
13
- registerApplicationCommands?: boolean;
14
- /**
15
- * Module optional info
16
- */
17
- moduleInfo?: RecipleModule['info'];
18
- }
19
4
  export interface UserHasCommandPermissionsOptions {
20
5
  /**
21
6
  * Command builder
@@ -33,7 +18,7 @@ export interface UserHasCommandPermissionsOptions {
33
18
  commands: ConfigCommandPermissions[];
34
19
  };
35
20
  }
36
- export interface ModuleManagerResolveFilesOptions {
21
+ export interface ClientModuleManagerGetModulesFromFilesOptions {
37
22
  files: string[];
38
23
  disabeVersionCheck?: boolean;
39
24
  dontSkipError?: boolean;
@@ -1,3 +1,4 @@
1
+ import { Logger } from 'fallout-utility';
1
2
  import { AnyCommandBuilder } from './types/builders';
2
3
  /**
3
4
  * Check if an object is a class
@@ -10,3 +11,10 @@ export declare function isClass<T = any>(object: any): object is T;
10
11
  */
11
12
  export declare function deprecationWarning(content: string | Error): void;
12
13
  export declare function validateCommandBuilder(command: AnyCommandBuilder): boolean;
14
+ /**
15
+ * Create new logger
16
+ * @param stringifyJSON stringify json objects in console
17
+ * @param debugmode display debug messages
18
+ * @param colorizeMessage add logger colours to messages
19
+ */
20
+ export declare function createLogger(stringifyJSON: boolean, debugmode?: boolean, colorizeMessage?: boolean): Logger;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reciple",
3
- "version": "6.0.0-dev.6",
3
+ "version": "6.0.0-dev.7",
4
4
  "bin": "./dist/cjs/bin.js",
5
5
  "license": "GPL-3.0",
6
6
  "main": "./dist/cjs/index.js",
@@ -28,9 +28,9 @@
28
28
  "scripts": {
29
29
  "format": "yarn prettier --write src",
30
30
  "clean": "yarn exec rimraf dist",
31
- "build": "yarn clean && yarn format && yarn exec tsc",
32
- "build:publish": "yarn build && yarn docs && yarn npm publish",
33
- "build:publish-dev": "yarn build && yarn npm publish --tag dev",
31
+ "build": "yarn clean && yarn exec tsc",
32
+ "build:publish": "yarn format && yarn build && yarn docs && yarn npm publish",
33
+ "build:publish-dev": "yarn format && yarn build && yarn npm publish --tag dev",
34
34
  "test": "yarn build && yarn workspace test start",
35
35
  "docs": "yarn exec docgen --typescript true -c ./docs/index.json -o ./docs/docs.json -i src/index.ts",
36
36
  "watch": "yarn exec tsc --watch --noEmit"
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createLogger = void 0;
7
- const fallout_utility_1 = require("fallout-utility");
8
- const flags_1 = require("./flags");
9
- const chalk_1 = __importDefault(require("chalk"));
10
- /**
11
- * Create new logger
12
- * @param stringifyJSON stringify json objects in console
13
- * @param debugmode display debug messages
14
- * @param colorizeMessage add logger colours to messages
15
- */
16
- function createLogger(stringifyJSON, debugmode = false, colorizeMessage = true) {
17
- return new fallout_utility_1.Logger({
18
- stringifyJSON: stringifyJSON,
19
- enableDebugMode: flags_1.flags.debugmode ?? debugmode,
20
- loggerName: 'Main',
21
- prefixes: {
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')}]`,
28
- },
29
- colorMessages: {
30
- [fallout_utility_1.LogLevels.INFO]: (message) => message,
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
- },
35
- });
36
- }
37
- exports.createLogger = createLogger;
@@ -1,8 +0,0 @@
1
- import { Logger } from 'fallout-utility';
2
- /**
3
- * Create new logger
4
- * @param stringifyJSON stringify json objects in console
5
- * @param debugmode display debug messages
6
- * @param colorizeMessage add logger colours to messages
7
- */
8
- export declare function createLogger(stringifyJSON: boolean, debugmode?: boolean, colorizeMessage?: boolean): Logger;