reciple 5.6.0 → 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 (37) hide show
  1. package/dist/cjs/bin.js +13 -10
  2. package/dist/cjs/index.js +8 -7
  3. package/dist/cjs/reciple/classes/RecipleClient.js +90 -184
  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 +7 -5
  7. package/dist/cjs/reciple/classes/builders/SlashCommandBuilder.js +12 -23
  8. package/dist/cjs/reciple/classes/managers/ApplicationCommandManager.js +136 -0
  9. package/dist/cjs/reciple/classes/managers/ClientCommandManager.js +62 -0
  10. package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +167 -0
  11. package/dist/cjs/reciple/classes/{CommandCooldownManager.js → managers/CommandCooldownManager.js} +15 -6
  12. package/dist/cjs/reciple/classes/{MessageCommandOptionManager.js → managers/MessageCommandOptionManager.js} +0 -0
  13. package/dist/cjs/reciple/permissions.js +3 -4
  14. package/dist/cjs/reciple/types/builders.js +6 -6
  15. package/dist/cjs/reciple/util.js +44 -1
  16. package/dist/types/index.d.ts +8 -7
  17. package/dist/types/reciple/classes/RecipleClient.d.ts +17 -65
  18. package/dist/types/reciple/classes/RecipleModule.d.ts +56 -0
  19. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +7 -7
  20. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +17 -17
  21. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +15 -0
  22. package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +37 -0
  23. package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +19 -0
  24. package/dist/types/reciple/classes/{CommandCooldownManager.d.ts → managers/CommandCooldownManager.d.ts} +4 -3
  25. package/dist/types/reciple/classes/{MessageCommandOptionManager.d.ts → managers/MessageCommandOptionManager.d.ts} +1 -1
  26. package/dist/types/reciple/types/builders.d.ts +19 -19
  27. package/dist/types/reciple/types/commands.d.ts +12 -12
  28. package/dist/types/reciple/types/paramOptions.d.ts +6 -32
  29. package/dist/types/reciple/util.d.ts +10 -0
  30. package/package.json +30 -24
  31. package/dist/cjs/reciple/logger.js +0 -35
  32. package/dist/cjs/reciple/modules.js +0 -113
  33. package/dist/cjs/reciple/registerApplicationCommands.js +0 -49
  34. package/dist/types/reciple/logger.d.ts +0 -8
  35. package/dist/types/reciple/modules.d.ts +0 -64
  36. package/dist/types/reciple/registerApplicationCommands.d.ts +0 -9
  37. package/docs/README.md +0 -1
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
4
4
  const builders_1 = require("../../types/builders");
5
5
  const discord_js_1 = require("discord.js");
6
- const MessageCommandOptionManager_1 = require("../MessageCommandOptionManager");
6
+ const MessageCommandOptionManager_1 = require("../managers/MessageCommandOptionManager");
7
7
  const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
8
8
  /**
9
9
  * Reciple builder for message command
10
10
  */
11
11
  class MessageCommandBuilder {
12
12
  constructor(data) {
13
- this.type = builders_1.CommandBuilderType.MessageCommand;
13
+ this.type = builders_1.CommandType.MessageCommand;
14
14
  this.name = '';
15
15
  this.description = '';
16
16
  this.cooldown = 0;
@@ -21,7 +21,9 @@ class MessageCommandBuilder {
21
21
  this.requiredMemberPermissions = [];
22
22
  this.allowExecuteInDM = true;
23
23
  this.allowExecuteByBots = false;
24
- this.execute = () => { };
24
+ this.execute = () => {
25
+ /* Execute */
26
+ };
25
27
  if (data?.name !== undefined)
26
28
  this.setName(data.name);
27
29
  if (data?.description !== undefined)
@@ -47,7 +49,7 @@ class MessageCommandBuilder {
47
49
  if (data?.validateOptions !== undefined)
48
50
  this.setValidateOptions(true);
49
51
  if (data?.options !== undefined)
50
- this.options = data.options.map(o => o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o));
52
+ this.options = data.options.map(o => (o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o)));
51
53
  }
52
54
  /**
53
55
  * Sets the command name
@@ -218,7 +220,7 @@ async function validateMessageCommandOptions(builder, options) {
218
220
  value: arg ?? undefined,
219
221
  required: option.required,
220
222
  invalid: false,
221
- missing: false
223
+ missing: false,
222
224
  };
223
225
  if (arg == undefined && option.required) {
224
226
  value.missing = true;
@@ -10,11 +10,13 @@ const discord_js_1 = require("discord.js");
10
10
  class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
11
11
  constructor(data) {
12
12
  super();
13
- this.type = builders_1.CommandBuilderType.SlashCommand;
13
+ this.type = builders_1.CommandType.SlashCommand;
14
14
  this.cooldown = 0;
15
15
  this.requiredBotPermissions = [];
16
16
  this.requiredMemberPermissions = [];
17
- this.execute = () => { };
17
+ this.execute = () => {
18
+ /* Execute */
19
+ };
18
20
  // TODO: WTH
19
21
  if (data?.name !== undefined)
20
22
  this.setName(data.name);
@@ -58,9 +60,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
58
60
  }
59
61
  setRequiredMemberPermissions(...permissions) {
60
62
  this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
61
- this.setDefaultMemberPermissions(this.requiredMemberPermissions.length
62
- ? new discord_js_1.PermissionsBitField(this.requiredMemberPermissions).bitfield
63
- : undefined);
63
+ this.setDefaultMemberPermissions(this.requiredMemberPermissions.length ? new discord_js_1.PermissionsBitField(this.requiredMemberPermissions).bitfield : undefined);
64
64
  return this;
65
65
  }
66
66
  setHalt(halt) {
@@ -135,13 +135,10 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
135
135
  builder = new discord_js_1.SlashCommandBooleanOption();
136
136
  break;
137
137
  case discord_js_1.ApplicationCommandOptionType.Channel:
138
- builder = new discord_js_1.SlashCommandChannelOption()
139
- .addChannelTypes(...(option.channelTypes ?? []));
138
+ builder = new discord_js_1.SlashCommandChannelOption().addChannelTypes(...(option.channelTypes ?? []));
140
139
  break;
141
140
  case discord_js_1.ApplicationCommandOptionType.Integer:
142
- builder = new discord_js_1.SlashCommandIntegerOption()
143
- .addChoices(...(option.choices ?? []))
144
- .setAutocomplete(!!option.autocomplete);
141
+ builder = new discord_js_1.SlashCommandIntegerOption().addChoices(...(option.choices ?? [])).setAutocomplete(!!option.autocomplete);
145
142
  if (option.maxValue)
146
143
  builder.setMaxValue(option.maxValue);
147
144
  if (option.minValue)
@@ -151,9 +148,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
151
148
  builder = new discord_js_1.SlashCommandMentionableOption();
152
149
  break;
153
150
  case discord_js_1.ApplicationCommandOptionType.Number:
154
- builder = new discord_js_1.SlashCommandNumberOption()
155
- .addChoices(...(option.choices ?? []))
156
- .setAutocomplete(!!option.autocomplete);
151
+ builder = new discord_js_1.SlashCommandNumberOption().addChoices(...(option.choices ?? [])).setAutocomplete(!!option.autocomplete);
157
152
  if (option.maxValue)
158
153
  builder.setMaxValue(option.maxValue);
159
154
  if (option.minValue)
@@ -163,9 +158,7 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
163
158
  builder = new discord_js_1.SlashCommandRoleOption();
164
159
  break;
165
160
  case discord_js_1.ApplicationCommandOptionType.String:
166
- builder = new discord_js_1.SlashCommandStringOption()
167
- .addChoices(...(option.choices ?? []))
168
- .setAutocomplete(!!option.autocomplete);
161
+ builder = new discord_js_1.SlashCommandStringOption().addChoices(...(option.choices ?? [])).setAutocomplete(!!option.autocomplete);
169
162
  if (option.maxLength)
170
163
  builder.setMaxLength(option.maxLength);
171
164
  if (option.minLength)
@@ -183,17 +176,13 @@ class SlashCommandBuilder extends discord_js_1.SlashCommandBuilder {
183
176
  case discord_js_1.ApplicationCommandOptionType.SubcommandGroup:
184
177
  builder = new discord_js_1.SlashCommandSubcommandGroupBuilder();
185
178
  for (const subCommandData of option.options) {
186
- builder.addSubcommand(subCommandData instanceof discord_js_1.SlashCommandSubcommandBuilder
187
- ? subCommandData
188
- : this.resolveOption(subCommandData));
179
+ builder.addSubcommand(subCommandData instanceof discord_js_1.SlashCommandSubcommandBuilder ? subCommandData : this.resolveOption(subCommandData));
189
180
  }
190
181
  break;
191
182
  default:
192
- throw new TypeError("Unknown option data");
183
+ throw new TypeError('Unknown option data');
193
184
  }
194
- if (!(builder instanceof discord_js_1.SlashCommandSubcommandBuilder) && !(builder instanceof discord_js_1.SlashCommandSubcommandGroupBuilder)
195
- &&
196
- option.type !== discord_js_1.ApplicationCommandOptionType.Subcommand && option.type !== discord_js_1.ApplicationCommandOptionType.SubcommandGroup) {
185
+ if (!(builder instanceof discord_js_1.SlashCommandSubcommandBuilder) && !(builder instanceof discord_js_1.SlashCommandSubcommandGroupBuilder) && option.type !== discord_js_1.ApplicationCommandOptionType.Subcommand && option.type !== discord_js_1.ApplicationCommandOptionType.SubcommandGroup) {
197
186
  builder.setRequired(option.required ?? false);
198
187
  }
199
188
  return builder
@@ -0,0 +1,136 @@
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
+ async set(commands, ...guilds) {
11
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
12
+ if (!this.client.isReady())
13
+ throw new Error('Client is not ready');
14
+ if (guilds && guilds.length > 1) {
15
+ for (const guild of guilds) {
16
+ await this.set(commands, guild);
17
+ }
18
+ return;
19
+ }
20
+ let guild = guilds?.shift();
21
+ guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
22
+ if (!guild) {
23
+ await this.client.application.commands.set(commands);
24
+ if (!this.client.isClientLogsSilent)
25
+ this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) globally...`);
26
+ }
27
+ else {
28
+ await this.client.application.commands.set(commands, guild);
29
+ if (!this.client.isClientLogsSilent)
30
+ this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) to guild ${guild}...`);
31
+ }
32
+ }
33
+ async add(command, ...guilds) {
34
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
35
+ if (!this.client.isReady())
36
+ throw new Error('Client is not ready');
37
+ if (!command)
38
+ throw new Error('Command is undefined');
39
+ if (guilds && guilds.length > 1) {
40
+ for (const guild of guilds) {
41
+ await this.add(command, guild);
42
+ }
43
+ return;
44
+ }
45
+ let guild = guilds?.shift();
46
+ guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
47
+ if (!guild) {
48
+ await this.client.application.commands.create(command);
49
+ if (!this.client.isClientLogsSilent)
50
+ this.client.logger.log(`Created application command '${command.name}' globally`);
51
+ }
52
+ else {
53
+ await this.client.application.commands.create(command, guild);
54
+ if (!this.client.isClientLogsSilent)
55
+ this.client.logger.log(`Created application command '${command.name}' to guild ${guild}`);
56
+ }
57
+ }
58
+ async remove(command, ...guilds) {
59
+ guilds = (0, discord_js_1.normalizeArray)(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
+ await 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
+ await 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
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
85
+ if (!this.client.isReady())
86
+ throw new Error('Client is not ready');
87
+ if (!command)
88
+ throw new Error('Command is undefined');
89
+ if (guilds && guilds.length > 1) {
90
+ for (const guild of guilds) {
91
+ await this.edit(command, newCommand, guild);
92
+ }
93
+ return;
94
+ }
95
+ let guild = guilds?.shift();
96
+ guild = guild ? this.client.guilds.resolveId(guild) || undefined : undefined;
97
+ if (!guild) {
98
+ await this.client.application.commands.edit(command, newCommand);
99
+ if (!this.client.isClientLogsSilent)
100
+ this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' globally`);
101
+ }
102
+ else {
103
+ await this.client.application.commands.edit(command, newCommand, guild);
104
+ if (!this.client.isClientLogsSilent)
105
+ this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
106
+ }
107
+ }
108
+ get(command, guild) {
109
+ const commands = guild ? this.client.guilds.resolve(guild)?.commands.cache : this.client.application?.commands.cache;
110
+ if (!commands)
111
+ throw new Error('Guild not found in cache');
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)));
113
+ }
114
+ async fetch(commandId, guild) {
115
+ const manager = guild ? this.client.guilds.resolve(guild)?.commands : this.client.application?.commands;
116
+ if (!manager)
117
+ throw new Error('Guild not found in cache');
118
+ return manager.fetch(commandId);
119
+ }
120
+ parseCommands(commands, setPermissions = true) {
121
+ return commands.map(cmd => {
122
+ if (cmd?.toJSON === undefined)
123
+ return cmd;
124
+ if (SlashCommandBuilder_1.SlashCommandBuilder.isSlashCommandBuilder(cmd) && this.client.config.commands.slashCommand.setRequiredPermissions) {
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;
126
+ if (permissions) {
127
+ cmd.setRequiredMemberPermissions(...permissions);
128
+ if (!this.client.isClientLogsSilent)
129
+ this.client.logger.debug(`Set required permissions for ${cmd.name}`);
130
+ }
131
+ }
132
+ return cmd.toJSON();
133
+ });
134
+ }
135
+ }
136
+ exports.ApplicationCommandManager = ApplicationCommandManager;
@@ -0,0 +1,62 @@
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.CommandType.SlashCommand) {
27
+ this.slashCommands.set(command.name, SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
28
+ }
29
+ else if (command.type === builders_1.CommandType.MessageCommand) {
30
+ this.messageCommands.set(command.name, MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
31
+ }
32
+ else {
33
+ throw new Error(`Unknown reciple command type`);
34
+ }
35
+ }
36
+ return this;
37
+ }
38
+ get(command, type) {
39
+ switch (type) {
40
+ case builders_1.CommandType.SlashCommand:
41
+ return this.slashCommands.get(command);
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);
44
+ default:
45
+ throw new TypeError('Unknown command type');
46
+ }
47
+ }
48
+ /**
49
+ * Register application commands
50
+ * @param guilds Register application commands to guilds
51
+ */
52
+ async registerApplicationCommands(...guilds) {
53
+ guilds = (0, discord_js_1.normalizeArray)(guilds);
54
+ guilds = guilds.length ? guilds : (0, discord_js_1.normalizeArray)([this.client.config.commands.slashCommand.guilds]);
55
+ if (!this.client.isClientLogsSilent)
56
+ this.client.logger.log(`Regestering ${this.applicationCommandsSize} application command(s) ${!guilds.length ? 'globaly' : 'to ' + guilds.length + ' guilds'}...`);
57
+ await this.client.applicationCommands.set([...this.slashCommands.toJSON(), ...this.additionalApplicationCommands], guilds);
58
+ this.client.emit('recipleRegisterApplicationCommands');
59
+ return this;
60
+ }
61
+ }
62
+ exports.ClientCommandManager = ClientCommandManager;
@@ -0,0 +1,167 @@
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 discord_js_1 = require("discord.js");
31
+ const fs_1 = require("fs");
32
+ const path_1 = __importDefault(require("path"));
33
+ const util_1 = require("util");
34
+ const wildcard_match_1 = __importDefault(require("wildcard-match"));
35
+ const flags_1 = require("../../flags");
36
+ const RecipleModule_1 = require("../RecipleModule");
37
+ class ClientModuleManager {
38
+ constructor(options) {
39
+ this.modules = new discord_js_1.Collection();
40
+ this.client = options.client;
41
+ options.modules?.forEach(m => (m instanceof RecipleModule_1.RecipleModule ? m : new RecipleModule_1.RecipleModule({ client: this.client, script: m })));
42
+ }
43
+ async startModules(modules, ignoreErrors = true) {
44
+ for (const module_ of modules) {
45
+ if (!this.client.isClientLogsSilent)
46
+ this.client.logger.log(`Starting module '${module_}'`);
47
+ try {
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_);
61
+ }
62
+ catch (err) {
63
+ if (!ignoreErrors)
64
+ throw err;
65
+ if (!this.client.isClientLogsSilent)
66
+ this.client.logger.error(`Failed to start module '${module_}': `, err);
67
+ }
68
+ }
69
+ return modules;
70
+ }
71
+ async loadModules(modules, addModuleCommandsToClient = true, ignoreErrors = true) {
72
+ for (const module_ of this.modules.toJSON()) {
73
+ try {
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
+ }
82
+ }
83
+ catch (err) {
84
+ if (!ignoreErrors)
85
+ throw err;
86
+ if (!this.client.isClientLogsSilent)
87
+ this.client.logger.error(`Failed to load module '${module_}': `, err);
88
+ }
89
+ }
90
+ return modules;
91
+ }
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);
108
+ }
109
+ }
110
+ return modules;
111
+ }
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;
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);
135
+ }
136
+ }
137
+ return modules;
138
+ }
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;
152
+ }
153
+ async getModuleFiles(...folders) {
154
+ const modules = [];
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])) {
156
+ if (!(0, fs_1.existsSync)(dir))
157
+ (0, fs_1.mkdirSync)(dir, { recursive: true });
158
+ if (!(0, fs_1.lstatSync)(dir).isDirectory())
159
+ continue;
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')));
163
+ }
164
+ return modules.filter(file => !this.client.config.ignoredFiles.some(ignored => (0, wildcard_match_1.default)(ignored)(path_1.default.basename(file))));
165
+ }
166
+ }
167
+ 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;
@@ -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,13 @@
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.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");
10
+ const builders_1 = require("./types/builders");
4
11
  /**
5
12
  * Check if an object is a class
6
13
  * @param object Object to identify
@@ -21,3 +28,39 @@ function deprecationWarning(content) {
21
28
  process.emitWarning(content, 'DeprecationWarning');
22
29
  }
23
30
  exports.deprecationWarning = deprecationWarning;
31
+ function validateCommandBuilder(command) {
32
+ if (!command.name)
33
+ return false;
34
+ if (command.type === builders_1.CommandType.MessageCommand && command.options.length && command.options.some(o => !o.name))
35
+ return false;
36
+ return true;
37
+ }
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;
@@ -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/ClientCommandManager';
6
+ export * from './reciple/classes/managers/ClientModuleManager';
7
+ export * from './reciple/classes/managers/CommandCooldownManager';
8
+ export * from './reciple/classes/managers/MessageCommandOptionManager';
9
+ export * from './reciple/classes/RecipleClient';
10
+ export * from './reciple/classes/RecipleConfig';
11
+ export * from './reciple/classes/RecipleModule';
8
12
  export * from './reciple/types/builders';
9
13
  export * from './reciple/types/commands';
10
14
  export * from './reciple/types/paramOptions';
11
15
  export * from './reciple/flags';
12
- 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';