reciple 6.0.0-dev.27 → 6.0.0-dev.29

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 (85) hide show
  1. package/dist/lib/bin.mjs +68 -67
  2. package/dist/lib/bin.mjs.map +1 -0
  3. package/dist/lib/esm.mjs +2 -1
  4. package/dist/lib/esm.mjs.map +1 -0
  5. package/dist/lib/index.js +34 -33
  6. package/dist/lib/index.js.map +1 -0
  7. package/dist/lib/reciple/classes/RecipleClient.js +308 -307
  8. package/dist/lib/reciple/classes/RecipleClient.js.map +1 -0
  9. package/dist/lib/reciple/classes/RecipleConfig.js +107 -106
  10. package/dist/lib/reciple/classes/RecipleConfig.js.map +1 -0
  11. package/dist/lib/reciple/classes/RecipleModule.js +137 -94
  12. package/dist/lib/reciple/classes/RecipleModule.js.map +1 -0
  13. package/dist/lib/reciple/classes/builders/MessageCommandBuilder.js +310 -309
  14. package/dist/lib/reciple/classes/builders/MessageCommandBuilder.js.map +1 -0
  15. package/dist/lib/reciple/classes/builders/MessageCommandOptionBuilder.js +127 -126
  16. package/dist/lib/reciple/classes/builders/MessageCommandOptionBuilder.js.map +1 -0
  17. package/dist/lib/reciple/classes/builders/SlashCommandBuilder.js +247 -246
  18. package/dist/lib/reciple/classes/builders/SlashCommandBuilder.js.map +1 -0
  19. package/dist/lib/reciple/classes/managers/ApplicationCommandManager.js +179 -178
  20. package/dist/lib/reciple/classes/managers/ApplicationCommandManager.js.map +1 -0
  21. package/dist/lib/reciple/classes/managers/CommandCooldownManager.js +100 -99
  22. package/dist/lib/reciple/classes/managers/CommandCooldownManager.js.map +1 -0
  23. package/dist/lib/reciple/classes/managers/CommandManager.js +65 -60
  24. package/dist/lib/reciple/classes/managers/CommandManager.js.map +1 -0
  25. package/dist/lib/reciple/classes/managers/MessageCommandOptionManager.js +26 -25
  26. package/dist/lib/reciple/classes/managers/MessageCommandOptionManager.js.map +1 -0
  27. package/dist/lib/reciple/classes/managers/ModuleManager.js +181 -180
  28. package/dist/lib/reciple/classes/managers/ModuleManager.js.map +1 -0
  29. package/dist/lib/reciple/flags.js +32 -31
  30. package/dist/lib/reciple/flags.js.map +1 -0
  31. package/dist/lib/reciple/permissions.js +31 -30
  32. package/dist/lib/reciple/permissions.js.map +1 -0
  33. package/dist/lib/reciple/types/builders.js +12 -11
  34. package/dist/lib/reciple/types/builders.js.map +1 -0
  35. package/dist/lib/reciple/types/commands.js +16 -15
  36. package/dist/lib/reciple/types/commands.js.map +1 -0
  37. package/dist/lib/reciple/types/paramOptions.js +3 -2
  38. package/dist/lib/reciple/types/paramOptions.js.map +1 -0
  39. package/dist/lib/reciple/util.js +72 -71
  40. package/dist/lib/reciple/util.js.map +1 -0
  41. package/dist/lib/reciple/version.js +48 -47
  42. package/dist/lib/reciple/version.js.map +1 -0
  43. package/dist/types/bin.d.mts +3 -2
  44. package/dist/types/bin.d.mts.map +1 -0
  45. package/dist/types/esm.d.mts +2 -1
  46. package/dist/types/esm.d.mts.map +1 -0
  47. package/dist/types/index.d.ts +18 -17
  48. package/dist/types/index.d.ts.map +1 -0
  49. package/dist/types/reciple/classes/RecipleClient.d.ts +115 -114
  50. package/dist/types/reciple/classes/RecipleClient.d.ts.map +1 -0
  51. package/dist/types/reciple/classes/RecipleConfig.d.ts +101 -100
  52. package/dist/types/reciple/classes/RecipleConfig.d.ts.map +1 -0
  53. package/dist/types/reciple/classes/RecipleModule.d.ts +88 -56
  54. package/dist/types/reciple/classes/RecipleModule.d.ts.map +1 -0
  55. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts +190 -189
  56. package/dist/types/reciple/classes/builders/MessageCommandBuilder.d.ts.map +1 -0
  57. package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts +54 -53
  58. package/dist/types/reciple/classes/builders/MessageCommandOptionBuilder.d.ts.map +1 -0
  59. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts +99 -98
  60. package/dist/types/reciple/classes/builders/SlashCommandBuilder.d.ts.map +1 -0
  61. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +54 -53
  62. package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts.map +1 -0
  63. package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts +71 -70
  64. package/dist/types/reciple/classes/managers/CommandCooldownManager.d.ts.map +1 -0
  65. package/dist/types/reciple/classes/managers/CommandManager.d.ts +35 -34
  66. package/dist/types/reciple/classes/managers/CommandManager.d.ts.map +1 -0
  67. package/dist/types/reciple/classes/managers/MessageCommandOptionManager.d.ts +23 -22
  68. package/dist/types/reciple/classes/managers/MessageCommandOptionManager.d.ts.map +1 -0
  69. package/dist/types/reciple/classes/managers/ModuleManager.d.ts +50 -49
  70. package/dist/types/reciple/classes/managers/ModuleManager.d.ts.map +1 -0
  71. package/dist/types/reciple/flags.d.ts +18 -17
  72. package/dist/types/reciple/flags.d.ts.map +1 -0
  73. package/dist/types/reciple/permissions.d.ts +16 -15
  74. package/dist/types/reciple/permissions.d.ts.map +1 -0
  75. package/dist/types/reciple/types/builders.d.ts +206 -205
  76. package/dist/types/reciple/types/builders.d.ts.map +1 -0
  77. package/dist/types/reciple/types/commands.d.ts +82 -81
  78. package/dist/types/reciple/types/commands.d.ts.map +1 -0
  79. package/dist/types/reciple/types/paramOptions.d.ts +102 -101
  80. package/dist/types/reciple/types/paramOptions.d.ts.map +1 -0
  81. package/dist/types/reciple/util.d.ts +27 -26
  82. package/dist/types/reciple/util.d.ts.map +1 -0
  83. package/dist/types/reciple/version.d.ts +26 -25
  84. package/dist/types/reciple/version.d.ts.map +1 -0
  85. package/package.json +8 -6
@@ -1,106 +1,107 @@
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');
107
+ //# sourceMappingURL=RecipleConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecipleConfig.js","sourceRoot":"","sources":["../../../../src/reciple/classes/RecipleConfig.ts"],"names":[],"mappings":";;;;;;AACA,2BAA6D;AAC7D,wCAAyD;AACzD,qDAAoD;AACpD,oCAA4C;AAC5C,kCAA+B;AAC/B,gDAAwB;AAkExB;;GAEG;AACH,MAAa,aAAa;IAKtB;;OAEG;IACH,YAAY,UAAkB;QAPvB,WAAM,GAAW,aAAa,CAAC,gBAAgB,EAAE,CAAC;QAClD,eAAU,GAAW,WAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EA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C,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC;SACjD;QAED,OAAO,KAAK,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACnE,CAAC;IAED;;OAEG;IACO,kBAAkB;QACxB,OAAO,IAAA,4BAAkB,EAAC,IAAI,CAAC,MAAM,EAAE,OAAO,IAAI,OAAO,EAAE,iBAAO,CAAC,CAAC;IACxE,CAAC;IAED;;OAEG;IACO,SAAS;QACf,OAAO,CACH,aAAO;YACP,IAAA,uBAAK,EAAC;gBACF,IAAI,EAAE,gBAAgB;gBACtB,IAAI,EAAE,GAAG;gBACT,aAAa,EAAE,IAAI;gBACnB,MAAM,EAAE,IAAI;aACf,CAAC;YACF,IAAI,CACP,CAAC;IACN,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,gBAAgB;QAC1B,IAAI,CAAC,IAAA,eAAU,EAAC,IAAI,CAAC,iBAAiB,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;QAE3H,OAAO,cAAI,CAAC,KAAK,CAAC,IAAA,iBAAY,EAAC,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,CAAC;IACrE,CAAC;;AArGL,sCAsGC;AAnGiB,+BAAiB,GAAG,WAAI,CAAC,IAAI,CAAC,SAAS,EAAE,kCAAkC,CAAC,CAAC"}
@@ -1,94 +1,137 @@
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
+ const version_1 = require("../version");
11
+ class RecipleModule {
12
+ constructor(options) {
13
+ this.commands = [];
14
+ this.id = (0, crypto_1.randomUUID)();
15
+ this.client = options.client;
16
+ this.script = options.script;
17
+ this.filePath = options.filePath;
18
+ this.metadata = options.metadata;
19
+ }
20
+ get versions() {
21
+ return this.script.versions;
22
+ }
23
+ get onStart() {
24
+ return this.script.onStart;
25
+ }
26
+ get onLoad() {
27
+ return this.script.onLoad;
28
+ }
29
+ get onUnload() {
30
+ return this.script.onUnload;
31
+ }
32
+ get displayName() {
33
+ return this.filePath ?? this.id;
34
+ }
35
+ get isSupported() {
36
+ return (0, discord_js_1.normalizeArray)([this.versions]).some(v => (0, version_1.isSupportedVersion)(v, this.client.version));
37
+ }
38
+ /**
39
+ * Execute module's {@link RecipleScript.onStart}
40
+ */
41
+ async start() {
42
+ return Promise.resolve(this.script.onStart(this.client));
43
+ }
44
+ /**
45
+ * Execute module's {@link RecipleScript.onLoad}
46
+ * @param resolveCommands Parse commands
47
+ */
48
+ async load(resolveCommands = true) {
49
+ if (typeof this.script.onLoad === 'function')
50
+ await this.script.onLoad(this.client);
51
+ if (resolveCommands)
52
+ this.resolveCommands();
53
+ }
54
+ /**
55
+ * Execute module's {@link RecipleScript.onUnload}
56
+ * @param reason Unload reason
57
+ */
58
+ async unload(reason) {
59
+ if (typeof this.script.onUnload === 'function')
60
+ await this.script.onUnload(reason, this.client);
61
+ }
62
+ /**
63
+ * Register application commands from this module
64
+ * @param guilds Register to certain guilds
65
+ */
66
+ async registerSlashCommands(...guilds) {
67
+ for (const command of this.commands) {
68
+ if (command.type !== builders_1.CommandType.SlashCommand)
69
+ continue;
70
+ await this.client.applicationCommands.add(command, (0, discord_js_1.normalizeArray)(guilds));
71
+ }
72
+ }
73
+ /**
74
+ * Unregister application commands from this module
75
+ * @param guilds Unregister from certain guilds
76
+ */
77
+ async unregisterSlashCommands(...guilds) {
78
+ for (const builder of this.commands) {
79
+ if (builder.type !== builders_1.CommandType.SlashCommand)
80
+ continue;
81
+ if ((0, discord_js_1.normalizeArray)(guilds).length) {
82
+ for (const guild of (0, discord_js_1.normalizeArray)(guilds)) {
83
+ const command = this.client.applicationCommands.get(builder, guild);
84
+ if (command)
85
+ await this.client.applicationCommands.remove(command, guild);
86
+ }
87
+ continue;
88
+ }
89
+ const command = this.client.applicationCommands.get(builder);
90
+ if (command)
91
+ await this.client.applicationCommands.remove(command);
92
+ }
93
+ }
94
+ /**
95
+ * Update registered application commands of this module
96
+ * @param guilds update commands from certain guilds
97
+ */
98
+ async updateSlashCommands(...guilds) {
99
+ for (const builder of this.commands) {
100
+ if (builder.type !== builders_1.CommandType.SlashCommand)
101
+ continue;
102
+ if ((0, discord_js_1.normalizeArray)(guilds).length) {
103
+ for (const guild of (0, discord_js_1.normalizeArray)(guilds)) {
104
+ const command = this.client.applicationCommands.get(builder, guild);
105
+ if (command)
106
+ await this.client.applicationCommands.edit(command, builder, guild);
107
+ }
108
+ continue;
109
+ }
110
+ const command = this.client.applicationCommands.get(builder);
111
+ if (command)
112
+ await this.client.applicationCommands.edit(command, builder);
113
+ }
114
+ }
115
+ /**
116
+ * Resolve module commands
117
+ */
118
+ resolveCommands() {
119
+ if (!Array.isArray(this.script?.commands))
120
+ return this.commands;
121
+ for (const command of this.script.commands) {
122
+ if (command?.type !== builders_1.CommandType.SlashCommand && command?.type !== builders_1.CommandType.MessageCommand)
123
+ continue;
124
+ const builder = command.type === builders_1.CommandType.SlashCommand ? SlashCommandBuilder_1.SlashCommandBuilder.resolveSlashCommand(command) : MessageCommandBuilder_1.MessageCommandBuilder.resolveMessageCommand(command);
125
+ if (!(0, util_1.validateCommandBuilder)(builder))
126
+ throw new Error('Invalid command builder, no name or contains option(s) without name');
127
+ this.commands.push(builder);
128
+ }
129
+ this.client.commands.add(this.commands);
130
+ return this.commands;
131
+ }
132
+ toString() {
133
+ return this.displayName;
134
+ }
135
+ }
136
+ exports.RecipleModule = RecipleModule;
137
+ //# sourceMappingURL=RecipleModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecipleModule.js","sourceRoot":"","sources":["../../../../src/reciple/classes/RecipleModule.ts"],"names":[],"mappings":";;;AAAA,gDAAmF;AACnF,2CAA0E;AAC1E,4EAAyE;AACzE,wEAAqE;AACrE,kCAAiD;AAEjD,mCAAoC;AACpC,wCAAgD;AAuChD,MAAa,aAAa;IAgCtB,YAAY,OAAgC;QA7B5B,aAAQ,GAAwB,EAAE,CAAC;QA8B/C,IAAI,CAAC,EAAE,GAAG,IAAA,mBAAU,GAAE,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;I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