reciple 6.0.0-dev.25 → 6.0.0-dev.26

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 (46) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +183 -183
  3. package/dist/lib/bin.mjs +67 -66
  4. package/dist/lib/esm.mjs +1 -1
  5. package/dist/lib/index.js +33 -33
  6. package/dist/lib/reciple/classes/RecipleClient.js +307 -296
  7. package/dist/lib/reciple/classes/RecipleConfig.js +106 -106
  8. package/dist/lib/reciple/classes/RecipleModule.js +94 -94
  9. package/dist/lib/reciple/classes/builders/MessageCommandBuilder.js +309 -309
  10. package/dist/lib/reciple/classes/builders/MessageCommandOptionBuilder.js +126 -126
  11. package/dist/lib/reciple/classes/builders/SlashCommandBuilder.js +246 -246
  12. package/dist/lib/reciple/classes/managers/ApplicationCommandManager.js +178 -178
  13. package/dist/lib/reciple/classes/managers/CommandCooldownManager.js +99 -99
  14. package/dist/lib/reciple/classes/managers/CommandManager.js +60 -59
  15. package/dist/lib/reciple/classes/managers/MessageCommandOptionManager.js +25 -25
  16. package/dist/lib/reciple/classes/managers/ModuleManager.js +176 -176
  17. package/dist/lib/reciple/flags.js +31 -31
  18. package/dist/lib/reciple/permissions.js +30 -30
  19. package/dist/lib/reciple/types/builders.js +11 -11
  20. package/dist/lib/reciple/types/commands.js +15 -15
  21. package/dist/lib/reciple/types/paramOptions.js +2 -2
  22. package/dist/lib/reciple/util.js +71 -69
  23. package/dist/lib/reciple/version.js +47 -47
  24. package/dist/types/bin.d.mts +2 -2
  25. package/dist/types/esm.d.mts +1 -1
  26. package/dist/types/index.d.ts +17 -17
  27. package/dist/types/reciple/classes/RecipleClient.d.ts +114 -104
  28. package/dist/types/reciple/classes/RecipleConfig.d.ts +100 -100
  29. package/dist/types/reciple/classes/RecipleModule.d.ts +56 -56
  30. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +189 -189
  31. package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +53 -53
  32. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +98 -98
  33. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +53 -53
  34. package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +70 -70
  35. package/dist/types/reciple/classes/managers/CommandManager.d.ts +34 -34
  36. package/dist/types/reciple/classes/managers/MessageCommandOptionManager.d.ts +22 -22
  37. package/dist/types/reciple/classes/managers/ModuleManager.d.ts +49 -49
  38. package/dist/types/reciple/flags.d.ts +17 -17
  39. package/dist/types/reciple/permissions.d.ts +15 -15
  40. package/dist/types/reciple/types/builders.d.ts +205 -205
  41. package/dist/types/reciple/types/commands.d.ts +81 -81
  42. package/dist/types/reciple/types/paramOptions.d.ts +101 -101
  43. package/dist/types/reciple/util.d.ts +26 -26
  44. package/dist/types/reciple/version.d.ts +25 -25
  45. package/package.json +2 -2
  46. package/resource/reciple.yml +120 -120
@@ -1,106 +1,106 @@
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.RecipleConfig = void 0;
7
- const fs_1 = require("fs");
8
- const version_1 = require("../version");
9
- const fallout_utility_1 = require("fallout-utility");
10
- const flags_1 = require("../flags");
11
- const util_1 = require("../util");
12
- const yaml_1 = __importDefault(require("yaml"));
13
- /**
14
- * Create/parse reciple config
15
- */
16
- class RecipleConfig {
17
- /**
18
- * @param configPath Path to config
19
- */
20
- constructor(configPath) {
21
- this.config = RecipleConfig.getDefaultConfig();
22
- this.configPath = util_1.path.join(process.cwd(), 'reciple.yml');
23
- if (!configPath)
24
- throw new Error('Config path is not defined');
25
- this.configPath = configPath;
26
- }
27
- /**
28
- * Parse the config file
29
- */
30
- parseConfig() {
31
- if (!(0, fs_1.existsSync)(this.configPath)) {
32
- const defaultConfigPath = RecipleConfig.defaultConfigPath;
33
- if (!(0, fs_1.existsSync)(defaultConfigPath))
34
- throw new Error('Default Config file not found. Please reinstall Reciple.');
35
- const defaultConfig = (0, fallout_utility_1.replaceAll)((0, fs_1.readFileSync)(defaultConfigPath, 'utf-8'), 'VERSION', version_1.version);
36
- (0, fs_1.writeFileSync)(this.configPath, defaultConfig, 'utf-8');
37
- if (!(0, fs_1.existsSync)(this.configPath))
38
- throw new Error('Failed to create config file.');
39
- this.config = yaml_1.default.parse(defaultConfig);
40
- if (this.config && this.config.token === 'TOKEN') {
41
- this.config.token = this._askToken() || this.config.token;
42
- (0, fs_1.writeFileSync)(this.configPath, (0, fallout_utility_1.replaceAll)(defaultConfig, ' TOKEN', ` ${this.config.token}`), 'utf-8');
43
- }
44
- return this;
45
- }
46
- if (!(0, fs_1.existsSync)(this.configPath))
47
- throw new Error('Failed to read config file.');
48
- const config = (0, fs_1.readFileSync)(this.configPath, 'utf-8');
49
- this.config = yaml_1.default.parse(config);
50
- if (!this._isSupportedConfig())
51
- throw new Error('Unsupported config version. Your config version: ' + (this.config?.version || 'No version specified.') + ', Reciple version: ' + version_1.version);
52
- return this;
53
- }
54
- /**
55
- * Returns the parsed config file
56
- */
57
- getConfig() {
58
- if (!this.config)
59
- throw new Error('Config is not parsed.');
60
- this.config.token = this.parseToken() || 'TOKEN';
61
- return this.config;
62
- }
63
- /**
64
- * Parse token from config
65
- * @param askIfEmpty Ask for token if the token is undefined
66
- */
67
- parseToken(askIfEmpty = true) {
68
- let token = flags_1.token || this.config?.token || undefined;
69
- if (!token)
70
- return token || (askIfEmpty ? this._askToken() : null);
71
- const envToken = token.toString().split(':');
72
- if (envToken.length === 2 && envToken[0].toLocaleLowerCase() === 'env' && envToken[1]) {
73
- token = process.env[envToken[1]] || undefined;
74
- }
75
- return token || (askIfEmpty == null ? this._askToken() : null);
76
- }
77
- /**
78
- * Check if the config version is supported
79
- */
80
- _isSupportedConfig() {
81
- return (0, version_1.isSupportedVersion)(this.config?.version || '0.0.0', version_1.version);
82
- }
83
- /**
84
- * Ask for a token
85
- */
86
- _askToken() {
87
- return (flags_1.token ||
88
- (0, fallout_utility_1.input)({
89
- text: 'Bot Token >>> ',
90
- echo: '*',
91
- repeatIfEmpty: true,
92
- sigint: true,
93
- }) ||
94
- null);
95
- }
96
- /**
97
- * Get default config
98
- */
99
- static getDefaultConfig() {
100
- if (!(0, fs_1.existsSync)(this.defaultConfigPath))
101
- throw new Error(`Default config file does not exists: ${this.defaultConfigPath}`);
102
- return yaml_1.default.parse((0, fs_1.readFileSync)(this.defaultConfigPath, 'utf-8'));
103
- }
104
- }
105
- exports.RecipleConfig = RecipleConfig;
106
- RecipleConfig.defaultConfigPath = util_1.path.join(__dirname, '../../../../resource/reciple.yml');
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.RecipleConfig = void 0;
7
+ const fs_1 = require("fs");
8
+ const version_1 = require("../version");
9
+ const fallout_utility_1 = require("fallout-utility");
10
+ const flags_1 = require("../flags");
11
+ const util_1 = require("../util");
12
+ const yaml_1 = __importDefault(require("yaml"));
13
+ /**
14
+ * Create/parse reciple config
15
+ */
16
+ class RecipleConfig {
17
+ /**
18
+ * @param configPath Path to config
19
+ */
20
+ constructor(configPath) {
21
+ this.config = RecipleConfig.getDefaultConfig();
22
+ this.configPath = util_1.path.join(process.cwd(), 'reciple.yml');
23
+ if (!configPath)
24
+ throw new Error('Config path is not defined');
25
+ this.configPath = configPath;
26
+ }
27
+ /**
28
+ * Parse the config file
29
+ */
30
+ parseConfig() {
31
+ if (!(0, fs_1.existsSync)(this.configPath)) {
32
+ const defaultConfigPath = RecipleConfig.defaultConfigPath;
33
+ if (!(0, fs_1.existsSync)(defaultConfigPath))
34
+ throw new Error('Default Config file not found. Please reinstall Reciple.');
35
+ const defaultConfig = (0, fallout_utility_1.replaceAll)((0, fs_1.readFileSync)(defaultConfigPath, 'utf-8'), 'VERSION', version_1.version);
36
+ (0, fs_1.writeFileSync)(this.configPath, defaultConfig, 'utf-8');
37
+ if (!(0, fs_1.existsSync)(this.configPath))
38
+ throw new Error('Failed to create config file.');
39
+ this.config = yaml_1.default.parse(defaultConfig);
40
+ if (this.config && this.config.token === 'TOKEN') {
41
+ this.config.token = this._askToken() || this.config.token;
42
+ (0, fs_1.writeFileSync)(this.configPath, (0, fallout_utility_1.replaceAll)(defaultConfig, ' TOKEN', ` ${this.config.token}`), 'utf-8');
43
+ }
44
+ return this;
45
+ }
46
+ if (!(0, fs_1.existsSync)(this.configPath))
47
+ throw new Error('Failed to read config file.');
48
+ const config = (0, fs_1.readFileSync)(this.configPath, 'utf-8');
49
+ this.config = yaml_1.default.parse(config);
50
+ if (!this._isSupportedConfig())
51
+ throw new Error('Unsupported config version. Your config version: ' + (this.config?.version || 'No version specified.') + ', Reciple version: ' + version_1.version);
52
+ return this;
53
+ }
54
+ /**
55
+ * Returns the parsed config file
56
+ */
57
+ getConfig() {
58
+ if (!this.config)
59
+ throw new Error('Config is not parsed.');
60
+ this.config.token = this.parseToken() || 'TOKEN';
61
+ return this.config;
62
+ }
63
+ /**
64
+ * Parse token from config
65
+ * @param askIfEmpty Ask for token if the token is undefined
66
+ */
67
+ parseToken(askIfEmpty = true) {
68
+ let token = flags_1.token || this.config?.token || undefined;
69
+ if (!token)
70
+ return token || (askIfEmpty ? this._askToken() : null);
71
+ const envToken = token.toString().split(':');
72
+ if (envToken.length === 2 && envToken[0].toLocaleLowerCase() === 'env' && envToken[1]) {
73
+ token = process.env[envToken[1]] || undefined;
74
+ }
75
+ return token || (askIfEmpty == null ? this._askToken() : null);
76
+ }
77
+ /**
78
+ * Check if the config version is supported
79
+ */
80
+ _isSupportedConfig() {
81
+ return (0, version_1.isSupportedVersion)(this.config?.version || '0.0.0', version_1.version);
82
+ }
83
+ /**
84
+ * Ask for a token
85
+ */
86
+ _askToken() {
87
+ return (flags_1.token ||
88
+ (0, fallout_utility_1.input)({
89
+ text: 'Bot Token >>> ',
90
+ echo: '*',
91
+ repeatIfEmpty: true,
92
+ sigint: true,
93
+ }) ||
94
+ null);
95
+ }
96
+ /**
97
+ * Get default config
98
+ */
99
+ static getDefaultConfig() {
100
+ if (!(0, fs_1.existsSync)(this.defaultConfigPath))
101
+ throw new Error(`Default config file does not exists: ${this.defaultConfigPath}`);
102
+ return yaml_1.default.parse((0, fs_1.readFileSync)(this.defaultConfigPath, 'utf-8'));
103
+ }
104
+ }
105
+ exports.RecipleConfig = RecipleConfig;
106
+ RecipleConfig.defaultConfigPath = util_1.path.join(__dirname, '../../../../resource/reciple.yml');
@@ -1,94 +1,94 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RecipleModule = void 0;
4
- const builders_1 = require("../types/builders");
5
- const discord_js_1 = require("discord.js");
6
- const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
7
- const SlashCommandBuilder_1 = require("./builders/SlashCommandBuilder");
8
- const util_1 = require("../util");
9
- const crypto_1 = require("crypto");
10
- class RecipleModule {
11
- constructor(options) {
12
- this.commands = [];
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() {
23
- return Promise.resolve(this.script.onStart(this.client));
24
- }
25
- async load(resolveCommands = true) {
26
- if (typeof this.script.onLoad === 'function')
27
- await this.script.onLoad(this.client);
28
- if (resolveCommands)
29
- this.resolveCommands();
30
- }
31
- async unload(reason) {
32
- if (typeof this.script.onUnload === 'function')
33
- await this.script.onUnload(reason, this.client);
34
- }
35
- async registerSlashCommands(...guilds) {
36
- for (const command of this.commands) {
37
- if (command.type !== builders_1.CommandType.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) {
44
- if (builder.type !== builders_1.CommandType.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) {
61
- if (builder.type !== builders_1.CommandType.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.CommandType.SlashCommand && command?.type !== builders_1.CommandType.MessageCommand)
81
- continue;
82
- const builder = command.type === builders_1.CommandType.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.push(builder);
86
- }
87
- this.client.commands.add(this.commands);
88
- return this.commands;
89
- }
90
- toString() {
91
- return this.displayName;
92
- }
93
- }
94
- exports.RecipleModule = RecipleModule;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecipleModule = void 0;
4
+ const builders_1 = require("../types/builders");
5
+ const discord_js_1 = require("discord.js");
6
+ const MessageCommandBuilder_1 = require("./builders/MessageCommandBuilder");
7
+ const SlashCommandBuilder_1 = require("./builders/SlashCommandBuilder");
8
+ const util_1 = require("../util");
9
+ const crypto_1 = require("crypto");
10
+ class RecipleModule {
11
+ constructor(options) {
12
+ this.commands = [];
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() {
23
+ return Promise.resolve(this.script.onStart(this.client));
24
+ }
25
+ async load(resolveCommands = true) {
26
+ if (typeof this.script.onLoad === 'function')
27
+ await this.script.onLoad(this.client);
28
+ if (resolveCommands)
29
+ this.resolveCommands();
30
+ }
31
+ async unload(reason) {
32
+ if (typeof this.script.onUnload === 'function')
33
+ await this.script.onUnload(reason, this.client);
34
+ }
35
+ async registerSlashCommands(...guilds) {
36
+ for (const command of this.commands) {
37
+ if (command.type !== builders_1.CommandType.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) {
44
+ if (builder.type !== builders_1.CommandType.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) {
61
+ if (builder.type !== builders_1.CommandType.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.CommandType.SlashCommand && command?.type !== builders_1.CommandType.MessageCommand)
81
+ continue;
82
+ const builder = command.type === builders_1.CommandType.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.push(builder);
86
+ }
87
+ this.client.commands.add(this.commands);
88
+ return this.commands;
89
+ }
90
+ toString() {
91
+ return this.displayName;
92
+ }
93
+ }
94
+ exports.RecipleModule = RecipleModule;