reciple 6.0.0-dev.15 → 6.0.0-dev.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/bin.mjs +16 -7
- package/dist/lib/reciple/classes/RecipleClient.js +1 -0
- package/dist/lib/reciple/classes/RecipleConfig.js +1 -1
- package/dist/lib/reciple/classes/RecipleModule.js +3 -3
- package/dist/lib/reciple/classes/managers/ApplicationCommandManager.js +37 -1
- package/dist/lib/reciple/classes/managers/ClientModuleManager.js +64 -25
- package/dist/types/reciple/classes/RecipleClient.d.ts +2 -0
- package/dist/types/reciple/classes/RecipleModule.d.ts +2 -2
- package/dist/types/reciple/classes/managers/ApplicationCommandManager.d.ts +36 -0
- package/dist/types/reciple/classes/managers/ClientModuleManager.d.ts +35 -5
- package/dist/types/reciple/types/paramOptions.d.ts +73 -2
- package/package.json +1 -1
- package/resource/reciple.yml +3 -1
package/dist/lib/bin.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import 'dotenv/config';
|
|
|
10
10
|
import path from 'path';
|
|
11
11
|
import { inspect } from 'util';
|
|
12
12
|
const allowedFiles = ['node_modules', 'reciple.yml', 'package.json'];
|
|
13
|
-
const configPath = path.join(cwd, '
|
|
13
|
+
const configPath = path.join(cwd, 'reciple.yml');
|
|
14
14
|
if (readdirSync(cwd).filter(f => !f.startsWith('.') && allowedFiles.indexOf(f)).length > 0 && !existsSync(flags.config ?? configPath)) {
|
|
15
15
|
const ask = (flags.yes ? 'y' : null) ?? input('This directory does not contain reciple.yml. Would you like to init axis here? [y/n] ') ?? '';
|
|
16
16
|
if (ask.toString().toLowerCase() !== 'y')
|
|
@@ -25,20 +25,29 @@ catch (err) {
|
|
|
25
25
|
process.exit(1);
|
|
26
26
|
}
|
|
27
27
|
const config = configParser.getConfig();
|
|
28
|
-
const client = new RecipleClient({ config: config, ...config.client });
|
|
28
|
+
const client = new RecipleClient({ config: config, cwd, ...config.client });
|
|
29
29
|
/**
|
|
30
30
|
* Start
|
|
31
31
|
*/
|
|
32
32
|
if (!client.isClientLogsSilent)
|
|
33
33
|
client.logger.info('Starting Reciple client v' + rawVersion);
|
|
34
34
|
client.addCommandListeners();
|
|
35
|
-
await client.modules.startModules(
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
await client.modules.startModules({
|
|
36
|
+
modules: await client.modules.resolveModuleFiles({
|
|
37
|
+
files: await client.modules.getModulePaths({
|
|
38
|
+
filter: file => file.endsWith('.js') || file.endsWith('.cjs') || file.endsWith('.mjs'),
|
|
39
|
+
}),
|
|
38
40
|
}),
|
|
39
|
-
})
|
|
41
|
+
});
|
|
40
42
|
client.on('ready', async () => {
|
|
41
|
-
await client.modules.loadModules(
|
|
43
|
+
await client.modules.loadModules();
|
|
44
|
+
const unloadModulesAndStopProcess = async (signal) => {
|
|
45
|
+
await client.modules.unloadModules({ reason: 'ProcessExit' });
|
|
46
|
+
client.logger.warn(`Exitting process${signal === 'SIGINT' ? ': keyboard interrupt' : signal === 'SIGTERM' ? ': terminate' : signal}`);
|
|
47
|
+
process.exit();
|
|
48
|
+
};
|
|
49
|
+
process.once('SIGINT', signal => unloadModulesAndStopProcess(signal));
|
|
50
|
+
process.once('SIGTERM', signal => unloadModulesAndStopProcess(signal));
|
|
42
51
|
if (!client.isClientLogsSilent)
|
|
43
52
|
client.logger.log(`Loaded ${client.commands.slashCommands.size} slash commands`, `Loaded ${client.commands.messageCommands.size} message commands`);
|
|
44
53
|
if (client.config.commands.slashCommand.registerCommands && (client.config.commands.slashCommand.allowRegisterEmptyCommandList || client.commands.applicationCommandsSize)) {
|
|
@@ -40,6 +40,7 @@ class RecipleClient extends discord_js_1.Client {
|
|
|
40
40
|
this.config = { ...this.config, ...(options.config ?? {}) };
|
|
41
41
|
if (this.config.fileLogging.enabled)
|
|
42
42
|
this.logger.logFile(path_1.default.join(flags_1.cwd, this.config.fileLogging.logFilePath ?? 'logs/latest.log'), false);
|
|
43
|
+
this.cwd = options.cwd ?? process.cwd();
|
|
43
44
|
this.applicationCommands = new ApplicationCommandManager_1.ApplicationCommandManager(this);
|
|
44
45
|
}
|
|
45
46
|
get isClientLogsSilent() {
|
|
@@ -19,7 +19,7 @@ class RecipleConfig {
|
|
|
19
19
|
*/
|
|
20
20
|
constructor(configPath) {
|
|
21
21
|
this.config = RecipleConfig.getDefaultConfig();
|
|
22
|
-
this.configPath = path_1.default.join(
|
|
22
|
+
this.configPath = path_1.default.join(process.cwd(), 'reciple.yml');
|
|
23
23
|
if (!configPath)
|
|
24
24
|
throw new Error('Config path is not defined');
|
|
25
25
|
this.configPath = configPath;
|
|
@@ -28,9 +28,9 @@ class RecipleModule {
|
|
|
28
28
|
if (resolveCommands)
|
|
29
29
|
this.resolveCommands();
|
|
30
30
|
}
|
|
31
|
-
async
|
|
32
|
-
if (typeof this.script.
|
|
33
|
-
await this.script.
|
|
31
|
+
async unload(reason) {
|
|
32
|
+
if (typeof this.script.onUnload === 'function')
|
|
33
|
+
await this.script.onUnload(reason, this.client);
|
|
34
34
|
}
|
|
35
35
|
async registerSlashCommands(...guilds) {
|
|
36
36
|
for (const command of this.commands) {
|
|
@@ -7,6 +7,11 @@ class ApplicationCommandManager {
|
|
|
7
7
|
constructor(client) {
|
|
8
8
|
this.client = client;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Sets application commands globally or in guilds
|
|
12
|
+
* @param commands Application commands
|
|
13
|
+
* @param guilds set only to guilds
|
|
14
|
+
*/
|
|
10
15
|
async set(commands, ...guilds) {
|
|
11
16
|
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
12
17
|
if (!this.client.isReady())
|
|
@@ -27,9 +32,14 @@ class ApplicationCommandManager {
|
|
|
27
32
|
else {
|
|
28
33
|
await this.client.application.commands.set(commands, guild);
|
|
29
34
|
if (!this.client.isClientLogsSilent)
|
|
30
|
-
this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) to guild ${guild}
|
|
35
|
+
this.client.logger.log(`Registered ${this.client.commands.applicationCommandsSize} application command(s) to guild ${guild}`);
|
|
31
36
|
}
|
|
32
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Add command globally or in guilds
|
|
40
|
+
* @param command Application command
|
|
41
|
+
* @param guilds add only in guilds
|
|
42
|
+
*/
|
|
33
43
|
async add(command, ...guilds) {
|
|
34
44
|
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
35
45
|
if (!this.client.isReady())
|
|
@@ -55,6 +65,11 @@ class ApplicationCommandManager {
|
|
|
55
65
|
this.client.logger.log(`Created application command '${command.name}' to guild ${guild}`);
|
|
56
66
|
}
|
|
57
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Remove application command globally or in guilds
|
|
70
|
+
* @param command id of application commmand or ApplicationCommand class
|
|
71
|
+
* @param guilds Remove from guilds
|
|
72
|
+
*/
|
|
58
73
|
async remove(command, ...guilds) {
|
|
59
74
|
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
60
75
|
if (!this.client.isReady())
|
|
@@ -80,6 +95,12 @@ class ApplicationCommandManager {
|
|
|
80
95
|
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
|
|
81
96
|
}
|
|
82
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Edit application command globally or in guilds
|
|
100
|
+
* @param command id of application command or ApplicationCommand class
|
|
101
|
+
* @param newCommand new application command data
|
|
102
|
+
* @param guilds Edit only from guilds
|
|
103
|
+
*/
|
|
83
104
|
async edit(command, newCommand, ...guilds) {
|
|
84
105
|
guilds = (0, discord_js_1.normalizeArray)(guilds);
|
|
85
106
|
if (!this.client.isReady())
|
|
@@ -105,18 +126,33 @@ class ApplicationCommandManager {
|
|
|
105
126
|
this.client.logger.log(`Removed application command '${typeof command === 'string' ? command : command.name}' from guild ${guild}`);
|
|
106
127
|
}
|
|
107
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Get application command from cache by application command data, builder, id, or name globally or from guid
|
|
131
|
+
* @param command application command data, builder, id, or name
|
|
132
|
+
* @param guild get command from guild
|
|
133
|
+
*/
|
|
108
134
|
get(command, guild) {
|
|
109
135
|
const commands = guild ? this.client.guilds.resolve(guild)?.commands.cache : this.client.application?.commands.cache;
|
|
110
136
|
if (!commands)
|
|
111
137
|
throw new Error('Guild not found in cache');
|
|
112
138
|
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
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Fetch application command by id globally or from guild
|
|
142
|
+
* @param commandId command id
|
|
143
|
+
* @param guild fetch from guild
|
|
144
|
+
*/
|
|
114
145
|
async fetch(commandId, guild) {
|
|
115
146
|
const manager = guild ? this.client.guilds.resolve(guild)?.commands : this.client.application?.commands;
|
|
116
147
|
if (!manager)
|
|
117
148
|
throw new Error('Guild not found in cache');
|
|
118
149
|
return manager.fetch(commandId);
|
|
119
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Parse application command builders to command data
|
|
153
|
+
* @param commands Application command builders
|
|
154
|
+
* @param setPermissions set slash commands permissions
|
|
155
|
+
*/
|
|
120
156
|
parseCommands(commands, setPermissions = true) {
|
|
121
157
|
return commands.map(cmd => {
|
|
122
158
|
if (cmd?.toJSON === undefined)
|
|
@@ -9,7 +9,6 @@ const fs_1 = require("fs");
|
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const util_1 = require("util");
|
|
11
11
|
const wildcard_match_1 = __importDefault(require("wildcard-match"));
|
|
12
|
-
const flags_1 = require("../../flags");
|
|
13
12
|
const RecipleModule_1 = require("../RecipleModule");
|
|
14
13
|
class ClientModuleManager {
|
|
15
14
|
constructor(options) {
|
|
@@ -17,8 +16,14 @@ class ClientModuleManager {
|
|
|
17
16
|
this.client = options.client;
|
|
18
17
|
options.modules?.forEach(m => (m instanceof RecipleModule_1.RecipleModule ? m : new RecipleModule_1.RecipleModule({ client: this.client, script: m })));
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Start modules
|
|
21
|
+
* @param options start modules options
|
|
22
|
+
* @returns started modules
|
|
23
|
+
*/
|
|
24
|
+
async startModules(options) {
|
|
25
|
+
const startedModules = [];
|
|
26
|
+
for (const module_ of options.modules) {
|
|
22
27
|
if (!this.client.isClientLogsSilent)
|
|
23
28
|
this.client.logger.log(`Starting module '${module_}'`);
|
|
24
29
|
try {
|
|
@@ -34,64 +39,88 @@ class ClientModuleManager {
|
|
|
34
39
|
this.client.logger.error(`Module '${module_}' returned false onStart`);
|
|
35
40
|
continue;
|
|
36
41
|
}
|
|
37
|
-
|
|
42
|
+
if (options.addToModulesCollection !== false)
|
|
43
|
+
this.modules.set(module_.id, module_);
|
|
44
|
+
startedModules.push(module_);
|
|
38
45
|
}
|
|
39
46
|
catch (err) {
|
|
40
|
-
if (
|
|
47
|
+
if (options?.ignoreErrors === false)
|
|
41
48
|
throw err;
|
|
42
49
|
if (!this.client.isClientLogsSilent)
|
|
43
50
|
this.client.logger.error(`Failed to start module '${module_}': `, err);
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
|
-
return
|
|
53
|
+
return startedModules;
|
|
47
54
|
}
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Load modules
|
|
57
|
+
* @param options load modules options
|
|
58
|
+
* @returns loaded modules
|
|
59
|
+
*/
|
|
60
|
+
async loadModules(options) {
|
|
61
|
+
const loadedModules = [];
|
|
62
|
+
for (const module_ of options?.modules ?? this.modules.toJSON()) {
|
|
50
63
|
try {
|
|
51
64
|
await module_.load().catch(err => {
|
|
52
65
|
throw err;
|
|
53
66
|
});
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
if (addModuleCommandsToClient) {
|
|
67
|
+
if (options?.resolveCommands !== false) {
|
|
68
|
+
module_.resolveCommands();
|
|
57
69
|
this.client.commands.add(module_.commands);
|
|
58
70
|
}
|
|
71
|
+
loadedModules.push(module_);
|
|
72
|
+
if (!this.client.isClientLogsSilent)
|
|
73
|
+
this.client.logger.log(`Loaded module '${module_}'`);
|
|
59
74
|
}
|
|
60
75
|
catch (err) {
|
|
61
|
-
if (
|
|
76
|
+
if (options?.ignoreErrors === false)
|
|
62
77
|
throw err;
|
|
63
78
|
if (!this.client.isClientLogsSilent)
|
|
64
79
|
this.client.logger.error(`Failed to load module '${module_}': `, err);
|
|
65
80
|
}
|
|
66
81
|
}
|
|
67
|
-
return
|
|
82
|
+
return loadedModules;
|
|
68
83
|
}
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Unload modules
|
|
86
|
+
* @param options unload modules options
|
|
87
|
+
* @returns unloaded modules
|
|
88
|
+
*/
|
|
89
|
+
async unloadModules(options) {
|
|
90
|
+
const unloadedModules = [];
|
|
91
|
+
for (const module_ of options?.modules ?? this.modules.toJSON()) {
|
|
71
92
|
try {
|
|
72
|
-
await module_.
|
|
93
|
+
await module_.unload().catch(err => {
|
|
73
94
|
throw err;
|
|
74
95
|
});
|
|
75
|
-
|
|
76
|
-
this.modules.delete(module_.id);
|
|
96
|
+
unloadedModules.push(module_);
|
|
77
97
|
if (!this.client.isClientLogsSilent)
|
|
78
98
|
this.client.logger.log(`Unloaded module '${module_}'`);
|
|
79
99
|
}
|
|
80
100
|
catch (err) {
|
|
81
|
-
if (
|
|
101
|
+
if (options?.ignoreErrors === false)
|
|
82
102
|
throw err;
|
|
83
103
|
if (!this.client.isClientLogsSilent)
|
|
84
104
|
this.client.logger.error(`Failed to unLoad module '${module_}': `, err);
|
|
85
105
|
}
|
|
86
106
|
}
|
|
87
|
-
return
|
|
107
|
+
return unloadedModules;
|
|
88
108
|
}
|
|
89
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Resolve modules from file paths
|
|
111
|
+
* @param options resolve module files options
|
|
112
|
+
* @returns resolved modules
|
|
113
|
+
*/
|
|
114
|
+
async resolveModuleFiles(options) {
|
|
90
115
|
const modules = [];
|
|
91
116
|
for (const file of options.files) {
|
|
92
117
|
try {
|
|
93
118
|
const resolveFile = await import(file);
|
|
94
|
-
let script = resolveFile instanceof RecipleModule_1.RecipleModule || ClientModuleManager.validateScript(resolveFile)
|
|
119
|
+
let script = resolveFile instanceof RecipleModule_1.RecipleModule || ClientModuleManager.validateScript(resolveFile)
|
|
120
|
+
? resolveFile
|
|
121
|
+
: resolveFile?.default?.default instanceof RecipleModule_1.RecipleModule || ClientModuleManager.validateScript(resolveFile?.default?.default)
|
|
122
|
+
? resolveFile.default.default
|
|
123
|
+
: resolveFile?.default;
|
|
95
124
|
if (script instanceof RecipleModule_1.RecipleModule) {
|
|
96
125
|
modules.push(script);
|
|
97
126
|
continue;
|
|
@@ -105,7 +134,7 @@ class ClientModuleManager {
|
|
|
105
134
|
}));
|
|
106
135
|
}
|
|
107
136
|
catch (err) {
|
|
108
|
-
if (options.
|
|
137
|
+
if (options.ignoreErrors === false)
|
|
109
138
|
throw err;
|
|
110
139
|
if (!this.client.isClientLogsSilent)
|
|
111
140
|
this.client.logger.error(`Can't resolve module from: ${file}`, err);
|
|
@@ -113,6 +142,11 @@ class ClientModuleManager {
|
|
|
113
142
|
}
|
|
114
143
|
return modules;
|
|
115
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Validate module script
|
|
147
|
+
* @param script module script
|
|
148
|
+
* @returns `true` if script is valid
|
|
149
|
+
*/
|
|
116
150
|
static validateScript(script) {
|
|
117
151
|
const s = script;
|
|
118
152
|
if (typeof s !== 'object')
|
|
@@ -123,10 +157,15 @@ class ClientModuleManager {
|
|
|
123
157
|
return false;
|
|
124
158
|
if (s.onLoad && typeof s.onLoad !== 'function')
|
|
125
159
|
return false;
|
|
126
|
-
if (s.
|
|
160
|
+
if (s.onUnload && typeof s.onUnload !== 'function')
|
|
127
161
|
return false;
|
|
128
162
|
return true;
|
|
129
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Get module file paths from folders
|
|
166
|
+
* @param options get module paths options
|
|
167
|
+
* @returns module paths
|
|
168
|
+
*/
|
|
130
169
|
async getModulePaths(options) {
|
|
131
170
|
const modules = [];
|
|
132
171
|
for (const dir of options?.folders ?? (0, discord_js_1.normalizeArray)([this.client.config.modulesFolder])) {
|
|
@@ -135,7 +174,7 @@ class ClientModuleManager {
|
|
|
135
174
|
if (!(0, fs_1.lstatSync)(dir).isDirectory())
|
|
136
175
|
continue;
|
|
137
176
|
modules.push(...(0, fs_1.readdirSync)(dir)
|
|
138
|
-
.map(file => path_1.default.join(
|
|
177
|
+
.map(file => path_1.default.join(!dir.startsWith('/') ? this.client.cwd : '', dir, file))
|
|
139
178
|
.filter(file => (options?.filter ? options.filter(file) : file.endsWith('.js'))));
|
|
140
179
|
}
|
|
141
180
|
return modules.filter(file => !(options?.ignoredFiles ?? this.client.config.ignoredFiles).some(ignored => (0, wildcard_match_1.default)(ignored)(path_1.default.basename(file))));
|
|
@@ -13,6 +13,7 @@ import { Logger } from 'fallout-utility';
|
|
|
13
13
|
*/
|
|
14
14
|
export interface RecipleClientOptions extends ClientOptions {
|
|
15
15
|
config?: Config;
|
|
16
|
+
cwd?: string;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Reciple client events
|
|
@@ -45,6 +46,7 @@ export declare class RecipleClient<Ready extends boolean = boolean> extends Clie
|
|
|
45
46
|
readonly applicationCommands: ApplicationCommandManager;
|
|
46
47
|
readonly cooldowns: CommandCooldownManager;
|
|
47
48
|
readonly modules: ClientModuleManager;
|
|
49
|
+
readonly cwd: string;
|
|
48
50
|
readonly logger: Logger;
|
|
49
51
|
readonly version: string;
|
|
50
52
|
get isClientLogsSilent(): boolean;
|
|
@@ -28,7 +28,7 @@ export interface RecipleScript {
|
|
|
28
28
|
* @param reason Unload reason
|
|
29
29
|
* @param client Bot client
|
|
30
30
|
*/
|
|
31
|
-
|
|
31
|
+
onUnload?(reason: unknown, client: RecipleClient<true>): void | Promise<void>;
|
|
32
32
|
}
|
|
33
33
|
export interface RecipleModuleOptions<M = unknown> {
|
|
34
34
|
client: RecipleClient;
|
|
@@ -47,7 +47,7 @@ export declare class RecipleModule<M = unknown> {
|
|
|
47
47
|
constructor(options: RecipleModuleOptions<M>);
|
|
48
48
|
start(): Promise<boolean>;
|
|
49
49
|
load(resolveCommands?: boolean): Promise<void>;
|
|
50
|
-
|
|
50
|
+
unload(reason?: any): Promise<void>;
|
|
51
51
|
registerSlashCommands(...guilds: RestOrArray<GuildResolvable>): Promise<void>;
|
|
52
52
|
unregisterSlashCommands(...guilds: RestOrArray<GuildResolvable>): Promise<void>;
|
|
53
53
|
updateSlashCommands(...guilds: RestOrArray<GuildResolvable>): Promise<void>;
|
|
@@ -5,11 +5,47 @@ export declare type ApplicationCommandBuilder = AnySlashCommandBuilder | Context
|
|
|
5
5
|
export declare class ApplicationCommandManager {
|
|
6
6
|
readonly client: RecipleClient;
|
|
7
7
|
constructor(client: RecipleClient);
|
|
8
|
+
/**
|
|
9
|
+
* Sets application commands globally or in guilds
|
|
10
|
+
* @param commands Application commands
|
|
11
|
+
* @param guilds set only to guilds
|
|
12
|
+
*/
|
|
8
13
|
set(commands: (ApplicationCommandBuilder | ApplicationCommandData)[], ...guilds: RestOrArray<GuildResolvable>): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Add command globally or in guilds
|
|
16
|
+
* @param command Application command
|
|
17
|
+
* @param guilds add only in guilds
|
|
18
|
+
*/
|
|
9
19
|
add(command: ApplicationCommandBuilder | ApplicationCommandData, ...guilds: RestOrArray<GuildResolvable>): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Remove application command globally or in guilds
|
|
22
|
+
* @param command id of application commmand or ApplicationCommand class
|
|
23
|
+
* @param guilds Remove from guilds
|
|
24
|
+
*/
|
|
10
25
|
remove(command: string | ApplicationCommand, ...guilds: RestOrArray<GuildResolvable>): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Edit application command globally or in guilds
|
|
28
|
+
* @param command id of application command or ApplicationCommand class
|
|
29
|
+
* @param newCommand new application command data
|
|
30
|
+
* @param guilds Edit only from guilds
|
|
31
|
+
*/
|
|
11
32
|
edit(command: string | ApplicationCommand, newCommand: ApplicationCommandBuilder | ApplicationCommandData, ...guilds: RestOrArray<GuildResolvable>): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Get application command from cache by application command data, builder, id, or name globally or from guid
|
|
35
|
+
* @param command application command data, builder, id, or name
|
|
36
|
+
* @param guild get command from guild
|
|
37
|
+
*/
|
|
12
38
|
get(command: ApplicationCommandData | ApplicationCommandBuilder | string, guild?: GuildResolvable): ApplicationCommand | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Fetch application command by id globally or from guild
|
|
41
|
+
* @param commandId command id
|
|
42
|
+
* @param guild fetch from guild
|
|
43
|
+
*/
|
|
13
44
|
fetch(commandId: string, guild?: GuildResolvable): Promise<ApplicationCommand>;
|
|
45
|
+
/**
|
|
46
|
+
* Parse application command builders to command data
|
|
47
|
+
* @param commands Application command builders
|
|
48
|
+
* @param setPermissions set slash commands permissions
|
|
49
|
+
*/
|
|
14
50
|
protected parseCommands(commands: (ApplicationCommandData | ApplicationCommandBuilder | RESTPostAPIApplicationCommandsJSONBody)[], setPermissions?: boolean): (ApplicationCommandData | RESTPostAPIApplicationCommandsJSONBody)[];
|
|
15
51
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Collection } from 'discord.js';
|
|
2
|
-
import { ClientModuleManagerGetModulePathsOptions,
|
|
2
|
+
import { ClientModuleManagerGetModulePathsOptions, ClientModuleManagerLoadModulesOptions, ClientModuleManagerResolveModuleFilesOptions, ClientModuleManagerStartModulesOptions, ClientModuleManagerUnloadModulesOptions } from '../../types/paramOptions';
|
|
3
3
|
import { RecipleClient } from '../RecipleClient';
|
|
4
4
|
import { RecipleModule, RecipleScript } from '../RecipleModule';
|
|
5
5
|
export interface ClientModuleManagerOptions {
|
|
@@ -10,10 +10,40 @@ export declare class ClientModuleManager {
|
|
|
10
10
|
readonly client: RecipleClient;
|
|
11
11
|
readonly modules: Collection<string, RecipleModule>;
|
|
12
12
|
constructor(options: ClientModuleManagerOptions);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Start modules
|
|
15
|
+
* @param options start modules options
|
|
16
|
+
* @returns started modules
|
|
17
|
+
*/
|
|
18
|
+
startModules(options: ClientModuleManagerStartModulesOptions): Promise<RecipleModule[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Load modules
|
|
21
|
+
* @param options load modules options
|
|
22
|
+
* @returns loaded modules
|
|
23
|
+
*/
|
|
24
|
+
loadModules(options?: ClientModuleManagerLoadModulesOptions): Promise<RecipleModule[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Unload modules
|
|
27
|
+
* @param options unload modules options
|
|
28
|
+
* @returns unloaded modules
|
|
29
|
+
*/
|
|
30
|
+
unloadModules(options?: ClientModuleManagerUnloadModulesOptions): Promise<RecipleModule[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Resolve modules from file paths
|
|
33
|
+
* @param options resolve module files options
|
|
34
|
+
* @returns resolved modules
|
|
35
|
+
*/
|
|
36
|
+
resolveModuleFiles(options: ClientModuleManagerResolveModuleFilesOptions): Promise<RecipleModule[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Validate module script
|
|
39
|
+
* @param script module script
|
|
40
|
+
* @returns `true` if script is valid
|
|
41
|
+
*/
|
|
17
42
|
static validateScript(script: unknown): script is RecipleScript;
|
|
43
|
+
/**
|
|
44
|
+
* Get module file paths from folders
|
|
45
|
+
* @param options get module paths options
|
|
46
|
+
* @returns module paths
|
|
47
|
+
*/
|
|
18
48
|
getModulePaths(options?: ClientModuleManagerGetModulePathsOptions): Promise<string[]>;
|
|
19
49
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ConfigCommandPermissions } from '../classes/RecipleConfig';
|
|
2
2
|
import { Awaitable, PermissionsBitField } from 'discord.js';
|
|
3
3
|
import { AnyCommandBuilder } from './builders';
|
|
4
|
+
import { RecipleModule } from '../classes/RecipleModule';
|
|
4
5
|
export interface UserHasCommandPermissionsOptions {
|
|
5
6
|
/**
|
|
6
7
|
* Command builder
|
|
@@ -18,13 +19,83 @@ export interface UserHasCommandPermissionsOptions {
|
|
|
18
19
|
commands: ConfigCommandPermissions[];
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
|
-
export interface
|
|
22
|
+
export interface ClientModuleManagerResolveModuleFilesOptions {
|
|
23
|
+
/**
|
|
24
|
+
* valid reciple module (ESM or CJS) Javascript file paths
|
|
25
|
+
*/
|
|
22
26
|
files: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Allow loading unsupported module versions
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
23
31
|
disabeVersionCheck?: boolean;
|
|
24
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Ignore errors
|
|
34
|
+
* @dafault true
|
|
35
|
+
*/
|
|
36
|
+
ignoreErrors?: boolean;
|
|
25
37
|
}
|
|
26
38
|
export interface ClientModuleManagerGetModulePathsOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Get javascript module file paths from folders
|
|
41
|
+
*/
|
|
27
42
|
folders?: string[];
|
|
43
|
+
/**
|
|
44
|
+
* Add ignored files (wildcard)
|
|
45
|
+
* @example _*.js // Ignores _module.js and _hi.js
|
|
46
|
+
*/
|
|
28
47
|
ignoredFiles?: string[];
|
|
48
|
+
/**
|
|
49
|
+
* Filter found javascript files
|
|
50
|
+
* @param file Loaded javascript file
|
|
51
|
+
* @returns `true` if the path is acceptable
|
|
52
|
+
*/
|
|
29
53
|
filter?: (file: string) => Awaitable<boolean>;
|
|
30
54
|
}
|
|
55
|
+
export interface ClientModuleManagerStartModulesOptions {
|
|
56
|
+
/**
|
|
57
|
+
* Modules to start
|
|
58
|
+
*/
|
|
59
|
+
modules: RecipleModule[];
|
|
60
|
+
/**
|
|
61
|
+
* Add modules to Client modules collection
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
addToModulesCollection?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Ignore errors
|
|
67
|
+
* @default true
|
|
68
|
+
*/
|
|
69
|
+
ignoreErrors?: boolean;
|
|
70
|
+
}
|
|
71
|
+
export interface ClientModuleManagerLoadModulesOptions {
|
|
72
|
+
/**
|
|
73
|
+
* Modules to execute `load` method
|
|
74
|
+
*/
|
|
75
|
+
modules?: RecipleModule[];
|
|
76
|
+
/**
|
|
77
|
+
* Add commands to client
|
|
78
|
+
* @default true
|
|
79
|
+
*/
|
|
80
|
+
resolveCommands?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Ignore errors
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
ignoreErrors?: boolean;
|
|
86
|
+
}
|
|
87
|
+
export interface ClientModuleManagerUnloadModulesOptions {
|
|
88
|
+
/**
|
|
89
|
+
* Modules to execute `unload` method
|
|
90
|
+
*/
|
|
91
|
+
modules?: RecipleModule[];
|
|
92
|
+
/**
|
|
93
|
+
* Reason for unloading modules
|
|
94
|
+
*/
|
|
95
|
+
reason?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Ignore errors
|
|
98
|
+
* @default true
|
|
99
|
+
*/
|
|
100
|
+
ignoreErrors?: boolean;
|
|
101
|
+
}
|
package/package.json
CHANGED