reciple 6.0.0-dev.3 → 6.0.0-dev.30

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 (97) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +183 -183
  3. package/dist/lib/bin.mjs +70 -0
  4. package/dist/lib/bin.mjs.map +1 -0
  5. package/dist/lib/esm.mjs +2 -0
  6. package/dist/lib/esm.mjs.map +1 -0
  7. package/dist/{cjs → lib}/index.js +17 -17
  8. package/dist/lib/index.js.map +1 -0
  9. package/dist/{cjs → lib}/reciple/classes/RecipleClient.js +42 -33
  10. package/dist/lib/reciple/classes/RecipleClient.js.map +1 -0
  11. package/dist/{cjs → lib}/reciple/classes/RecipleConfig.js +11 -10
  12. package/dist/lib/reciple/classes/RecipleConfig.js.map +1 -0
  13. package/dist/lib/reciple/classes/RecipleModule.js +137 -0
  14. package/dist/lib/reciple/classes/RecipleModule.js.map +1 -0
  15. package/dist/lib/reciple/classes/builders/MessageCommandBuilder.js +310 -0
  16. package/dist/lib/reciple/classes/builders/MessageCommandBuilder.js.map +1 -0
  17. package/dist/{cjs → lib}/reciple/classes/builders/MessageCommandOptionBuilder.js +55 -13
  18. package/dist/lib/reciple/classes/builders/MessageCommandOptionBuilder.js.map +1 -0
  19. package/dist/{cjs → lib}/reciple/classes/builders/SlashCommandBuilder.js +43 -15
  20. package/dist/lib/reciple/classes/builders/SlashCommandBuilder.js.map +1 -0
  21. package/dist/{cjs → lib}/reciple/classes/managers/ApplicationCommandManager.js +69 -27
  22. package/dist/lib/reciple/classes/managers/ApplicationCommandManager.js.map +1 -0
  23. package/dist/{cjs → lib}/reciple/classes/managers/CommandCooldownManager.js +1 -1
  24. package/dist/lib/reciple/classes/managers/CommandCooldownManager.js.map +1 -0
  25. package/dist/{cjs/reciple/classes/managers/ClientCommandManager.js → lib/reciple/classes/managers/CommandManager.js} +21 -16
  26. package/dist/lib/reciple/classes/managers/CommandManager.js.map +1 -0
  27. package/dist/{cjs → lib}/reciple/classes/managers/MessageCommandOptionManager.js +1 -0
  28. package/dist/lib/reciple/classes/managers/MessageCommandOptionManager.js.map +1 -0
  29. package/dist/lib/reciple/classes/managers/ModuleManager.js +181 -0
  30. package/dist/lib/reciple/classes/managers/ModuleManager.js.map +1 -0
  31. package/dist/{cjs → lib}/reciple/flags.js +4 -3
  32. package/dist/lib/reciple/flags.js.map +1 -0
  33. package/dist/{cjs → lib}/reciple/permissions.js +1 -0
  34. package/dist/lib/reciple/permissions.js.map +1 -0
  35. package/dist/lib/reciple/types/builders.js +12 -0
  36. package/dist/lib/reciple/types/builders.js.map +1 -0
  37. package/dist/{cjs → lib}/reciple/types/commands.js +7 -6
  38. package/dist/lib/reciple/types/commands.js.map +1 -0
  39. package/dist/{cjs → lib}/reciple/types/paramOptions.js +1 -0
  40. package/dist/lib/reciple/types/paramOptions.js.map +1 -0
  41. package/dist/{cjs/reciple/logger.js → lib/reciple/util.js} +40 -5
  42. package/dist/lib/reciple/util.js.map +1 -0
  43. package/dist/{cjs → lib}/reciple/version.js +1 -1
  44. package/dist/lib/reciple/version.js.map +1 -0
  45. package/dist/types/{bin.d.ts → bin.d.mts} +1 -0
  46. package/dist/types/bin.d.mts.map +1 -0
  47. package/dist/types/esm.d.mts +2 -0
  48. package/dist/types/esm.d.mts.map +1 -0
  49. package/dist/types/index.d.ts +17 -17
  50. package/dist/types/index.d.ts.map +1 -0
  51. package/dist/types/reciple/classes/RecipleClient.d.ts +22 -8
  52. package/dist/types/reciple/classes/RecipleClient.d.ts.map +1 -0
  53. package/dist/types/reciple/classes/RecipleConfig.d.ts +4 -2
  54. package/dist/types/reciple/classes/RecipleConfig.d.ts.map +1 -0
  55. package/dist/types/reciple/classes/RecipleModule.d.ts +88 -0
  56. package/dist/types/reciple/classes/RecipleModule.d.ts.map +1 -0
  57. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +67 -27
  58. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts.map +1 -0
  59. package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +18 -7
  60. package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts.map +1 -0
  61. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +23 -12
  62. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts.map +1 -0
  63. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +46 -12
  64. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts.map +1 -0
  65. package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +3 -2
  66. package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts.map +1 -0
  67. package/dist/types/reciple/classes/managers/CommandManager.d.ts +35 -0
  68. package/dist/types/reciple/classes/managers/CommandManager.d.ts.map +1 -0
  69. package/dist/types/reciple/classes/managers/MessageCommandOptionManager.d.ts +2 -1
  70. package/dist/types/reciple/classes/managers/MessageCommandOptionManager.d.ts.map +1 -0
  71. package/dist/types/reciple/classes/managers/ModuleManager.d.ts +50 -0
  72. package/dist/types/reciple/classes/managers/ModuleManager.d.ts.map +1 -0
  73. package/dist/types/reciple/flags.d.ts +2 -1
  74. package/dist/types/reciple/flags.d.ts.map +1 -0
  75. package/dist/types/reciple/permissions.d.ts +3 -6
  76. package/dist/types/reciple/permissions.d.ts.map +1 -0
  77. package/dist/types/reciple/types/builders.d.ts +29 -20
  78. package/dist/types/reciple/types/builders.d.ts.map +1 -0
  79. package/dist/types/reciple/types/commands.d.ts +19 -18
  80. package/dist/types/reciple/types/commands.d.ts.map +1 -0
  81. package/dist/types/reciple/types/paramOptions.d.ts +80 -18
  82. package/dist/types/reciple/types/paramOptions.d.ts.map +1 -0
  83. package/dist/types/reciple/util.d.ts +17 -2
  84. package/dist/types/reciple/util.d.ts.map +1 -0
  85. package/dist/types/reciple/version.d.ts +1 -0
  86. package/dist/types/reciple/version.d.ts.map +1 -0
  87. package/package.json +46 -36
  88. package/resource/reciple.yml +120 -117
  89. package/dist/cjs/bin.js +0 -50
  90. package/dist/cjs/reciple/classes/builders/MessageCommandBuilder.js +0 -242
  91. package/dist/cjs/reciple/classes/managers/ClientModuleManager.js +0 -193
  92. package/dist/cjs/reciple/types/builders.js +0 -11
  93. package/dist/cjs/reciple/util.js +0 -32
  94. package/dist/types/reciple/classes/managers/ClientCommandManager.d.ts +0 -37
  95. package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +0 -79
  96. package/dist/types/reciple/logger.d.ts +0 -8
  97. package/docs/README.md +0 -1
@@ -1,242 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateMessageCommandOptions = exports.MessageCommandBuilder = void 0;
4
- const builders_1 = require("../../types/builders");
5
- const discord_js_1 = require("discord.js");
6
- const MessageCommandOptionManager_1 = require("../managers/MessageCommandOptionManager");
7
- const MessageCommandOptionBuilder_1 = require("./MessageCommandOptionBuilder");
8
- /**
9
- * Reciple builder for message command
10
- */
11
- class MessageCommandBuilder {
12
- constructor(data) {
13
- this.type = builders_1.CommandBuilderType.MessageCommand;
14
- this.name = '';
15
- this.description = '';
16
- this.cooldown = 0;
17
- this.aliases = [];
18
- this.validateOptions = false;
19
- this.options = [];
20
- this.requiredBotPermissions = [];
21
- this.requiredMemberPermissions = [];
22
- this.allowExecuteInDM = true;
23
- this.allowExecuteByBots = false;
24
- this.execute = () => {
25
- /* Execute */
26
- };
27
- if (data?.name !== undefined)
28
- this.setName(data.name);
29
- if (data?.description !== undefined)
30
- this.setDescription(data.description);
31
- if (data?.aliases !== undefined)
32
- this.addAliases(data.aliases);
33
- if (data?.cooldown !== undefined)
34
- this.setCooldown(Number(data?.cooldown));
35
- if (data?.requiredBotPermissions !== undefined)
36
- this.setRequiredBotPermissions(data.requiredBotPermissions);
37
- if (data?.requiredMemberPermissions !== undefined)
38
- this.setRequiredMemberPermissions(data.requiredMemberPermissions);
39
- if (data?.halt !== undefined)
40
- this.setHalt(data.halt);
41
- if (data?.execute !== undefined)
42
- this.setExecute(data.execute);
43
- if (data?.metadata !== undefined)
44
- this.setMetadata(data.metadata);
45
- if (data?.allowExecuteByBots !== undefined)
46
- this.setAllowExecuteByBots(true);
47
- if (data?.allowExecuteInDM !== undefined)
48
- this.setAllowExecuteInDM(true);
49
- if (data?.validateOptions !== undefined)
50
- this.setValidateOptions(true);
51
- if (data?.options !== undefined)
52
- this.options = data.options.map(o => (o instanceof MessageCommandOptionBuilder_1.MessageCommandOptionBuilder ? o : new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder(o)));
53
- }
54
- /**
55
- * Sets the command name
56
- * @param name Command name
57
- */
58
- setName(name) {
59
- if (!name || typeof name !== 'string' || !name.match(/^[\w-]{1,32}$/))
60
- throw new TypeError('name must be a string and match the regex /^[\\w-]{1,32}$/');
61
- this.name = name;
62
- return this;
63
- }
64
- /**
65
- * Sets the command description
66
- * @param description Command description
67
- */
68
- setDescription(description) {
69
- if (!description || typeof description !== 'string')
70
- throw new TypeError('description must be a string.');
71
- this.description = description;
72
- return this;
73
- }
74
- /**
75
- * Add aliases to the command
76
- * @param aliases Command aliases
77
- */
78
- addAliases(...aliases) {
79
- aliases = (0, discord_js_1.normalizeArray)(aliases);
80
- if (!aliases.length)
81
- throw new TypeError('Provide atleast one alias');
82
- if (aliases.some(a => !a || typeof a !== 'string' || a.match(/^\s+$/)))
83
- throw new TypeError('aliases must be strings and should not contain whitespaces');
84
- if (this.name && aliases.some(a => a == this.name))
85
- throw new TypeError('alias cannot have same name to its real command name');
86
- this.aliases = [...new Set(aliases.map(s => s.toLowerCase()))];
87
- return this;
88
- }
89
- /**
90
- * Set if command can be executed in dms
91
- * @param allowExecuteInDM `true` if the command can execute in DMs
92
- */
93
- setAllowExecuteInDM(allowExecuteInDM) {
94
- if (typeof allowExecuteInDM !== 'boolean')
95
- throw new TypeError('allowExecuteInDM must be a boolean.');
96
- this.allowExecuteInDM = allowExecuteInDM;
97
- return this;
98
- }
99
- /**
100
- * Allow command to be executed by bots
101
- * @param allowExecuteByBots `true` if the command can be executed by bots
102
- */
103
- setAllowExecuteByBots(allowExecuteByBots) {
104
- if (typeof allowExecuteByBots !== 'boolean')
105
- throw new TypeError('allowExecuteByBots must be a boolean.');
106
- this.allowExecuteByBots = allowExecuteByBots;
107
- return this;
108
- }
109
- /**
110
- * Add option to the command
111
- * @param option Message option builder
112
- */
113
- addOption(option) {
114
- if (!option)
115
- throw new TypeError('option must be a MessageOption.');
116
- option = typeof option === 'function' ? option(new MessageCommandOptionBuilder_1.MessageCommandOptionBuilder()) : option;
117
- if (this.options.find(o => o.name === option.name))
118
- throw new TypeError('option with name "' + option.name + '" already exists.');
119
- if (this.options.length > 0 && !this.options[this.options.length - 1 < 0 ? 0 : this.options.length - 1].required && option.required)
120
- throw new TypeError('All required options must be before optional options.');
121
- this.options.push(option);
122
- return this;
123
- }
124
- /**
125
- * Validate options before executing
126
- * @param validateOptions `true` if the command options needs to be validated before executing
127
- */
128
- setValidateOptions(validateOptions) {
129
- if (typeof validateOptions !== 'boolean')
130
- throw new TypeError('validateOptions must be a boolean.');
131
- this.validateOptions = validateOptions;
132
- return this;
133
- }
134
- setCooldown(cooldown) {
135
- this.cooldown = cooldown;
136
- return this;
137
- }
138
- setRequiredBotPermissions(...permissions) {
139
- this.requiredBotPermissions = (0, discord_js_1.normalizeArray)(permissions);
140
- return this;
141
- }
142
- setRequiredMemberPermissions(...permissions) {
143
- this.requiredMemberPermissions = (0, discord_js_1.normalizeArray)(permissions);
144
- return this;
145
- }
146
- setHalt(halt) {
147
- this.halt = halt ?? undefined;
148
- return this;
149
- }
150
- setExecute(execute) {
151
- if (!execute || typeof execute !== 'function')
152
- throw new TypeError('execute must be a function.');
153
- this.execute = execute;
154
- return this;
155
- }
156
- setMetadata(metadata) {
157
- this.metadata = metadata;
158
- return this;
159
- }
160
- /**
161
- * Returns JSON object of this builder
162
- */
163
- toJSON() {
164
- return {
165
- type: this.type,
166
- name: this.name,
167
- description: this.description,
168
- aliases: this.aliases,
169
- cooldown: this.cooldown,
170
- requiredBotPermissions: this.requiredBotPermissions,
171
- requiredMemberPermissions: this.requiredMemberPermissions,
172
- halt: this.halt,
173
- execute: this.execute,
174
- metadata: this.metadata,
175
- allowExecuteByBots: this.allowExecuteByBots,
176
- allowExecuteInDM: this.allowExecuteInDM,
177
- validateOptions: this.validateOptions,
178
- options: this.options.map(o => o.toJSON()),
179
- };
180
- }
181
- /**
182
- * Resolve message command data/builder
183
- * @param commandData Command data to resolve
184
- */
185
- static resolveMessageCommand(commandData) {
186
- return this.isMessageCommandBuilder(commandData) ? commandData : new MessageCommandBuilder(commandData);
187
- }
188
- /**
189
- * Is a message command builder
190
- * @param builder data to check
191
- */
192
- static isMessageCommandBuilder(builder) {
193
- return builder instanceof MessageCommandBuilder;
194
- }
195
- /**
196
- * Is a message command execute data
197
- * @param executeData data to check
198
- */
199
- static isMessageCommandExecuteData(executeData) {
200
- return executeData.builder !== undefined && this.isMessageCommandBuilder(executeData.builder);
201
- }
202
- }
203
- exports.MessageCommandBuilder = MessageCommandBuilder;
204
- /**
205
- * Validate message command options
206
- * @param builder Command builder
207
- * @param options Parsed command args
208
- */
209
- async function validateMessageCommandOptions(builder, options) {
210
- const args = options.args || [];
211
- const required = builder.options.filter(o => o.required);
212
- const optional = builder.options.filter(o => !o.required);
213
- const allOptions = [...required, ...optional];
214
- const result = [];
215
- let i = 0;
216
- for (const option of allOptions) {
217
- const arg = args[i];
218
- const value = {
219
- name: option.name,
220
- value: arg ?? undefined,
221
- required: option.required,
222
- invalid: false,
223
- missing: false,
224
- };
225
- if (arg == undefined && option.required) {
226
- value.missing = true;
227
- result.push(value);
228
- continue;
229
- }
230
- if (arg == undefined && !option.required) {
231
- result.push(value);
232
- continue;
233
- }
234
- const validate = option.validator ? await Promise.resolve(option.validator(arg)) : true;
235
- if (!validate)
236
- value.invalid = true;
237
- result.push(value);
238
- i++;
239
- }
240
- return new MessageCommandOptionManager_1.MessageCommandOptionManager(...result);
241
- }
242
- exports.validateMessageCommandOptions = validateMessageCommandOptions;
@@ -1,193 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.ClientModuleManager = void 0;
30
- const crypto_1 = require("crypto");
31
- const discord_js_1 = require("discord.js");
32
- const fs_1 = require("fs");
33
- const path_1 = __importDefault(require("path"));
34
- const wildcard_match_1 = __importDefault(require("wildcard-match"));
35
- const flags_1 = require("../../flags");
36
- const builders_1 = require("../../types/builders");
37
- const util_1 = require("../../util");
38
- const version_1 = require("../../version");
39
- const MessageCommandBuilder_1 = require("../builders/MessageCommandBuilder");
40
- const SlashCommandBuilder_1 = require("../builders/SlashCommandBuilder");
41
- class ClientModuleManager {
42
- constructor(options) {
43
- this.modules = new discord_js_1.Collection();
44
- this.client = options.client;
45
- options.modules?.forEach(m => {
46
- if (!m.id)
47
- m.id = (0, crypto_1.randomUUID)();
48
- this.modules.set(m.id, this.resolveModule(m));
49
- });
50
- }
51
- async startModulesFromFiles(options) {
52
- const modules = await this.resolveModulesFromFiles(options);
53
- for (const module_ of modules) {
54
- try {
55
- await this.startModule(module_);
56
- }
57
- catch (err) {
58
- if (options.dontSkipError)
59
- throw err;
60
- if (!this.client.isClientLogsSilent)
61
- this.client.logger.err(`Cannot start module ${ClientModuleManager.getModuleDisplayId(module_)}:`, err);
62
- }
63
- }
64
- return modules;
65
- }
66
- async resolveModulesFromFiles(options) {
67
- const modules = [];
68
- const isVersionCheckDisabled = options.disabeVersionCheck || this.client.config.disableVersionCheck;
69
- for (const file of options.files) {
70
- const moduleFileName = path_1.default.basename(file);
71
- const moduleDirPath = path_1.default.dirname(file);
72
- const id = (0, crypto_1.randomUUID)();
73
- let script;
74
- try {
75
- const resolveModuleFile = await Promise.resolve().then(() => __importStar(require(file)));
76
- script = resolveModuleFile?.default ?? resolveModuleFile;
77
- const module_ = this.resolveModule({
78
- id,
79
- script,
80
- info: {
81
- filename: moduleFileName,
82
- path: moduleDirPath,
83
- },
84
- }, isVersionCheckDisabled);
85
- modules.push(module_);
86
- if (!this.client.isClientLogsSilent)
87
- this.client.logger.log(`Resolved ${file}`);
88
- }
89
- catch (err) {
90
- if (options.dontSkipError)
91
- throw err;
92
- if (!this.client.isClientLogsSilent)
93
- this.client.logger.err(`Cannot resolve module file ${file}:`, err);
94
- }
95
- }
96
- return modules;
97
- }
98
- resolveScriptCommands(...modules) {
99
- const resolvedCommands = [];
100
- for (const script of (0, discord_js_1.normalizeArray)(modules)) {
101
- const commands = [];
102
- if (Array.isArray(script?.commands)) {
103
- for (const command of script.commands) {
104
- if (command.type === builders_1.CommandBuilderType.MessageCommand) {
105
- commands.push(MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command));
106
- }
107
- else if (command.type === builders_1.CommandBuilderType.SlashCommand) {
108
- commands.push(SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command));
109
- }
110
- }
111
- }
112
- const invalidBuilders = commands.some(c => !(0, util_1.validateCommandBuilder)(c));
113
- if (invalidBuilders)
114
- throw new Error(`Module script commands contains a command builder without name or option name`);
115
- resolvedCommands.push({
116
- script,
117
- commands,
118
- });
119
- }
120
- return resolvedCommands;
121
- }
122
- async loadAll(registerApplicationCommands, ...registerApplicationCommandsGuilds) {
123
- await Promise.all(this.modules.map(async (m) => {
124
- if (typeof m.script?.onLoad === 'function') {
125
- try {
126
- await Promise.resolve(m.script.onLoad(this.client)).catch(err => {
127
- throw err;
128
- });
129
- }
130
- catch (err) {
131
- this.modules.delete(m.id);
132
- if (!this.client.isClientLogsSilent)
133
- this.client.logger.error(`Error loading ${m.info.filename ?? 'unknown module'}:`, err);
134
- return;
135
- }
136
- }
137
- this.client.commands.add(m.commands);
138
- if (!this.client.isClientLogsSilent)
139
- this.client.logger.log(`Loaded module: ${ClientModuleManager.getModuleDisplayId(m)}`);
140
- }));
141
- if (!this.client.isClientLogsSilent) {
142
- this.client.logger.info(`${this.modules.size} modules loaded.`);
143
- this.client.logger.info(`${this.client.commands.messageCommands.size} message commands loaded.`);
144
- this.client.logger.info(`${this.client.commands.slashCommands.size} slash commands loaded.`);
145
- }
146
- if (registerApplicationCommands)
147
- this.client.commands.registerApplicationCommands((0, discord_js_1.normalizeArray)(registerApplicationCommandsGuilds));
148
- }
149
- async startModule(mod) {
150
- let err;
151
- const identifier = ClientModuleManager.getModuleDisplayId(mod);
152
- if (!this.client.isClientLogsSilent)
153
- this.client.logger.log(`Starting Module: ${identifier}`);
154
- const start = await Promise.resolve(mod.script.onStart(this.client)).catch(e => (err = e));
155
- if (err)
156
- throw err;
157
- if (!start)
158
- throw new Error(`Module ${identifier} returned 'false' on start`);
159
- this.modules.set(mod.id, mod);
160
- }
161
- resolveModule(mod, disabeVersionCheck) {
162
- const identifier = ClientModuleManager.getModuleDisplayId(mod);
163
- if (!disabeVersionCheck && !mod?.script?.versions?.length)
164
- throw new Error(`Module ${identifier} does not contain supported versions`);
165
- if (typeof mod.script?.onStart !== 'function')
166
- throw new Error(`Module ${identifier} does not have a valid 'onStart' method`);
167
- const versions = (0, discord_js_1.normalizeArray)([mod.script.versions]);
168
- const commands = this.resolveScriptCommands(mod.script)[0].commands;
169
- if (!disabeVersionCheck && !versions.some(v => (0, version_1.isSupportedVersion)(v, version_1.version)))
170
- throw new Error(`Module ${identifier} does not support 'reciple@${version_1.rawVersion}'`);
171
- return {
172
- ...mod,
173
- commands,
174
- };
175
- }
176
- async getModuleFiles(...folders) {
177
- const modules = [];
178
- for (const dir of (0, discord_js_1.normalizeArray)(folders).length ? (0, discord_js_1.normalizeArray)(folders) : (0, discord_js_1.normalizeArray)([this.client.config.modulesFolder])) {
179
- if (!(0, fs_1.existsSync)(dir))
180
- (0, fs_1.mkdirSync)(dir, { recursive: true });
181
- if (!(0, fs_1.lstatSync)(dir).isDirectory())
182
- continue;
183
- modules.push(...(0, fs_1.readdirSync)(dir)
184
- .map(file => path_1.default.join(flags_1.cwd, dir, file))
185
- .filter(file => file.endsWith('.js') || file.endsWith('.cjs')));
186
- }
187
- return modules.filter(file => !this.client.config.ignoredFiles.some(ignored => (0, wildcard_match_1.default)(ignored)(path_1.default.basename(file))));
188
- }
189
- static getModuleDisplayId(mod) {
190
- return mod.info.path && mod.info.filename ? path_1.default.join(mod.info.path, mod.info.filename) : mod.id;
191
- }
192
- }
193
- exports.ClientModuleManager = ClientModuleManager;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommandBuilderType = void 0;
4
- /**
5
- * Types of command builders
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 = {}));
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateCommandBuilder = exports.deprecationWarning = exports.isClass = void 0;
4
- const builders_1 = require("./types/builders");
5
- /**
6
- * Check if an object is a class
7
- * @param object Object to identify
8
- */
9
- function isClass(object) {
10
- const isClassConstructor = object.constructor && object.constructor.toString().substring(0, 5) === 'class';
11
- if (object.prototype === undefined)
12
- return isClassConstructor;
13
- const isPrototypeClassConstructor = object.prototype.constructor && object.prototype.constructor.toString && object.prototype.constructor.toString().substring(0, 5) === 'class';
14
- return isClassConstructor || isPrototypeClassConstructor;
15
- }
16
- exports.isClass = isClass;
17
- /**
18
- * Emit process warning about deprecated method/function
19
- * @param content Warning content
20
- */
21
- function deprecationWarning(content) {
22
- process.emitWarning(content, 'DeprecationWarning');
23
- }
24
- exports.deprecationWarning = deprecationWarning;
25
- function validateCommandBuilder(command) {
26
- if (!command.name)
27
- return false;
28
- if (command.type === builders_1.CommandBuilderType.MessageCommand && command.options.length && command.options.some(o => !o.name))
29
- return false;
30
- return true;
31
- }
32
- exports.validateCommandBuilder = validateCommandBuilder;
@@ -1,37 +0,0 @@
1
- import { ApplicationCommandData, Collection, GuildResolvable, RestOrArray } from 'discord.js';
2
- import { AnyCommandBuilder, AnyCommandData, AnySlashCommandBuilder, CommandBuilderType, MessageCommandData, SlashCommandData } from '../../types/builders';
3
- import { MessageCommandBuilder } from '../builders/MessageCommandBuilder';
4
- import { SlashCommandBuilder } from '../builders/SlashCommandBuilder';
5
- import { RecipleClient } from '../RecipleClient';
6
- import { ApplicationCommandBuilder } from './ApplicationCommandManager';
7
- export interface ClientCommandManagerOptions {
8
- client: RecipleClient;
9
- messageCommands?: (MessageCommandBuilder | MessageCommandData)[];
10
- slashCommands?: (AnySlashCommandBuilder | SlashCommandData)[];
11
- }
12
- export declare class ClientCommandManager {
13
- readonly client: RecipleClient;
14
- readonly slashCommands: Collection<string, AnySlashCommandBuilder>;
15
- readonly messageCommands: Collection<string, MessageCommandBuilder>;
16
- readonly additionalApplicationCommands: (ApplicationCommandBuilder | ApplicationCommandData)[];
17
- get applicationCommandsSize(): number;
18
- constructor(options: ClientCommandManagerOptions);
19
- /**
20
- * Add command to command manager
21
- * @param commands Any command data or builder
22
- */
23
- add(...commands: RestOrArray<AnyCommandBuilder | AnyCommandData>): this;
24
- /**
25
- * Get command builder by name or alias if it's a message command
26
- * @param command Command name
27
- * @param type Command type
28
- */
29
- get(command: string, type?: undefined): AnyCommandBuilder | undefined;
30
- get(command: string, type?: CommandBuilderType.MessageCommand): MessageCommandBuilder | undefined;
31
- get(command: string, type?: CommandBuilderType.SlashCommand): SlashCommandBuilder | undefined;
32
- /**
33
- * Register application commands
34
- * @param guilds Register application commands to guilds
35
- */
36
- registerApplicationCommands(...guilds: RestOrArray<GuildResolvable>): Promise<this>;
37
- }
@@ -1,79 +0,0 @@
1
- import { Collection, GuildResolvable, RestOrArray } from 'discord.js';
2
- import { AnyCommandBuilder, AnyCommandData } from '../../types/builders';
3
- import { ModuleManagerResolveFilesOptions } from '../../types/paramOptions';
4
- 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
- }
61
- export interface ClientModuleManagerOptions {
62
- client: RecipleClient;
63
- modules?: (RecipleModule & {
64
- id?: string;
65
- })[];
66
- }
67
- export declare class ClientModuleManager {
68
- readonly client: RecipleClient;
69
- readonly modules: Collection<string, ResolvedModule>;
70
- 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;
77
- getModuleFiles(...folders: RestOrArray<string>): Promise<string[]>;
78
- static getModuleDisplayId(mod: RecipleModule): string;
79
- }
@@ -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;
package/docs/README.md DELETED
@@ -1 +0,0 @@
1
- # [VIEW DOCS](https://reciple.js.org/#/docs)